Last active
August 29, 2015 13:57
-
-
Save kirsle/9516693 to your computer and use it in GitHub Desktop.
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
import benchmark | |
class DictBenchmark(benchmark.Benchmark): | |
each = 5000 | |
def setUp(self): | |
self.data = dict() | |
for i in range(0, 10000): | |
self.data["key_{}".format(i)] = "value {}".format(i) | |
def test_get(self): | |
for i in range(0, 10000): | |
if self.data.get("key_{}".format(i)): | |
continue | |
def test_in(self): | |
for i in range(0, 10000): | |
if "key_{}".format(i) in self.data: continue | |
if __name__ == "__main__": | |
benchmark.main(format="markdown") | |
""" | |
Benchmark Report | |
================ | |
DictBenchmark | |
------------- | |
name | rank | runs | mean | sd | timesBaseline | |
-----|------|------|----------|-----------|-------------- | |
in | 1 | 5000 | 0.003251 | 0.0001655 | 1.0 | |
get | 2 | 5000 | 0.004477 | 0.0002571 | 1.3771510273 | |
Each of the above 10000 runs were run in random, non-consecutive order by | |
`benchmark` v0.1.5 (http://jspi.es/benchmark) with Python 2.7.5 | |
Linux-3.13.6-200.fc20.x86_64-x86_64 on 2014-03-12 21:22:42. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment