-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for singleton object construction
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |