Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Last active October 12, 2016 18:22
Show Gist options
  • Save davidwtbuxton/ca843407f025e1b5b4585aa415885321 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/ca843407f025e1b5b4585aa415885321 to your computer and use it in GitHub Desktop.
Benchmarks for bencodepy.encode and buxtor.bencode.
# Speed comparison of bencodepy and buxtor.bencode
# bencodepy is consistently 0.3 - 0.5 seconds faster. Why?
# bencodepy: https://github.com/eweast/BencodePy/blob/master/bencodepy/encode.py
# 4914005 function calls (3618005 primitive calls) in 2.830 seconds
#
#
# buxtor.bencode: https://github.com/davidwtbuxton/buxtor/blob/master/buxtor/bencode.py
# 5592005 function calls (4548005 primitive calls) in 3.183 seconds
# This is the output of bencodepy's benchmark, using Python 3.5.2 on Mac OS X 10.11.6.
# (with a whole bunch of setup logging removed).
$ python bench_encoding.py
Number of objects to decode: 30000.
Benchmark using bencodepy.encode
Match
Total encode size: 1718.662 MB.
Wed Oct 12 19:11:55 2016 encode_stats
4914005 function calls (3618005 primitive calls) in 2.830 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
630000 0.893 0.000 0.985 0.000 encode.py:13(__encode_byte_str)
30000 0.480 0.000 0.480 0.000 {method 'join' of 'bytes' objects}
1002000/30000 0.367 0.000 2.085 0.000 encode.py:56(__select_encoder)
120000/30000 0.241 0.000 2.059 0.000 encode.py:37(__encode_dict)
30000 0.205 0.000 2.770 0.000 encode.py:5(encode)
630000 0.141 0.000 1.126 0.000 encode.py:47(<lambda>)
156000 0.120 0.000 0.134 0.000 encode.py:19(__encode_int)
1218000 0.100 0.000 0.100 0.000 {method 'append' of 'list' objects}
96000/24000 0.082 0.000 0.670 0.000 encode.py:29(__encode_list)
1 0.060 0.060 2.830 2.830 bench_encoding.py:30(<listcomp>)
156000 0.041 0.000 0.175 0.000 encode.py:52(<lambda>)
630000 0.041 0.000 0.041 0.000 {built-in method builtins.len}
120000/30000 0.033 0.000 2.067 0.000 encode.py:48(<lambda>)
96000/24000 0.027 0.000 0.677 0.000 encode.py:50(<lambda>)
1 0.000 0.000 2.830 2.830 {built-in method builtins.exec}
1 0.000 0.000 2.830 2.830 bench_encoding.py:28(bench)
1 0.000 0.000 2.830 2.830 <string>:1(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
# And the output of buxtor.bencode using the same Python, same script but modified with
# from buxtor.bencode import encode, decode
$ python bench_encoding_buxtor.py
Number of objects to decode: 30000.
Benchmark using buxtor.bencode
Match
Total encode size: 1718.662 MB.
Wed Oct 12 19:11:04 2016 encode_stats
5592005 function calls (4548005 primitive calls) in 3.183 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1002000/30000 2.464 0.000 3.160 0.000 bencode.py:66(encode)
2712000 0.259 0.000 0.259 0.000 {built-in method builtins.isinstance}
216000 0.199 0.000 0.199 0.000 {method 'join' of 'bytes' objects}
816000 0.075 0.000 0.075 0.000 {method 'append' of 'list' objects}
120000 0.065 0.000 0.065 0.000 {built-in method builtins.sorted}
96000/24000 0.057 0.000 0.755 0.000 bencode.py:83(<listcomp>)
630000 0.041 0.000 0.041 0.000 {built-in method builtins.len}
1 0.022 0.022 3.182 3.182 bench_encoding_buxtor.py:28(<listcomp>)
1 0.000 0.000 3.183 3.183 {built-in method builtins.exec}
1 0.000 0.000 3.182 3.182 <string>:1(<module>)
1 0.000 0.000 3.182 3.182 bench_encoding_buxtor.py:26(bench)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment