-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from emattiza/chore/add-benchmarks
update: v0.1.0 -> v0.1.1
- Loading branch information
Showing
8 changed files
with
1,601 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from io import TextIOBase | ||
import sys | ||
import time | ||
from typing import Any, Callable, Optional | ||
from pathlib import Path | ||
|
||
|
||
def benchmark_impl( | ||
msg: bytes, | ||
detector: Callable[[Any], Any], | ||
n_calls: int, | ||
module: Any, | ||
output_buf: Optional[TextIOBase] = None, | ||
): | ||
result = 0 | ||
for _ in range(n_calls): | ||
start = time.time() | ||
detector(msg) | ||
result += time.time() - start | ||
print( | ||
"%s v%s:" % (module.__name__, module.__version__), | ||
1 / (result / n_calls), | ||
"call(s)/s", | ||
file=(output_buf or sys.stdout), | ||
) | ||
|
||
|
||
def main(): | ||
import chardet | ||
import cchardet | ||
import rs_chardet | ||
|
||
do_times = 5 | ||
path = ( | ||
Path(__file__).parent | ||
) / "samples/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt" | ||
with path.open("rb") as f: | ||
msg = f.read() | ||
|
||
detector_chardet = lambda msg: chardet.detect(msg) | ||
detector_rschardet = lambda msg: rs_chardet.detect_rs_enc_name(msg) | ||
detector_cchardet = lambda msg: cchardet.detect(msg) | ||
|
||
# Test chardet | ||
benchmark_impl(msg, detector_chardet, do_times, chardet, None) | ||
benchmark_impl(msg, detector_rschardet, do_times, rs_chardet, None) | ||
benchmark_impl(msg, detector_cchardet, do_times, cchardet, None) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
1,522 changes: 1,522 additions & 0 deletions
1,522
benchmark/samples/wikipediaJa_One_Thousand_and_One_Nights_SJIS.txt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters