Commit 54ffea34 authored by Jason Madden's avatar Jason Madden

Update bench_spawn

Current numbers on my workstation:

CPython 3.6.4

//gevent36/bin/python bench_spawn.py eventlet --ignore-import-errors
using eventlet from //python3.6/site-packages/eventlet/__init__.py
spawning: 11.93 microseconds per greenlet
sleep(0): 23.49 microseconds per greenlet

//gevent36/bin/python bench_spawn.py gevent --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 3.39 microseconds per greenlet
sleep(0): 17.59 microseconds per greenlet

//gevent36/bin/python bench_spawn.py geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 8.71 microseconds per greenlet
sleep(0): 16.99 microseconds per greenlet
 joining: 7.34 microseconds per greenlet

//gevent36/bin/python bench_spawn.py geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 2.09 microseconds per greenlet
sleep(0): 13.57 microseconds per greenlet

//gevent36/bin/python bench_spawn.py none --ignore-import-errors
    noop: 0.33 microseconds per greenlet

//gevent36/bin/python bench_spawn.py --with-kwargs eventlet --ignore-import-errors
using eventlet from //python3.6/site-packages/eventlet/__init__.py
spawning: 12.06 microseconds per greenlet
sleep(0): 24.25 microseconds per greenlet

//gevent36/bin/python bench_spawn.py --with-kwargs gevent --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 4.62 microseconds per greenlet
sleep(0): 22.18 microseconds per greenlet

//gevent36/bin/python bench_spawn.py --with-kwargs geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 10.25 microseconds per greenlet
sleep(0): 18.89 microseconds per greenlet
 joining: 7.14 microseconds per greenlet

//gevent36/bin/python bench_spawn.py --with-kwargs geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 3.27 microseconds per greenlet
sleep(0): 15.03 microseconds per greenlet

//gevent36/bin/python bench_spawn.py --with-kwargs none --ignore-import-errors
    noop: 0.50 microseconds per greenlet

CPython 2.7.14

//gevent27/bin/python bench_spawn.py eventlet --ignore-import-errors
using eventlet from //python2.7/site-packages/eventlet/__init__.pyc
spawning: 17.84 microseconds per greenlet
sleep(0): 31.42 microseconds per greenlet

//gevent27/bin/python bench_spawn.py gevent --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 4.95 microseconds per greenlet
sleep(0): 21.40 microseconds per greenlet

//gevent27/bin/python bench_spawn.py geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 12.44 microseconds per greenlet
sleep(0): 22.90 microseconds per greenlet
 joining: 10.68 microseconds per greenlet

//gevent27/bin/python bench_spawn.py geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 2.33 microseconds per greenlet
sleep(0): 15.11 microseconds per greenlet

//gevent27/bin/python bench_spawn.py none --ignore-import-errors
    noop: 0.58 microseconds per greenlet

//gevent27/bin/python bench_spawn.py --with-kwargs eventlet --ignore-import-errors
using eventlet from //python2.7/site-packages/eventlet/__init__.pyc
spawning: 19.38 microseconds per greenlet
sleep(0): 31.62 microseconds per greenlet

//gevent27/bin/python bench_spawn.py --with-kwargs gevent --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 6.59 microseconds per greenlet
sleep(0): 23.12 microseconds per greenlet

//gevent27/bin/python bench_spawn.py --with-kwargs geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 13.78 microseconds per greenlet
sleep(0): 21.65 microseconds per greenlet
 joining: 10.86 microseconds per greenlet

//gevent27/bin/python bench_spawn.py --with-kwargs geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 3.59 microseconds per greenlet
sleep(0): 16.14 microseconds per greenlet

//gevent27/bin/python bench_spawn.py --with-kwargs none --ignore-import-errors
    noop: 0.65 microseconds per greenlet

PyPy2 5.10.0

//geventpypy/bin/python bench_spawn.py eventlet --ignore-import-errors
using eventlet from //geventpypy/site-packages/eventlet/__init__.pyc
spawning: 29.91 microseconds per greenlet
sleep(0): 84.24 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py gevent --ignore-import-errors
using gevent from //src/gevent/__init__.py
spawning: 0.73 microseconds per greenlet
sleep(0): 33.02 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 2.49 microseconds per greenlet
sleep(0): 38.56 microseconds per greenlet
 joining: 13.08 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 0.52 microseconds per greenlet
sleep(0): 29.63 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py none --ignore-import-errors
    noop: 0.02 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py --with-kwargs eventlet --ignore-import-errors
using eventlet from //geventpypy/site-packages/eventlet/__init__.pyc
spawning: 30.36 microseconds per greenlet
sleep(0): 83.00 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py --with-kwargs gevent --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 1.56 microseconds per greenlet
sleep(0): 34.80 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py --with-kwargs geventpool --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 3.48 microseconds per greenlet
sleep(0): 39.43 microseconds per greenlet
 joining: 16.21 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py --with-kwargs geventraw --ignore-import-errors
using gevent from //src/gevent/__init__.pyc
spawning: 1.51 microseconds per greenlet
sleep(0): 52.19 microseconds per greenlet

//geventpypy/bin/python bench_spawn.py --with-kwargs none --ignore-import-errors
    noop: 0.13 microseconds per greenlet

