-
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 benchmark for an object with a list.
Current timing on cpython2.7: ..................... __main__: toExternalObject: Mean +- std dev: 405 us +- 9 us ..................... __main__: fromExternalObject: Mean +- std dev: 1.37 ms +- 0.03 ms
- Loading branch information
Showing
5 changed files
with
102 additions
and
9 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
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
67 changes: 67 additions & 0 deletions
67
src/nti/externalization/tests/benchmarks/bm_simple_iface_list.py
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,67 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Extends bm_simple_iface to add a list. | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import sys | ||
|
||
import perf | ||
|
||
|
||
from zope.configuration import xmlconfig | ||
|
||
from nti.externalization.externalization import toExternalObject | ||
from nti.externalization.interfaces import StandardExternalFields | ||
|
||
import nti.externalization.tests.benchmarks | ||
|
||
from nti.externalization.tests.benchmarks.objects import DerivedWithOneTextField | ||
from nti.externalization.tests.benchmarks.objects import HasListOfDerived | ||
|
||
from nti.externalization.tests.benchmarks.bm_simple_iface import ( | ||
INNER_LOOPS, | ||
to_external_object_time_func, | ||
update_from_external_object_time_func, | ||
profile | ||
) | ||
|
||
logger = __import__('logging').getLogger(__name__) | ||
|
||
|
||
def main(runner=None): | ||
|
||
xmlconfig.file('configure.zcml', nti.externalization.tests.benchmarks) | ||
|
||
obj = HasListOfDerived() | ||
obj.the_objects = [DerivedWithOneTextField(text=u"This is some text " + str(i)) | ||
for i in range(10)] | ||
|
||
|
||
if '--profile' in sys.argv: | ||
profile(100, obj) | ||
return | ||
|
||
mt = getattr(obj, 'mimeType') | ||
assert mt == 'application/vnd.nextthought.benchmarks.haslistofderived', mt | ||
|
||
runner = runner or perf.Runner() | ||
runner.bench_time_func(__name__ + ": toExternalObject", | ||
to_external_object_time_func, | ||
obj, | ||
inner_loops=INNER_LOOPS) | ||
|
||
ext = toExternalObject(obj) | ||
assert StandardExternalFields.MIMETYPE in ext | ||
|
||
|
||
runner.bench_time_func(__name__ + ": fromExternalObject", | ||
update_from_external_object_time_func, | ||
ext, | ||
inner_loops=INNER_LOOPS) | ||
|
||
if __name__ == '__main__': | ||
main() |
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
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