More micro benchmarks.

Comparing to current master, there is no substantial difference.

+-------------------------------------------------------------+----------------+------------------------------+
| Benchmark                                                   | bench_master38 | bench_issue200               |
+=============================================================+================+==============================+
| call interface (alternate, no conform, not provided)        | 395 ns         | 414 ns: 1.05x slower (+5%)   |
+-------------------------------------------------------------+----------------+------------------------------+
| call interface (no alternate, valid conform, not provided)  | 250 ns         | 240 ns: 1.04x faster (-4%)   |
+-------------------------------------------------------------+----------------+------------------------------+
| read __module__                                             | 45.3 ns        | 43.4 ns: 1.04x faster (-4%)  |
+-------------------------------------------------------------+----------------+------------------------------+
| query adapter (no registrations)                            | 3.23 ms        | 3.31 ms: 1.02x slower (+2%)  |
+-------------------------------------------------------------+----------------+------------------------------+
| query adapter (all trivial registrations)                   | 3.93 ms        | 4.40 ms: 1.12x slower (+12%) |
+-------------------------------------------------------------+----------------+------------------------------+
| query adapter (all trivial registrations, wide inheritance) | 43.3 us        | 45.5 us: 1.05x slower (+5%)  |
+-------------------------------------------------------------+----------------+------------------------------+
| query adapter (all trivial registrations, deep inheritance) | 43.2 us        | 46.9 us: 1.09x slower (+9%)  |
+-------------------------------------------------------------+----------------+------------------------------+
| sort mixed                                                  | 361 us         | 354 us: 1.02x faster (-2%)   |
+-------------------------------------------------------------+----------------+------------------------------+
| contains (populated dict: interfaces)                       | 61.3 ns        | 59.7 ns: 1.03x faster (-3%)  |
+-------------------------------------------------------------+----------------+------------------------------+

Not significant (13): call interface (provides; deep); call interface (provides; wide); call interface (no alternate, no conform, not provided); call interface (alternate, invalid conform, not provided); read __name__; read __doc__; read providedBy; sort interfaces; sort implementedBy; contains (empty dict); contains (populated list: interfaces); contains (populated dict: implementedBy); contains (populated list: implementedBy)
pull/201/head
Jason Madden 3 years ago
parent a4ed0566f9
commit 719851072c
No known key found for this signature in database
GPG Key ID: 349F84431A08B99E
  1. 118
      benchmarks/micro.py

@ -37,6 +37,21 @@ class DeepestInheritance(object):
pass
classImplements(DeepestInheritance, deep_ifaces[-1])
class ImplementsNothing(object):
pass
class HasConformReturnNone(object):
def __conform__(self, iface):
return None
class HasConformReturnObject(object):
def __conform__(self, iface):
return self
def make_implementer(iface):
c = type('Implementer' + iface.__name__, (object,), {})
classImplements(c, iface)
@ -77,16 +92,17 @@ def bench_sort(loops, objs):
return pyperf.perf_counter() - t0
def bench_query_adapter(loops, components, objs=providers):
components_queryAdapter = components.queryAdapter
# One time through to prime the caches
for iface in ifaces:
for provider in providers:
components.queryAdapter(provider, iface)
components_queryAdapter(provider, iface)
t0 = pyperf.perf_counter()
for _ in range(loops):
for iface in ifaces:
for provider in objs:
components.queryAdapter(provider, iface)
components_queryAdapter(provider, iface)
return pyperf.perf_counter() - t0
@ -106,8 +122,106 @@ def bench_getattr(loops, name, get=getattr):
get(Interface, name) # 10
return pyperf.perf_counter() - t0
def bench_iface_call_no_conform_no_alternate_not_provided(loops):
inst = ImplementsNothing()
t0 = pyperf.perf_counter()
for _ in range(loops):
for _ in range(INNER):
for iface in ifaces:
try:
iface(inst)
except TypeError:
pass
else:
raise TypeError("Should have failed")
return pyperf.perf_counter() - t0
def bench_iface_call_no_conform_w_alternate_not_provided(loops):
inst = ImplementsNothing()
t0 = pyperf.perf_counter()
for _ in range(loops):
for _ in range(INNER):
for iface in ifaces:
iface(inst, 42)
return pyperf.perf_counter() - t0
def bench_iface_call_w_conform_return_none_not_provided(loops):
inst = HasConformReturnNone()
t0 = pyperf.perf_counter()
for _ in range(loops):
for _ in range(INNER):
for iface in ifaces:
iface(inst, 42)
return pyperf.perf_counter() - t0
def bench_iface_call_w_conform_return_non_none_not_provided(loops):
inst = HasConformReturnObject()
t0 = pyperf.perf_counter()
for _ in range(loops):
for _ in range(INNER):
for iface in ifaces:
iface(inst)
return pyperf.perf_counter() - t0
def _bench_iface_call_simple(loops, inst):
t0 = pyperf.perf_counter()
for _ in range(loops):
for _ in range(INNER):
for iface in ifaces:
iface(inst)
return pyperf.perf_counter() - t0
def bench_iface_call_no_conform_provided_wide(loops):
return _bench_iface_call_simple(loops, WideInheritance())
def bench_iface_call_no_conform_provided_deep(loops):
return _bench_iface_call_simple(loops, DeepestInheritance())
runner = pyperf.Runner()
runner.bench_time_func(
'call interface (provides; deep)',
bench_iface_call_no_conform_provided_deep,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'call interface (provides; wide)',
bench_iface_call_no_conform_provided_wide,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'call interface (no alternate, no conform, not provided)',
bench_iface_call_no_conform_no_alternate_not_provided,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'call interface (alternate, no conform, not provided)',
bench_iface_call_no_conform_w_alternate_not_provided,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'call interface (no alternate, valid conform, not provided)',
bench_iface_call_w_conform_return_non_none_not_provided,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'call interface (alternate, invalid conform, not provided)',
bench_iface_call_w_conform_return_none_not_provided,
inner_loops=INNER * len(ifaces)
)
runner.bench_time_func(
'read __module__', # stored in C, accessed through __getattribute__
bench_getattr,

Loading…
Cancel
Save