Commit d9602bf8 authored by Jason Madden's avatar Jason Madden

Add a script for benchmarking gevent.local

[skip ci]
Current numbers:

local_36_master
===============

getattr gevent: Mean +- std dev: 216 ns +- 6 ns
setattr gevent: Mean +- std dev: 215 ns +- 6 ns
getattr gevent sub: Mean +- std dev: 600 ns +- 19 ns
setattr gevent sub: Mean +- std dev: 591 ns +- 38 ns
getattr native: Mean +- std dev: 56.9 ns +- 4.1 ns
setattr native: Mean +- std dev: 84.3 ns +- 4.9 ns
getattr native sub: Mean +- std dev: 65.6 ns +- 5.3 ns
setattr native sub: Mean +- std dev: 76.2 ns +- 4.6 ns

local_27_master
===============

getattr gevent: Mean +- std dev: 177 ns +- 7 ns
setattr gevent: Mean +- std dev: 192 ns +- 6 ns
getattr gevent sub: Mean +- std dev: 501 ns +- 10 ns
setattr gevent sub: Mean +- std dev: 536 ns +- 25 ns
getattr native: Mean +- std dev: 93.8 ns +- 3.6 ns
setattr native: Mean +- std dev: 118 ns +- 6 ns
getattr native sub: Mean +- std dev: 102 ns +- 4 ns
setattr native sub: Mean +- std dev: 118 ns +- 8 ns

local_pypy_master
=================

getattr gevent: Mean +- std dev: 135 ns +- 6 ns
setattr gevent: Mean +- std dev: 126 ns +- 4 ns
getattr gevent sub: Mean +- std dev: 150 ns +- 4 ns
setattr gevent sub: Mean +- std dev: 153 ns +- 7 ns
getattr native: Mean +- std dev: 0.18 ns +- 0.00 ns
setattr native: Mean +- std dev: 0.18 ns +- 0.01 ns
getattr native sub: Mean +- std dev: 0.18 ns +- 0.01 ns
setattr native sub: Mean +- std dev: 0.19 ns +- 0.01 ns
parent 43e776b6
# -*- coding: utf-8 -*-
"""
Benchmarks for thread locals.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import perf
from gevent.local import local as glocal
from threading import local as nlocal
class GLocalSub(glocal):
pass
class NativeSub(nlocal):
pass
benchmarks = []
def _populate(l):
for i in range(10):
setattr(l, 'attr' + str(i), i)
def bench_getattr(loops, local):
t0 = perf.perf_counter()
for _ in range(loops):
# pylint:disable=pointless-statement
local.attr0
local.attr1
local.attr2
local.attr3
local.attr4
local.attr5
local.attr6
local.attr7
local.attr8
local.attr9
return perf.perf_counter() - t0
def bench_setattr(loops, local):
t0 = perf.perf_counter()
for _ in range(loops):
local.attr0 = 0
local.attr1 = 1
local.attr2 = 2
local.attr3 = 3
local.attr4 = 4
local.attr5 = 5
local.attr6 = 6
local.attr7 = 7
local.attr8 = 8
local.attr9 = 9
return perf.perf_counter() - t0
def main():
runner = perf.Runner()
for name, obj in (('gevent', glocal()),
('gevent sub', GLocalSub()),
('native', nlocal()),
('native sub', NativeSub())):
_populate(obj)
benchmarks.append(
runner.bench_time_func('getattr ' + name,
bench_getattr,
obj,
inner_loops=10))
benchmarks.append(
runner.bench_time_func('setattr ' + name,
bench_setattr,
obj,
inner_loops=10))
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