Hacker News new | ask | show | jobs
by km6GEwiQqsyEKQH 1545 days ago

  lim = 10**1000000
  a, b = 1, 2
  acc = 0
  while a < lim:
      if not a & 1:
          acc += a
      a, b = b, (a + b)
  print("done", flush=True)
  print(acc)
For a baseline this trivial python implementation does it in 34 ms for 10^10000 and 2m55 for 10^1,000,000 on a ryzen 5. Because the fibonacci sequence is increasing roughly exponentially, the iteration count scales roughly linearly to the number of digits. Then it just goes down to the number crunching speed of the bignum implementation? (Calculating the exponent also takes multiple seconds, as well formatting the number to a string takes around 10 seconds as well.)
1 comments

Thanks for the comparison :) I'm plotting the racket implementation over input size to see how it performs over input size - it feels slightly more sharply curved than linear but you may very well be correct!
If you benchmark the solution, remember to do it in the terminal using the command line version `racket`.

With default settings DrRacket will add extra debug code to the program, which will slow it down.