[Python-Dev] Python Benchmarks (original) (raw)

Tim Peters tim.peters at gmail.com
Sat Jun 3 15:43:38 CEST 2006


[Fredrik Lundh]

.... but it's always the thread that runs when the timer interrupt arrives that gets the entire jiffy time. for example, this script runs for ten seconds, usually without using any process time at all:

import time for i in range(1000): for i in range(1000): i+i+i+i time.sleep(0.005) while the same program, without the sleep, will run for a second or two, most of which is assigned to the process.

Nice example! On my desktop box (WinXP, 3.4GHz), I had to make it nastier to see it consume any "time" without the sleep:

import time for i in range(1000): for i in range(10000): # 10x bigger i+i+i+i*(i+i+i+i) # more work time.sleep(0.005) raw_input("done")

The raw_input is there so I can see Task Manager's idea of elapsed "CPU Time" (sum of process "user time" and "kernel time") when it's done.

Without the sleep, it gets charged 6 CPU seconds. With the sleep, 0 CPU seconds.

But life would be more boring if people believed you the first time ;-)



More information about the Python-Dev mailing list