All posts
Lab Reports

charset-normalizer vs chardet Benchmark: 1.71x Faster

In 7 isolated runs (2026-11-18 raw data, 5000 multilingual lines, 300kb), charset-normalizer 3.5.2 (3.026ms median) was 1.71x faster than chardet (5.174ms), with shorter detection times in all runs.

Nov 18, 2026 4 min read

Across 7 repeated runs measuring a 5000-line (300kb) multilingual text buffer in this site's isolated environment on 2026-11-18, charset-normalizer 3.5.2 recorded a median detection time of 3.026ms, making it 1.71x faster than chardet (5.174ms). The full measurement records and environment specifications from 2026-11-18 are available in the Raw Data (JSON), comparing the Python encoding detection packages in the charset-normalizer repository and the chardet repository.

Original README claim and this site's isolated measurement conditions

The original README states that when comparing large text payloads with chardet's default maximum byte limit lifted, charset-normalizer's encoding detection speed is 10x faster than chardet. This 10x figure is the claim presented by the original README and is not a value directly measured by this site.

To examine this, this site directly measured and compared the full-buffer encoding detection times of charset-normalizer and chardet on deterministically generated large multilingual byte data. The hypothesis of this measurement is whether charset-normalizer finishes detection in a shorter time on the same input buffer.

The conditions of this site's experiment differ from the original documentation. Instead of using external large files and a separate setting to lift the maximum byte limit as in the original claim, we compared a single byte buffer of 5000 multilingual text lines deterministically generated in memory using each package's default detection function.

The measurement was repeated 7 times on 2026-11-18 in this site's isolated environment (Raw Data (JSON)). The isolated environment consisted of an aarch64 architecture, a Neoverse-N1 x2 (CPUQuota 150%) processor, 2048MB memory, the Ubuntu 24.04.5 LTS operating system, and the Python 3.12.3 runtime, and installing charset-normalizer 3.5.2 took 5.5 seconds (installation size: 21862778 bytes).

The input data consisted of 300kb of byte data formed by concatenating 5000 sentence lines mixing ASCII characters, Korean characters, and European characters. After performing a warm-up before measurement, we repeated the process a total of 7 times, where each run measured the combined elapsed time of detecting the same byte buffer 5 times within a single execution.

Results: encoding detection time comparison across 7 repeated runs

According to the aggregated results from the Raw Data (JSON) measured across 7 repeated runs in this site's isolated environment on 2026-11-18, the median combined elapsed time for 5 repeated detections was 3.026ms for charset-normalizer 3.5.2 and 5.174ms for chardet. The median ratio (speedup) was 1.709848 (approximately 1.71x), and in all 7 runs charset-normalizer completed encoding detection in a shorter time than chardet.

Experiment conditions
OS
Ubuntu 24.04.5 LTS
Processor
Neoverse-N1 x2, CPUQuota 150%aarch64
Memory
2,048 MB
Runtime
Python 3.12.3
Tool tested
charset-normalizer 3.5.2
Repeats
7×
Measured on
2026-11-18
Encoding detection time comparison
charset-normalizer 3.5.2 (tested)chardet (baseline)
MedianMin–maxPer-run value
Detection time ms · shorter is better
normalizer 1.71× faster
charset-normalizer7 runs
chardet7 runs

Figure. The same input was measured 7 times. Bars show the median, the line below shows min–max, and dots show each run. Raw data (JSON)

View as table · raw data from 7 runs
Detection time (ms)
Runcharset-normalizerchardet
13.015.35
23.105.07
32.955.17
43.565.11
53.025.09
63.035.32
73.055.51
Median3.035.17
Min2.955.07
Max3.565.51
MetricMedian (ms)Min (ms)Max (ms)Median Ratio (speedup)Measurement Date & Source
charsetNormalizerMs (charset-normalizer 3.5.2)3.026 ms2.948 ms3.556 ms1.709848 (approx. 1.71x)2026-11-18 Raw Data (JSON)
chardetMs (chardet)5.174 ms5.073 ms5.514 ms1 (baseline)2026-11-18 Raw Data (JSON)

Looking at the measurement range in the Raw Data (JSON) as of 2026-11-18, charset-normalizer 3.5.2 stayed between a minimum of 2.948ms and a maximum of 3.556ms. By contrast, chardet took between a minimum of 5.073ms and a maximum of 5.514ms, meaning the maximum elapsed time of charset-normalizer (3.556ms) was lower than the minimum elapsed time of chardet (5.073ms). The total process execution time (wallMs) recorded 318.215ms in the first run and remained between 265.283ms and 266.902ms in subsequent runs.

