2016-10-17 04:04:33 +00:00
|
|
|
import time
|
|
|
|
|
2016-10-17 02:22:14 +00:00
|
|
|
import cchardet
|
|
|
|
import chardet
|
|
|
|
|
|
|
|
|
2016-10-17 04:04:33 +00:00
|
|
|
def main():
|
|
|
|
do_times = 100
|
2017-03-27 15:36:22 +00:00
|
|
|
path = r'tests/samples/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt'
|
2016-10-17 04:04:33 +00:00
|
|
|
with open(path, 'rb') as f:
|
|
|
|
msg = f.read()
|
|
|
|
|
|
|
|
# Test chardet
|
|
|
|
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')
|
2016-10-17 02:22:14 +00:00
|
|
|
|
2016-10-17 04:04:33 +00:00
|
|
|
# Test cchardet
|
|
|
|
result_cchardet = 0
|
|
|
|
for i in range(do_times):
|
|
|
|
start_cchardet = time.time()
|
|
|
|
cchardet.detect(msg)
|
|
|
|
result_cchardet += (time.time() - start_cchardet)
|
|
|
|
print('cchardet:', 1 / (result_cchardet / do_times), 'call(s)/s')
|
2016-10-17 02:22:14 +00:00
|
|
|
|
2016-10-17 04:04:33 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|