Home › Forums › kdb+ › Fastest Fibonacci sequence generator › Re: Fastest Fibonacci sequence generator
-
It’s perhaps nicer to always fill the entire input array instead of taking the number of values to generate as an argument.
fibn:{[s] n: count get s; @[s; 0 1; :; 0 1]; f: {[s; i]; @[s; i; :; @[s; i-2] + @[s; i-1]]; i+1}; (f[s]/)[n-2; 2]; s} x: zeros[`long; 1000000] ts fibn[`x] / 319 576
Interestingly, this reduces the number of bytes allocated by 352, but seems to be slightly slower.