diff options
author | INADA Naoki <songofacandy@gmail.com> | 2013-02-03 08:11:34 -0800 |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2013-02-03 08:11:34 -0800 |
commit | 2330e6c7d92455c84fef4b7f9ac44b2a8b430def (patch) | |
tree | c4a2a3ba74d4f5788b8dd507553f23b8d2ff2519 /benchmark/benchmark.py | |
parent | 266eaf813d4e958dce5a2a8c4a84babf331369f0 (diff) | |
parent | 1951b197b547c3f12b755790717d799272fbeb34 (diff) | |
download | msgpack-python-2330e6c7d92455c84fef4b7f9ac44b2a8b430def.tar.gz |
Merge pull request #45 from msgpack/purepython
fallback enhancements.
Diffstat (limited to 'benchmark/benchmark.py')
-rw-r--r-- | benchmark/benchmark.py | 32 |
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() |