Created
November 19, 2014 06:56
-
-
Save dasniko/c8df16793298b95c282f to your computer and use it in GitHub Desktop.
Fibonacci/Array Benchmark Test (JavaScript)
This file contains 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
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