Run (run)charsetNormalizerMs (ms)chardetMs (ms)wallMs (ms)
13.013 ms5.348 ms318.215 ms
23.102 ms5.073 ms265.799 ms
32.948 ms5.174 ms265.283 ms
43.556 ms5.11 ms266.057 ms
53.022 ms5.094 ms266.902 ms
63.026 ms5.321 ms266.32 ms
73.053 ms5.514 ms265.678 ms

The evaluation criterion for this experiment is that a speedup greater than 1 aligns in direction with the original claim, whereas a speedup of 1 or less points in a different direction. Because the speedup in the 2026-11-18 measurement is 1.709848, which is greater than 1, the result aligns in direction with the original claim in that charset-normalizer completes detection in a shorter time than chardet.

However, compared against the 10x faster figure described by the original README when lifting chardet's maximum byte limit on large text, the median ratio under our conditions was 1.709848 (approximately 1.71x). There is a difference in experimental conditions: the original documentation used external large files and a separate setting to lift the byte limit, whereas this site's experiment compared a single 5000-line (300kb) byte buffer generated in memory using the default detection functions. The specific cause of the difference between the two multipliers cannot be determined from this measurement alone.

Reproduction script and measurement structure

The Python reproduction script executed on 2026-11-18 in this site's isolated environment (Raw Data (JSON)) is shown below. It concatenates 5000 lines of a UTF-8 string containing ASCII characters, Korean characters, and European characters to generate a single 300kb byte buffer.

import json
import time
import chardet
from charset_normalizer import from_bytes

line = "Log entry: status=OK, message=데이터 처리 완료 café\n".encode("utf-8")
payload = line * 5000
iterations = 5

_ = from_bytes(payload).best()
_ = chardet.detect(payload)

t0 = time.perf_counter()
for _ in range(iterations):
    res_cn = from_bytes(payload).best()
    if res_cn is None:
        raise RuntimeError("detection failed")
cn_ms = (time.perf_counter() - t0) * 1000.0

t1 = time.perf_counter()
for _ in range(iterations):
    res_cd = chardet.detect(payload)
    if not res_cd or not res_cd.get("encoding"):
        raise RuntimeError("detection failed")
cd_ms = (time.perf_counter() - t1) * 1000.0

print(json.dumps({"charsetNormalizerMs": round(cn_ms, 3), "chardetMs": round(cd_ms, 3)}))

Before starting the timer, the script calls from_bytes(payload).best() and chardet.detect(payload) once each to complete a warm-up. It then uses time.perf_counter() to record the combined elapsed time of running each function 5 times in milliseconds (ms), and raises a RuntimeError if the encoding detection result is empty to verify that detection succeeded.

Limitations of the measurement environment and practical selection criteria

The figures confirmed in the Raw Data (JSON) as of 2026-11-18 (median 3.026ms vs. 5.174ms, speedup 1.709848) hold only under the condition of measuring a single in-memory buffer of 5000 multilingual UTF-8 text lines (300kb) using default functions, 5 iterations per run across 7 repeated runs, in an environment with aarch64, Neoverse-N1 x2 (CPUQuota 150%), 2048MB memory, Ubuntu 24.04.5 LTS, and Python 3.12.3. Conditions involving legacy-encoded documents such as EUC-KR or Shift_JIS, very short strings, or directly adjusting byte-limit options on large files on disk were not measured in this experiment and cannot be determined from these results alone.

Under conditions where data must be read in chunks from a network socket or a large file without loading all bytes into memory at once, it is difficult to apply single-buffer measurement results directly. According to the chardet repository and the chardet FAQ documentation, chardet supports UniversalDetector streaming detection that feeds data line by line and terminates early once sufficient confidence is reached, mime_type reporting to identify the format of binary inputs, and EncodingEra and include_encodings filters to restrict candidate encodings. By contrast, according to the charset-normalizer repository, charset-normalizer does not support a streaming interface, but instead provides custom codec registration and direct extraction of decoded Unicode text, while the cChardet repository exists as a separate C/C++ extension binding tool.

Therefore, in a Python 3.12.3 environment where a 5000-line (300kb) multilingual UTF-8 byte buffer is loaded into memory as a whole for detection, and an MIT license along with a shorter single-buffer detection time (3.026ms measured median on 2026-11-18) is important, choosing charset-normalizer 3.5.2 is advantageous. Conversely, for pipelines that require incremental streaming detection via UniversalDetector, mime_type identification for binary files, or candidate encoding filtering based on EncodingEra, choosing chardet is appropriate even though its single-buffer detection median takes slightly longer at 5.174ms.

#charset-normalizer#chardet#Python#encoding-detection#performance-benchmark#UTF-8
Robeedau

Written by AI from public sources; numbers and claims are checked against those sources before publishing.