Last active
August 29, 2015 14:04
-
-
Save ulope/a63aff42f51b08181f72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
.tox |
This file contains hidden or 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
from collections import namedtuple | |
import sys | |
SomeNT = namedtuple("SomeNT", ('a_field', 'another_field', 'yet_another_field')) | |
def test_tuple_instantiate(): | |
some_tup = (1, "blah", [1, 2, 3, 4]) | |
def test_tuple_access(some_tuple): | |
some_tuple[1] | |
some_tuple[0] | |
def test_namedtuple_instantiate(namedtuple_class): | |
some_nt = namedtuple_class(1, "blah", [1, 2, 3, 4]) | |
def test_namedtuple_access(some_namedtuple): | |
some_namedtuple.another_field | |
some_namedtuple.a_field | |
def main(): | |
import timeit | |
tup_inst = timeit.timeit("""test_tuple_instantiate()""", setup="from __main__ import test_tuple_instantiate", number=1000000) | |
tup_acc = timeit.timeit("""test_tuple_access((1, "blah", [1, 2, 3, 4]))""", setup="from __main__ import test_tuple_access", number=1000000) | |
ntup_inst = timeit.timeit("""test_namedtuple_instantiate(SomeNT)""", setup="from __main__ import test_namedtuple_instantiate, SomeNT", number=1000000) | |
ntup_acc = timeit.timeit("""test_namedtuple_access(SomeNT(1, "blah", [1, 2, 3, 4]))""", setup="from __main__ import test_namedtuple_access, SomeNT", number=1000000) | |
print("tuple instantiate: {0}".format(tup_inst)) | |
print("namedtuple instantiate: {0}".format(ntup_inst)) | |
print("tuple access: {0}".format(tup_acc)) | |
print("namedtuple access: {0}".format(ntup_acc)) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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
py26 runtests: PYTHONHASHSEED='609294106' | |
py26 runtests: commands[0] | /Users/ulo/devel/py/namedtuple_bench/.tox/py26/bin/python namedtuple_bench.py | |
tuple instantiate: 0.243867874146 | |
namedtuple instantiate: 0.791953086853 | |
tuple access: 0.342396020889 | |
namedtuple access: 1.09635186195 | |
py27 runtests: PYTHONHASHSEED='609294106' | |
py27 runtests: commands[0] | /Users/ulo/devel/py/namedtuple_bench/.tox/py27/bin/python namedtuple_bench.py | |
tuple instantiate: 0.300357103348 | |
namedtuple instantiate: 0.817892074585 | |
tuple access: 0.397746801376 | |
namedtuple access: 1.12735199928 | |
py33 runtests: PYTHONHASHSEED='609294106' | |
py33 runtests: commands[0] | /Users/ulo/devel/py/namedtuple_bench/.tox/py33/bin/python namedtuple_bench.py | |
tuple instantiate: 0.19853064499329776 | |
namedtuple instantiate: 0.8839332649949938 | |
tuple access: 0.2663196460052859 | |
namedtuple access: 1.1236915799963754 | |
py34 runtests: PYTHONHASHSEED='609294106' | |
py34 runtests: commands[0] | /Users/ulo/devel/py/namedtuple_bench/.tox/py34/bin/python namedtuple_bench.py | |
tuple instantiate: 0.2100249359937152 | |
namedtuple instantiate: 0.707535210007336 | |
tuple access: 0.2940493019996211 | |
namedtuple access: 0.9200455860118382 | |
pypy runtests: PYTHONHASHSEED='609294106' | |
pypy runtests: commands[0] | /Users/ulo/devel/py/namedtuple_bench/.tox/pypy/bin/python namedtuple_bench.py | |
tuple instantiate: 0.00525689125061 | |
namedtuple instantiate: 0.00653004646301 | |
tuple access: 0.00449419021606 | |
namedtuple access: 0.00840997695923 | |
___________________________________ summary ____________________________________ | |
py26: commands succeeded | |
py27: commands succeeded | |
py33: commands succeeded | |
py34: commands succeeded | |
pypy: commands succeeded | |
congratulations :) |
This file contains hidden or 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
[tox] | |
envlist = py26,py27,py33,py34,pypy | |
skipsdist = true | |
[testenv] | |
commands = {envpython} namedtuple_bench.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment