KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Fastest Fibonacci sequence generator Re: Fastest Fibonacci sequence generator

  • albin

    Member
    February 12, 2024 at 12:00 am

    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.