[skip ci]
parent e4d19e58
"""Benchmarking spawn() performance. """Benchmarking spawn() performance.
""" """
from __future__ import print_function from __future__ import print_function, absolute_import, division
import sys import sys
import os import os
import random import time
from time import time
try: try:
xrange xrange
except NameError: except NameError:
xrange = range xrange = range
if hasattr(time, "perf_counter"):
curtime = time.perf_counter # 3.3
elif sys.platform.startswith('win'):
curtime = time.clock
else:
curtime = time.time
N = 10000 N = 100000
counter = 0 counter = 0
def incr(sleep, **kwargs): def incr(sleep, **_kwargs):
global counter global counter
counter += 1 counter += 1
sleep(0) sleep(0)
def noop(p): def noop(_p):
pass pass
def _report(name, delta):
print('%8s: %3.2f microseconds per greenlet' % (name, delta * 1000000.0 / N))
def test(spawn, sleep, kwargs): def test(spawn, sleep, kwargs):
start = time() start = curtime()
for _ in xrange(N): for _ in xrange(N):
spawn(incr, sleep, **kwargs) spawn(incr, sleep, **kwargs)
delta = time() - start _report('spawning', curtime() - start)
print('spawning: %.1f microseconds per greenlet' % (delta * 1000000.0 / N))
assert counter == 0, counter assert counter == 0, counter
start = time() start = curtime()
sleep(0) sleep(0)
delta = time() - start _report('sleep(0)', curtime() - start)
assert counter == N, (counter, N) assert counter == N, (counter, N)
print('sleep(0): %.1f microseconds per greenlet' % (delta * 1000000.0 / N))
def bench_none(options): def bench_none(options):
kwargs = options.kwargs kwargs = options.kwargs
start = time() start = curtime()
for _ in xrange(N): for _ in xrange(N):
incr(noop, **kwargs) incr(noop, **kwargs)
delta = time() - start
assert counter == N, (counter, N) assert counter == N, (counter, N)
print('%.2f microseconds' % (delta * 1000000.0 / N)) _report('noop', curtime() - start)
def bench_gevent(options): def bench_gevent(options):
...@@ -70,10 +76,12 @@ def bench_geventpool(options): ...@@ -70,10 +76,12 @@ def bench_geventpool(options):
from gevent.pool import Pool from gevent.pool import Pool
p = Pool() p = Pool()
test(p.spawn, sleep, options.kwargs) test(p.spawn, sleep, options.kwargs)
start = time() start = curtime()
p.join() p.join()
delta = time() - start
print('joining: %.1f microseconds per greenlet' % (delta * 1000000.0 / N)) _report('joining', curtime() - start)
def bench_eventlet(options): def bench_eventlet(options):
...@@ -84,40 +92,24 @@ def bench_eventlet(options): ...@@ -84,40 +92,24 @@ def bench_eventlet(options):
return return
raise raise
print('using eventlet from %s' % eventlet.__file__) print('using eventlet from %s' % eventlet.__file__)
from eventlet.api import spawn, sleep, use_hub from eventlet import spawn, sleep
from eventlet.hubs import use_hub
if options.eventlet_hub is not None: if options.eventlet_hub is not None:
use_hub(options.eventlet_hub) use_hub(options.eventlet_hub)
test(spawn, sleep, options.kwargs) test(spawn, sleep, options.kwargs)
def bench_eventlet1(options):
try:
import eventlet
except ImportError:
if options.ignore_import_errors:
return
raise
print('using eventlet from %s' % eventlet.__file__)
from eventlet.proc import spawn_greenlet as spawn
from eventlet.api import sleep, use_hub
if options.eventlet_hub:
use_hub(options.eventlet_hub)
if options.with_kwargs:
print('eventlet.proc.spawn_greenlet does support kwargs')
return
test(spawn, sleep, options.kwargs)
def bench_all(options): def bench_all():
import time from time import sleep
error = 0 error = 0
names = all() names = sorted(all())
random.shuffle(names)
for func in names: for func in names:
cmd = '%s %s %s --ignore-import-errors' % (sys.executable, __file__, func) cmd = '%s %s %s --ignore-import-errors' % (sys.executable, __file__, func)
print(cmd) print(cmd)
sys.stdout.flush() sys.stdout.flush()
time.sleep(0.01) sleep(0.01)
if os.system(cmd): if os.system(cmd):
error = 1 error = 1
print('%s failed' % cmd) print('%s failed' % cmd)
...@@ -148,7 +140,7 @@ def all_functions(): ...@@ -148,7 +140,7 @@ def all_functions():
return [globals()['bench_%s' % x] for x in all()] return [globals()['bench_%s' % x] for x in all()]
if __name__ == '__main__': def main():
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--with-kwargs', default=False, action='store_true') parser.add_argument('--with-kwargs', default=False, action='store_true')
...@@ -161,7 +153,10 @@ if __name__ == '__main__': ...@@ -161,7 +153,10 @@ if __name__ == '__main__':
else: else:
options.kwargs = {} options.kwargs = {}
if options.benchmark == 'all': if options.benchmark == 'all':
bench_all(options) bench_all()
else: else:
function = globals()['bench_' + options.benchmark] function = globals()['bench_' + options.benchmark]
function(options) function(options)
if __name__ == '__main__':
main()
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