Commit be8616bf authored by Denis Bilenko's avatar Denis Bilenko

bench_sleep0.py: dynamically select N; measure cpu time

parent 7c0cef4e
from time import time
from gevent import sleep
import os
N = 10000
N = 10
start = time()
for _ in xrange(N):
sleep(0)
delta = time() - start
print ('sleep(0): %.1f microseconds' % (delta * 1000000.0 / N))
while True:
start = time()
user_time, system_time = os.times()[:2]
for _ in xrange(N):
sleep(0)
user_time_x, system_time_x = os.times()[:2]
delta = time() - start
if delta > 1:
break
N *= 10
user_time_x -= user_time
system_time_x -= system_time
ms = 1000000. / N
print 'N=%s delta=%s utime=%s stime=%s' % (N, delta, user_time_x, system_time_x)
print ('sleep(0): %.1f, utime: %.1f, stime: %.1f (microseconds)' % (delta * ms, user_time_x * ms, system_time_x * ms))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment