From 75774f628aa43f84eb098baa449e5b865a7647b7 Mon Sep 17 00:00:00 2001 From: PyYoshi Date: Mon, 17 Oct 2016 13:04:33 +0900 Subject: [PATCH] update benchmark --- src/tests/bench.py | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/tests/bench.py b/src/tests/bench.py index 9843e7b..62c3bd3 100644 --- a/src/tests/bench.py +++ b/src/tests/bench.py @@ -1,30 +1,33 @@ #!/usr/bin/env python # coding: utf-8 +import time + import cchardet import chardet -class TestCchardetSpeed(): - def test_speed(self): - import time - do_times = 5 - path = r'tests/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt' - with open(path, 'rb') as f: - msg = f.read() +def main(): + do_times = 100 + path = r'tests/testdata/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt' + 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') + # 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') - # 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') + # 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') + +if __name__ == '__main__': + main()