summaryrefslogtreecommitdiff
path: root/benchmark/benchmark.py
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2013-02-04 15:16:17 +0900
committerINADA Naoki <inada-n@klab.com>2013-02-04 15:16:17 +0900
commit6740b90385b2d8a23fe7ace6e9a69f62e7a0e14c (patch)
tree728d616ffb33a27ba00bd1a331d199f4434029b2 /benchmark/benchmark.py
parent266eaf813d4e958dce5a2a8c4a84babf331369f0 (diff)
parenta865f8f7e94ea5b484771c1be3fe57ff3a63aa2a (diff)
downloadmsgpack-python-6740b90385b2d8a23fe7ace6e9a69f62e7a0e14c.tar.gz
Merge branch 'purepython'
Diffstat (limited to 'benchmark/benchmark.py')
-rw-r--r--benchmark/benchmark.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py
new file mode 100644
index 0000000..1439289
--- /dev/null
+++ b/benchmark/benchmark.py
@@ -0,0 +1,32 @@
+from msgpack import fallback
+try:
+ from msgpack import _unpacker, _packer
+ has_ext = True
+except ImportError:
+ has_ext = False
+import timeit
+
+
+def profile(name, func):
+ times = timeit.repeat(func, number=1000, repeat=4)
+ times = ', '.join(["%8f" % t for t in times])
+ print("%-30s %40s" % (name, times))
+
+
+def simple(name, data):
+ if has_ext:
+ profile("packing %s (ext)" % name, lambda: _packer.packb(data))
+ profile('packing %s (fallback)' % name, lambda: fallback.packb(data))
+
+ data = fallback.packb(data)
+ if has_ext:
+ profile('unpacking %s (ext)' % name, lambda: _unpacker.unpackb(data))
+ profile('unpacking %s (fallback)' % name, lambda: fallback.unpackb(data))
+
+def main():
+ simple("integers", [7]*10000)
+ simple("bytes", [b'x'*n for n in range(100)]*10)
+ simple("lists", [[]]*10000)
+ simple("dicts", [{}]*10000)
+
+main()