Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created January 31, 2014 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PyYoshi/8728593 to your computer and use it in GitHub Desktop.
Save PyYoshi/8728593 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
import chardet
import time
def main():
do_times = 10
path = r"wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt"
with open(path, 'rb') as f:
msg = f.read()
result_chardet = 0
for i in range(do_times):
start_chardet = time.time()
chardet.detect(msg)
result_chardet += (time.time() - start_chardet)
print('chardet:',1/(result_chardet/do_times), 'call(s)/s')
if '__main__' in __name__:
main()
$ python --version
Python 2.7.6
$ python ./bench.py
('chardet:', 0.13635000826167848, 'call(s)/s')
$ python --version
Python 2.7.3 (87aa9de10f9c, Nov 24 2013, 18:48:13)
[PyPy 2.2.1 with GCC 4.6.3]
$ python ./bench.py
('chardet:', 1.0764693665798812, 'call(s)/s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment