• Jason Madden's avatar
    Add spawn_tree_locals, spawning_greenlet and spawning_stack to Greenlet · 15fc1ecc
    Jason Madden authored
    Based on #755.
    
    A comment in the code goes into detail about the timing. Here it is
    again:
    
     Timings taken Feb 21 2018 prior to integration of #755
     python -m perf timeit -s 'import gevent' 'gevent.Greenlet()'
     3.6.4       : Mean +- std dev: 1.08 us +- 0.05 us
     2.7.14      : Mean +- std dev: 1.44 us +- 0.06 us
     PyPy2 5.10.0: Mean +- std dev: 2.14 ns +- 0.08 ns
    
     After the integration of spawning_stack, spawning_greenlet,
     and spawn_tree_locals on that same date:
     3.6.4       : Mean +- std dev: 8.92 us +- 0.36 us ->  8.2x
     2.7.14      : Mean +- std dev: 14.8 us +- 0.5 us  -> 10.2x
     PyPy2 5.10.0: Mean +- std dev: 3.24 us +- 0.17 us ->  1.5x
    
    Selected bench_spawn output on 3.6.4 before:
    
    //gevent36/bin/python src/greentest/bench_spawn.py eventlet --ignore-import-errors
    using eventlet from //gevent36/lib/python3.6/site-packages/eventlet/__init__.py
    spawning: 11.93 microseconds per greenlet
    sleep(0): 23.49 microseconds per greenlet
    
    //gevent36/bin/python src/greentest/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 src/greentest/bench_spawn.py geventpool --ignore-import-errors
    using gevent from //src/gevent/__init__.py
    spawning: 8.71 microseconds per greenlet
    
    //gevent36/bin/python src/greentest/bench_spawn.py geventraw --ignore-import-errors
    using gevent from //src/gevent/__init__.py
    spawning: 2.09 microseconds per greenlet
    
    //gevent36/bin/python src/greentest/bench_spawn.py none --ignore-import-errors
        noop: 0.33 microseconds per greenlet
    
    And after:
    
    //gevent36/bin/python bench_spawn.py gevent --ignore-import-errors
    using gevent from //src/gevent/__init__.py
    spawning: 12.99 microseconds per greenlet -> 3.8x
    
    //gevent36/bin/python bench_spawn.py geventpool --ignore-import-errors
    using gevent from //src/gevent/__init__.py
    spawning: 19.49 microseconds per greenlet -> 2.2x
    
    //gevent36/bin/python bench_spawn.py geventraw --ignore-import-errors
    using gevent from //src/gevent/__init__.py
    spawning: 4.57 microseconds per greenlet -> 2.2x
    
    We're approximately the speed of eventlet now.
    
    Refs #755
    15fc1ecc
gevent.rst 6.05 KB