Created
April 10, 2013 14:37
-
-
Save 19h/5355190 to your computer and use it in GitHub Desktop.
Ultra High-Speed Fibonacci Generator. This is faster then the addition-increment approach in C or ASM.
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
| fib = function (c) { | |
| var b, a = [0, 1]; | |
| for (b = 0; b < c; ++b) a.push(a[0] + a[1]), a.shift(); | |
| return a[0] | |
| }; |
Author
19h
commented
Apr 10, 2013
Author
An last but not least:
v = function (d) {
var a = 0,
b = 1,
c = 0,
e = [0, 1],
f = 1;
do e.push(a = c + b), c = b, b = a; while (++f < d);
return a
};
Author
Benchmark:
Approach B: [ 0, 22516 Nanoseconds ] 1000th Fibonacci
Approach C: [ 0, 62743 Nanoseconds ] 1000th Fibonacci
Approach A: [ 0, 159227 Nanoseconds ] 1000th Fibonacci
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment