Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chardet.detect a lot slower than using UniversalDetector.feed with chunks #286

Open
AdrianB-sovo opened this issue Mar 5, 2024 · 0 comments

Comments

@AdrianB-sovo
Copy link

I noticed a very big difference in execution time between using chardet.detect with a complete bytes string and using UniversalDetector.feed with chunks of 1 MB.

  • With a 100 MB file, composed only of "tests tests tests tests [....]":

    • chardet.detect takes ~64 seconds.
    • UniversalDetector.feed takes ~3 seconds.
  • With the previous file on which I appended a file in MacRoman of ~10 KB (containing the character in MacRoman):

    • chardet.detect: I interrupted the execution after 20 minutes...
    • UniversalDetector.feed takes ~3 seconds.

In case you wonder what code I used, I compared the execution time of the following:

  • chardet.detect:
print(detect(original_txt))
  • UniversalDetector.feed:
num_chunks_processed = 0
for start, end in _get_chunk_slice_intervals(len(original_txt), CHUNK_SIZE):
    chunk = original_txt[start:end]
    detector.feed(chunk)
    num_chunks_processed += 1
detector.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant