CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <chrono>
using namespace std;
#define BENCH(times, function, parameter) \
for(int i = 0; i < times; ++i){ \
std::chrono::time_point <std::chrono::system_clock> start, end; \
start = std::chrono::system_clock::now(); \
function parameter; \
end = std::chrono::system_clock::now();\
int elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds> (end-start).count();\
std::time_t end_time = std::chrono::system_clock::to_time_t(end);\
std::cout << "finished computation at " << std::ctime(&end_time) << "elapsed time: " << elapsed_milliseconds << "ms\n";\
}
long fibo(long v){
long res = 1;
long old = 1;
for(long i = 1; i < v; ++i){
long tmp = old;
old = res;
res += tmp;
}
return res;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run