[Python-Dev] Optimizing list.sort() by checking type in advance (original) (raw)
Nathaniel Smith njs at pobox.com
Mon Oct 10 17:49:07 EDT 2016
- Previous message (by thread): [Python-Dev] Optimizing list.sort() by checking type in advance
- Next message (by thread): [Python-Dev] Optimizing list.sort() by checking type in advance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Oct 10, 2016 at 2:16 PM, Elliot Gorokhovsky <elliot.gorokhovsky at gmail.com> wrote:
Hm... that is strange, but I don't think there's anything wrong with the way I'm timing, though I agree perf/timeit would be better. I ran the benchmark a couple of times and the numbers seem to exactly line up something like one in five times; perhaps not that crazy considering they're executing nearly the same code?
No, computer clocks are precise enough, and CPUs are wonky enough (cache effects, etc.), that it should be effectively impossible to get the same timing result twice in row, even for running exactly the same code. I'm not sure what's going on, but it's weird. Making these kinds of measurements is much more complicated than it looks and you really need to use something like timeit or perf if you want trustworthy results. Fortunately, they're easy to use :-)
-n
-- Nathaniel J. Smith -- https://vorpus.org
- Previous message (by thread): [Python-Dev] Optimizing list.sort() by checking type in advance
- Next message (by thread): [Python-Dev] Optimizing list.sort() by checking type in advance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]