Created
August 1, 2015 18:05
-
-
Save jl2/4d74958b02b3caea2f5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <chrono> | |
uint64_t fib(uint64_t n) { | |
uint64_t a=1; | |
uint64_t b=1; | |
uint64_t c = b+a; | |
for (uint64_t i=0; i<(n-2); ++i) { | |
c = b + a; | |
b = a; | |
a = c; | |
} | |
return c; | |
} | |
int main(int argc, char *argv[]) { | |
const auto times = 10000000; | |
volatile uint64_t myval = 0; | |
auto start = std::chrono::system_clock::now(); | |
for (auto i=0; i < times; ++i) { | |
myval = fib(78); | |
} | |
auto stop = std::chrono::system_clock::now(); | |
std::chrono::duration<double> elapsed = stop - start; | |
std::cout << "fib(78) = " << myval << " took " << elapsed.count() << " seconds." << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment