Skip to content

Commit

Permalink
Add a benchmark for singleton object construction
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jun 26, 2018
1 parent 0bc4733 commit 56dbcb7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/nti/externalization/tests/benchmarks/bm_singleton.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
"""
Benchmark for creating singleton objects.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import perf

from nti.externalization.singleton import Singleton
from nti.externalization.singleton import SingletonMetaclass

# These are defined to have __slots__ = ()
class SingletonSubclass(Singleton):
pass


class ObjectSubclass(object):
__slots__ = ()
def __init__(self, _context=None, _request=None):
pass


def main(runner=None):

runner = runner or perf.Runner()
runner.bench_func('Construct Singleton', SingletonSubclass)

runner.bench_func('Construct non-Singleton', ObjectSubclass)

runner.bench_func('Construct Singleton with args',
SingletonSubclass, 'context', 'request')

runner.bench_func("Construct non-Singleton with args",
ObjectSubclass, 'context', 'request')


if __name__ == '__main__':
main()

0 comments on commit 56dbcb7

Please sign in to comment.