Skip to content

Instantly share code, notes, and snippets.

@dasniko
Created November 19, 2014 06:56
Show Gist options
  • Save dasniko/c8df16793298b95c282f to your computer and use it in GitHub Desktop.
Save dasniko/c8df16793298b95c282f to your computer and use it in GitHub Desktop.
Fibonacci/Array Benchmark Test (JavaScript)
var fibonacci = function() {
var i;
var fib = [];
fib[0] = 1;
fib[1] = 1;
for(i = 2; i <= 100; i++) {
fib[i] = fib[i-2] + fib[i-1];
}
fib;
};
var fibExec = function(times) {
var start = new Date().getTime();
for (n = 0; n < times; n++) {
fibonacci();
}
var duration = times + ": " + (new Date().getTime() - start);
print(duration);
};
fibExec(1);
fibExec(10000);
fibExec(100000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment