summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2013-02-03 00:02:37 +0900
committerINADA Naoki <inada-n@klab.com>2013-02-03 00:02:37 +0900
commit95dfec808a700c99144e454fbf9d98be420f2c51 (patch)
treec46f3f101c043f7d44f82fb62c18ddf59434fe7a /benchmark
parent8d6a387dff10dd2150aa86cd96e2bece26546268 (diff)
downloadmsgpack-python-95dfec808a700c99144e454fbf9d98be420f2c51.tar.gz
Add simple benchmark.
Diffstat (limited to 'benchmark')
-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()