[Python-Dev] Microbenchmarks

Victor Stinner victor.stinner at gmail.com
Thu Sep 15 17:04:03 EDT 2016


2016-09-15 21:33 GMT+02:00 Victor Stinner <victor.stinner at gmail.com>:
> perf takes ~60 seconds by default. If you don't care of the accuracy,
> use --fast and it now only takes 20 seconds ;-)

Oops, I'm wrong. By default, a "single dot" (one worker process) takes
less 1 second, so 20 dots (default) takes less than 20 seconds.

On the following example, the setup statement is quite expensive:

$ python3 -m timeit -s "d=dict.fromkeys(map(str,range(10**6)))" "list(d)"

The statement "list(d)" takes around 47 ms, but the setup statement
takes 377 ms.

It seems like timeit executes the setup statement. Perf is based on
timeit, and so each process runs the setup statement at least 4 times
(1 warmup + 3 samples): 4*377 ms ~= 1.5 sec per process.

Replace range(10**6) with range(10**5) and the benchmark itself
becomes much faster: 57 seconds => 15 seconds.

Victor


More information about the Python-Dev mailing list