Rev | Line | |
---|
[2] | 1 | #include "stream.h" |
---|
| 2 | #include "test_common.h" |
---|
| 3 | #include <sys/time.h> |
---|
| 4 | |
---|
| 5 | long timeval_diff(struct timeval &tv1, struct timeval &tv2) |
---|
| 6 | { |
---|
| 7 | long ret = tv1.tv_usec - tv2.tv_usec; |
---|
| 8 | if(ret<0) ret += 1000000; |
---|
| 9 | return ret; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | long fib(int n) |
---|
| 14 | { |
---|
| 15 | long a=0,b=1; |
---|
| 16 | for(int i=0; i<n; ++i) { |
---|
| 17 | b+=a; |
---|
| 18 | a=b-a; |
---|
| 19 | } |
---|
| 20 | return a; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | int main() |
---|
| 25 | { |
---|
| 26 | stream<long> s = 0l<<=s+(1l<<=s); |
---|
| 27 | compare(s, {0l,1l,1l,2l,3l,5l,8l,13l,21l,34l}, 1); |
---|
| 28 | |
---|
| 29 | const int n = 200000; |
---|
| 30 | struct timeval tv1, tv2; |
---|
| 31 | struct timezone tz; |
---|
| 32 | |
---|
| 33 | gettimeofday(&tv1, &tz); |
---|
| 34 | stream<long>::iterator it = s.begin(); |
---|
| 35 | for(int i=0; i<n; ++i) ++it; |
---|
| 36 | *it; |
---|
| 37 | gettimeofday(&tv2, &tz); |
---|
| 38 | std::cout<<timeval_diff(tv2, tv1)<<std::endl; |
---|
| 39 | |
---|
| 40 | gettimeofday(&tv1, &tz); |
---|
| 41 | fib(n); |
---|
| 42 | gettimeofday(&tv2, &tz); |
---|
| 43 | std::cout<<timeval_diff(tv2, tv1)<<std::endl; |
---|
| 44 | |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.