Benchmarks¶
Overview
This page compares the execution time of modern_colorthief (Rust-based)
against the original colorthief (pure Python) and fast_colorthief
(C++ based).
Benchmark Script
You can reproduce the benchmarks using the following script:
benchmark_colorthief.py¶
1import os
2import timeit
3from pathlib import Path
4
5from colorthief import ColorThief
6from fast_colorthief import get_dominant_color, get_palette as f_get_palette
7from modern_colorthief import get_color, get_palette
8
9BASE_DIR = Path(__file__).resolve().parent
10path = os.path.join(BASE_DIR, "test.jpg")
11
12# --- Extracting Color ---
13start_time = timeit.default_timer()
14ColorThief(path).get_color()
15py_color_time = timeit.default_timer() - start_time
16
17start_time = timeit.default_timer()
18get_dominant_color(path, 10)
19cpp_color_time = timeit.default_timer() - start_time
20
21start_time = timeit.default_timer()
22get_color(path)
23rust_color_time = timeit.default_timer() - start_time
24
25# --- Extracting Palette ---
26start_time = timeit.default_timer()
27ColorThief(path).get_palette()
28py_palette_time = timeit.default_timer() - start_time
29
30start_time = timeit.default_timer()
31f_get_palette(path)
32cpp_palette_time = timeit.default_timer() - start_time
33
34start_time = timeit.default_timer()
35get_palette(path)
36rust_palette_time = timeit.default_timer() - start_time
37
38print(f"Python color: {py_color_time:.6f}s")
39print(f"C++ color: {cpp_color_time:.6f}s")
40print(f"Rust color: {rust_color_time:.6f}s")
41print(f"Python palette: {py_palette_time:.6f}s")
42print(f"C++ palette: {cpp_palette_time:.6f}s")
43print(f"Rust palette: {rust_palette_time:.6f}s")
Results
On a sample image, the execution times are approximately as follows:
Task |
Python (colorthief) |
C++ (fast_colorthief) |
Rust (modern_colorthief) |
|---|---|---|---|
Extracting Color |
0.219895 s |
0.021180 s |
0.019645 s |
Extracting Palette |
0.202956 s |
0.023626 s |
0.018661 s |
Warning
Benchmark results may vary depending on the image size, color complexity, and hardware. Use the script above to test on your own workloads.
See also
Median Cut Color Quantization (MMCQ) – The algorithm behind these performance numbers.