update benchmark
This commit is contained in:
parent
bb4df62c77
commit
75774f628a
1 changed files with 24 additions and 21 deletions
|
@ -1,30 +1,33 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
import cchardet
|
import cchardet
|
||||||
import chardet
|
import chardet
|
||||||
|
|
||||||
|
|
||||||
class TestCchardetSpeed():
|
def main():
|
||||||
def test_speed(self):
|
do_times = 100
|
||||||
import time
|
path = r'tests/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt'
|
||||||
do_times = 5
|
with open(path, 'rb') as f:
|
||||||
path = r'tests/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt'
|
msg = f.read()
|
||||||
with open(path, 'rb') as f:
|
|
||||||
msg = f.read()
|
|
||||||
|
|
||||||
# Test chardet
|
# Test chardet
|
||||||
result_chardet = 0
|
result_chardet = 0
|
||||||
for i in range(do_times):
|
for i in range(do_times):
|
||||||
start_chardet = time.time()
|
start_chardet = time.time()
|
||||||
chardet.detect(msg)
|
chardet.detect(msg)
|
||||||
result_chardet += (time.time() - start_chardet)
|
result_chardet += (time.time() - start_chardet)
|
||||||
print('chardet:', 1 / (result_chardet / do_times), 'call(s)/s')
|
print('chardet:', 1 / (result_chardet / do_times), 'call(s)/s')
|
||||||
|
|
||||||
# Test cchardet
|
# Test cchardet
|
||||||
result_cchardet = 0
|
result_cchardet = 0
|
||||||
for i in range(do_times):
|
for i in range(do_times):
|
||||||
start_cchardet = time.time()
|
start_cchardet = time.time()
|
||||||
cchardet.detect(msg)
|
cchardet.detect(msg)
|
||||||
result_cchardet += (time.time() - start_cchardet)
|
result_cchardet += (time.time() - start_cchardet)
|
||||||
print('cchardet:', 1 / (result_cchardet / do_times), 'call(s)/s')
|
print('cchardet:', 1 / (result_cchardet / do_times), 'call(s)/s')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in a new issue