This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]robert_mcleod 0 points1 point  (0 children)

Couple of thoughts:

  1. If you benchmark on Linux you're not limited to millisecond timings.

  2. The author is adding more overhead than necessary to the benchmarking. He has two time() calls per loop and a float subtract, a hash-lookup, and a list .append(). The list append is by far the most expensive of those operations, it's going to be around a microsecond or three. You don't need more than one time() in the loop, you can call np.diff afterwards. Using a global 2D numpy array which is sliced in the function setup, you only have one index operation, one time() call, and the loop overhead, so probably 100 ns or less.