File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ from msgpack import fallback
2+ try :
3+ from msgpack import _unpacker , _packer
4+ has_ext = True
5+ except ImportError :
6+ has_ext = False
7+ import timeit
8+
9+
10+ def profile (name , func ):
11+ times = timeit .repeat (func , number = 1000 , repeat = 4 )
12+ times = ', ' .join (["%8f" % t for t in times ])
13+ print ("%-30s %40s" % (name , times ))
14+
15+
16+ def simple (name , data ):
17+ if has_ext :
18+ profile ("packing %s (ext)" % name , lambda : _packer .packb (data ))
19+ profile ('packing %s (fallback)' % name , lambda : fallback .packb (data ))
20+
21+ data = fallback .packb (data )
22+ if has_ext :
23+ profile ('unpacking %s (ext)' % name , lambda : _unpacker .unpackb (data ))
24+ profile ('unpacking %s (fallback)' % name , lambda : fallback .unpackb (data ))
25+
26+ def main ():
27+ simple ("integers" , [7 ]* 10000 )
28+ simple ("bytes" , [b'x' * n for n in range (100 )]* 10 )
29+ simple ("lists" , [[]]* 10000 )
30+ simple ("dicts" , [{}]* 10000 )
31+
32+ main ()
You can’t perform that action at this time.
0 commit comments