mingyuetutu0527 commited on
Commit
efb887d
·
verified ·
1 Parent(s): c576c02

Add benchmark dataset, method and dataset card

Browse files

108 measured canvas.toBlob runs; see METHOD.md for reproducibility.

Files changed (3) hide show
  1. METHOD.md +110 -0
  2. README.md +58 -0
  3. data/browser-encoder-benchmarks.csv +109 -0
METHOD.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Method
2
+
3
+ Every number in `data/browser-encoder-benchmarks.csv` was produced by running
4
+ `tools/bench.html` in headless Chrome on one machine. Nothing in the CSV is
5
+ estimated, copied from another site, or extrapolated from a formula.
6
+
7
+ ## Environment
8
+
9
+ | Item | Value |
10
+ |---|---|
11
+ | Browser | Chrome 156.0.8078.80 (headless) |
12
+ | OS | Windows 11 Pro, x64 |
13
+ | Encoders | `canvas.toBlob()` — the browser's own JPEG and WebP encoders |
14
+ | Run date | 2026-11-03 |
15
+ | Harness | `tools/bench.html`, driven by `tools/run-headless.js` over the DevTools protocol |
16
+
17
+ ## What is measured
18
+
19
+ For each combination of source pattern, source resolution, output format and
20
+ target size, the harness records the blob the encoder actually returns: its
21
+ byte size, the quality setting it settled on, and the downscale factor applied
22
+ to the pixels.
23
+
24
+ Matrix: 3 patterns × 3 resolutions × 2 formats × 6 targets = 108 runs.
25
+
26
+ - Patterns: `photo`, `screenshot`, `flat`
27
+ - Resolutions: 4000×3000, 1920×1080, 1024×1024
28
+ - Formats: `image/jpeg`, `image/webp`
29
+ - Targets: 20, 50, 100, 200, 500, 1024 KB (1 KB = 1024 bytes here)
30
+
31
+ ## How the test images are generated
32
+
33
+ No stock photos are shipped with this repo. Each source image is drawn on a
34
+ canvas from a seeded linear congruential generator, so the same pattern at the
35
+ same resolution is byte-identical on every machine and every run.
36
+
37
+ - `photo` — a three-stop diagonal gradient, 60 translucent discs, then ±13
38
+ levels of per-pixel grain. The grain is the point: it is what makes a
39
+ photograph expensive to encode, and it is the main reason a photo cannot be
40
+ squeezed as hard as a screenshot.
41
+ - `screenshot` — white background, dark word-shaped blocks on a regular
42
+ baseline grid, 8 coloured rectangles. Sharp edges, flat colour: the opposite
43
+ case, where the encoder can spend almost nothing.
44
+ - `flat` — a near-solid two-stop vertical gradient. The floor case: what a
45
+ target size looks like when the content is trivially compressible.
46
+
47
+ These are synthetic. They are reproducible and they bracket the range, but
48
+ they are not your photos. See the caveats below.
49
+
50
+ ## The search
51
+
52
+ Same policy the site uses, reimplemented in `tools/hit-target-size.js`:
53
+
54
+ 1. Hold the pixel dimensions. Binary-search quality in [0.40, 0.95], 7 steps.
55
+ 2. If quality 0.40 at full resolution still overshoots the target, binary-search
56
+ the downscale factor in [0.05, 1.0] at quality 0.40, 7 steps.
57
+ 3. At the largest scale that fits, spend the leftover budget on quality: another
58
+ 7-step binary search in [0.40, 0.95] at that scale.
59
+ 4. If nothing fits, the row is recorded with `fits=0` and the smallest attempt.
60
+
61
+ 7 steps over a 0.55-wide range resolves quality to about 0.4%, finer than the
62
+ encoder's own quantisation, at a cost of up to 21 full encodes per cell.
63
+
64
+ ### One artifact worth knowing about
65
+
66
+ Downscaling is not a gentle dial. `drawImage` resamples every pixel, which
67
+ destroys high-frequency detail — and high-frequency detail is exactly what costs
68
+ bytes. On the grain-heavy `photo` source a 0.4% reduction in scale cut the WebP
69
+ blob from 611,160 bytes to 156,668 bytes in a single step. That is a real
70
+ measurement, not a bug, and it is why the rows in this dataset are not a smooth
71
+ function of scale: a small downscale can free up far more budget than the pixel
72
+ count suggests.
73
+
74
+ ## Caveats — read these before quoting a row
75
+
76
+ - **Synthetic sources, not photographs.** A real 12 MP camera JPEG has
77
+ different noise characteristics. Expect real photos to need more aggressive
78
+ settings than the `photo` rows here.
79
+ - **One browser, one build.** Chrome 156's JPEG and WebP encoders. Firefox and
80
+ Safari use different implementations and will not produce these exact bytes.
81
+ - **Encoder output is not monotonic in quality.** `toBlob()` at quality q and
82
+ q+0.001 can return the same or even a larger blob. The binary search assumes
83
+ monotonicity as a working approximation; individual rows can therefore land a
84
+ fraction of a percent under the target rather than exactly on it.
85
+ - **Colour management is not exercised.** Sources are sRGB canvases. Images
86
+ carrying an embedded ICC profile are converted by the browser before encoding
87
+ and can behave differently.
88
+ - **`image/webp` quality in Chrome is not the same scale as JPEG quality.** The
89
+ numbers are comparable within a format, not across formats.
90
+
91
+ ## Reproducing
92
+
93
+ ```
94
+ # serve the folder (file:// works too, but a local server is cleaner)
95
+ python -m http.server 8000
96
+
97
+ # open tools/bench.html in Chrome, then from the DevTools console:
98
+ await runAll() # returns the CSV as a string
99
+ ```
100
+
101
+ Or drive it headless:
102
+
103
+ ```
104
+ chrome --headless=new --remote-debugging-port=9444 \
105
+ --user-data-dir=/tmp/bench file:///path/to/tools/bench.html
106
+
107
+ node tools/run-headless.js 9444 out.csv
108
+ ```
109
+
110
+ Expect 10-20 minutes on a laptop: the 4000×3000 photo cells dominate the run.
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ pretty_name: Browser JPEG/WebP target-size benchmarks
4
+ language:
5
+ - en
6
+ tags:
7
+ - image-compression
8
+ - jpeg
9
+ - webp
10
+ - canvas
11
+ - benchmarks
12
+ - web-performance
13
+ configs:
14
+ - config_name: default
15
+ data_files:
16
+ - split: train
17
+ path: data/browser-encoder-benchmarks.csv
18
+ ---
19
+
20
+ # Browser JPEG/WebP target-size benchmarks
21
+
22
+ Measured byte outputs of browser-side `canvas.toBlob()` encoding for **3 synthetic image
23
+ classes** (photo, screenshot, flat) × **3 source resolutions** × **2 formats** (JPEG, WebP)
24
+ × **6 target sizes** (20KB, 50KB, 100KB, 200KB, 500KB, 1MB) = **108 measurement runs**.
25
+
26
+ Each row records the quality and scale parameters a binary search chose, the final output
27
+ dimensions, and the resulting byte size — so you can see what it actually costs, in pixels
28
+ and quality, to hit a target file size in the browser.
29
+
30
+ ## What the data shows
31
+
32
+ - A 12MP photo cannot keep its full resolution at a 200KB JPEG target: it lands at
33
+ 3139×2354 (7.4MP) with quality already at the 0.40 floor.
34
+ - Screenshots are far easier: 1920×1080 fits 200KB at quality 0.76, but the same image
35
+ needs 395×222 to fit 20KB.
36
+ - A near-flat image always encodes to ~14KB regardless of the target (20KB or 1MB) —
37
+ there is nothing left to compress. Any tool claiming "compressed to 1MB" on such an
38
+ image is reporting the target, not the result.
39
+ - 32 of the 108 runs had to give up resolution; the other 76 fit by lowering quality alone.
40
+
41
+ ## Files
42
+
43
+ - `data/browser-encoder-benchmarks.csv` — the 108 runs.
44
+ - `METHOD.md` — browser version, machine, how the synthetic images are generated, the
45
+ search algorithm, and five stated limitations (synthetic images are not your photos,
46
+ single browser, encoder non-monotonicity, ICC handling, WebP quality scale ≠ JPEG).
47
+
48
+ ## Reproduce
49
+
50
+ The harness that produced this CSV is public, and the synthetic images use a fixed seed,
51
+ so a rerun on the same browser version yields the same numbers:
52
+
53
+ - Source repository: <https://github.com/mingyuetutu0527-glitch/exact-size-benchmarks>
54
+ - Archived dataset (DOI): <https://doi.org/10.5281/zenodo.23916007>
55
+
56
+ ## Licence
57
+
58
+ MIT. Free to reuse with attribution to this dataset.
data/browser-encoder-benchmarks.csv ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pattern,src_w,src_h,format,target_kb,target_bytes,out_bytes,out_w,out_h,quality,scale,fits
2
+ photo,4000,3000,jpeg,20,20480,20446,1328,996,0.413,0.332,1
3
+ photo,4000,3000,jpeg,50,51200,50914,2011,1508,0.404,0.503,1
4
+ photo,4000,3000,jpeg,100,102400,98388,2486,1864,0.404,0.621,1
5
+ photo,4000,3000,jpeg,200,204800,201398,3139,2354,0.404,0.785,1
6
+ photo,4000,3000,jpeg,500,512000,506505,4000,3000,0.404,1.000,1
7
+ photo,4000,3000,jpeg,1024,1048576,1014515,4000,3000,0.645,1.000,1
8
+ photo,4000,3000,webp,20,20480,20386,1863,1397,0.409,0.466,1
9
+ photo,4000,3000,webp,50,51200,50950,2664,1998,0.426,0.666,1
10
+ photo,4000,3000,webp,100,102400,100764,3347,2510,0.417,0.837,1
11
+ photo,4000,3000,webp,200,204800,195554,3970,2978,0.439,0.993,1
12
+ photo,4000,3000,webp,500,512000,474058,3970,2978,0.654,0.993,1
13
+ photo,4000,3000,webp,1024,1048576,1036614,4000,3000,0.559,1.000,1
14
+ photo,1920,1080,jpeg,20,20480,20256,1165,655,0.404,0.607,1
15
+ photo,1920,1080,jpeg,50,51200,50930,1664,936,0.404,0.866,1
16
+ photo,1920,1080,jpeg,100,102400,101494,1920,1080,0.421,1.000,1
17
+ photo,1920,1080,jpeg,200,204800,201042,1920,1080,0.671,1.000,1
18
+ photo,1920,1080,jpeg,500,512000,492620,1920,1080,0.864,1.000,1
19
+ photo,1920,1080,jpeg,1024,1048576,926818,1920,1080,0.950,1.000,1
20
+ photo,1920,1080,webp,20,20480,20462,1564,880,0.413,0.814,1
21
+ photo,1920,1080,webp,50,51200,51080,1906,1072,0.507,0.993,1
22
+ photo,1920,1080,webp,100,102400,100374,1906,1072,0.684,0.993,1
23
+ photo,1920,1080,webp,200,204800,203430,1920,1080,0.593,1.000,1
24
+ photo,1920,1080,webp,500,512000,499366,1920,1080,0.855,1.000,1
25
+ photo,1920,1080,webp,1024,1048576,844408,1920,1080,0.950,1.000,1
26
+ photo,1024,1024,jpeg,20,20480,20003,750,750,0.404,0.733,1
27
+ photo,1024,1024,jpeg,50,51200,50763,1024,1024,0.404,1.000,1
28
+ photo,1024,1024,jpeg,100,102400,100904,1024,1024,0.654,1.000,1
29
+ photo,1024,1024,jpeg,200,204800,202635,1024,1024,0.821,1.000,1
30
+ photo,1024,1024,jpeg,500,512000,479645,1024,1024,0.950,1.000,1
31
+ photo,1024,1024,jpeg,1024,1048576,479645,1024,1024,0.950,1.000,1
32
+ photo,1024,1024,webp,20,20480,20450,978,978,0.404,0.955,1
33
+ photo,1024,1024,webp,50,51200,49182,1016,1016,0.641,0.993,1
34
+ photo,1024,1024,webp,100,102400,101960,1024,1024,0.563,1.000,1
35
+ photo,1024,1024,webp,200,204800,204008,1024,1024,0.804,1.000,1
36
+ photo,1024,1024,webp,500,512000,438110,1024,1024,0.950,1.000,1
37
+ photo,1024,1024,webp,1024,1048576,438110,1024,1024,0.950,1.000,1
38
+ screenshot,4000,3000,jpeg,20,20480,20446,319,239,0.563,0.080,1
39
+ screenshot,4000,3000,jpeg,50,51200,51054,645,484,0.404,0.161,1
40
+ screenshot,4000,3000,jpeg,100,102400,101611,1120,840,0.404,0.280,1
41
+ screenshot,4000,3000,jpeg,200,204800,203867,2219,1664,0.413,0.555,1
42
+ screenshot,4000,3000,jpeg,500,512000,504238,4000,3000,0.941,1.000,1
43
+ screenshot,4000,3000,jpeg,1024,1048576,516845,4000,3000,0.950,1.000,1
44
+ screenshot,4000,3000,webp,20,20480,20448,556,417,0.464,0.139,1
45
+ screenshot,4000,3000,webp,50,51200,50846,4000,3000,0.911,1.000,1
46
+ screenshot,4000,3000,webp,100,102400,51738,4000,3000,0.950,1.000,1
47
+ screenshot,4000,3000,webp,200,204800,51738,4000,3000,0.950,1.000,1
48
+ screenshot,4000,3000,webp,500,512000,51738,4000,3000,0.950,1.000,1
49
+ screenshot,4000,3000,webp,1024,1048576,51738,4000,3000,0.950,1.000,1
50
+ screenshot,1920,1080,jpeg,20,20480,20473,395,222,0.443,0.206,1
51
+ screenshot,1920,1080,jpeg,50,51200,51188,752,423,0.404,0.391,1
52
+ screenshot,1920,1080,jpeg,100,102400,101400,1279,719,0.404,0.666,1
53
+ screenshot,1920,1080,jpeg,200,204800,203475,1920,1080,0.761,1.000,1
54
+ screenshot,1920,1080,jpeg,500,512000,281146,1920,1080,0.950,1.000,1
55
+ screenshot,1920,1080,jpeg,1024,1048576,281146,1920,1080,0.950,1.000,1
56
+ screenshot,1920,1080,webp,20,20480,20472,723,407,0.434,0.377,1
57
+ screenshot,1920,1080,webp,50,51200,38926,1920,1080,0.950,1.000,1
58
+ screenshot,1920,1080,webp,100,102400,38926,1920,1080,0.950,1.000,1
59
+ screenshot,1920,1080,webp,200,204800,38926,1920,1080,0.950,1.000,1
60
+ screenshot,1920,1080,webp,500,512000,38926,1920,1080,0.950,1.000,1
61
+ screenshot,1920,1080,webp,1024,1048576,38926,1920,1080,0.950,1.000,1
62
+ screenshot,1024,1024,jpeg,20,20480,20354,287,287,0.421,0.280,1
63
+ screenshot,1024,1024,jpeg,50,51200,51142,598,598,0.404,0.584,1
64
+ screenshot,1024,1024,jpeg,100,102400,101940,1024,1024,0.421,1.000,1
65
+ screenshot,1024,1024,jpeg,200,204800,193713,1024,1024,0.950,1.000,1
66
+ screenshot,1024,1024,jpeg,500,512000,193713,1024,1024,0.950,1.000,1
67
+ screenshot,1024,1024,jpeg,1024,1048576,193713,1024,1024,0.950,1.000,1
68
+ screenshot,1024,1024,webp,20,20480,20194,652,652,0.486,0.636,1
69
+ screenshot,1024,1024,webp,50,51200,34634,1024,1024,0.950,1.000,1
70
+ screenshot,1024,1024,webp,100,102400,34634,1024,1024,0.950,1.000,1
71
+ screenshot,1024,1024,webp,200,204800,34634,1024,1024,0.950,1.000,1
72
+ screenshot,1024,1024,webp,500,512000,34634,1024,1024,0.950,1.000,1
73
+ screenshot,1024,1024,webp,1024,1048576,34634,1024,1024,0.950,1.000,1
74
+ flat,4000,3000,jpeg,20,20480,20427,2041,1530,0.731,0.510,1
75
+ flat,4000,3000,jpeg,50,51200,51195,3347,2510,0.632,0.837,1
76
+ flat,4000,3000,jpeg,100,102400,100023,4000,3000,0.941,1.000,1
77
+ flat,4000,3000,jpeg,200,204800,123401,4000,3000,0.950,1.000,1
78
+ flat,4000,3000,jpeg,500,512000,123401,4000,3000,0.950,1.000,1
79
+ flat,4000,3000,jpeg,1024,1048576,123401,4000,3000,0.950,1.000,1
80
+ flat,4000,3000,webp,20,20480,20340,3733,2800,0.731,0.933,1
81
+ flat,4000,3000,webp,50,51200,46838,4000,3000,0.950,1.000,1
82
+ flat,4000,3000,webp,100,102400,46838,4000,3000,0.950,1.000,1
83
+ flat,4000,3000,webp,200,204800,46838,4000,3000,0.950,1.000,1
84
+ flat,4000,3000,webp,500,512000,46838,4000,3000,0.950,1.000,1
85
+ flat,4000,3000,webp,1024,1048576,46838,4000,3000,0.950,1.000,1
86
+ flat,1920,1080,jpeg,20,20480,14328,1920,1080,0.933,1.000,1
87
+ flat,1920,1080,jpeg,50,51200,24175,1920,1080,0.950,1.000,1
88
+ flat,1920,1080,jpeg,100,102400,24175,1920,1080,0.950,1.000,1
89
+ flat,1920,1080,jpeg,200,204800,24175,1920,1080,0.950,1.000,1
90
+ flat,1920,1080,jpeg,500,512000,24175,1920,1080,0.950,1.000,1
91
+ flat,1920,1080,jpeg,1024,1048576,24175,1920,1080,0.950,1.000,1
92
+ flat,1920,1080,webp,20,20480,8092,1920,1080,0.950,1.000,1
93
+ flat,1920,1080,webp,50,51200,8092,1920,1080,0.950,1.000,1
94
+ flat,1920,1080,webp,100,102400,8092,1920,1080,0.950,1.000,1
95
+ flat,1920,1080,webp,200,204800,8092,1920,1080,0.950,1.000,1
96
+ flat,1920,1080,webp,500,512000,8092,1920,1080,0.950,1.000,1
97
+ flat,1920,1080,webp,1024,1048576,8092,1920,1080,0.950,1.000,1
98
+ flat,1024,1024,jpeg,20,20480,14435,1024,1024,0.950,1.000,1
99
+ flat,1024,1024,jpeg,50,51200,14435,1024,1024,0.950,1.000,1
100
+ flat,1024,1024,jpeg,100,102400,14435,1024,1024,0.950,1.000,1
101
+ flat,1024,1024,jpeg,200,204800,14435,1024,1024,0.950,1.000,1
102
+ flat,1024,1024,jpeg,500,512000,14435,1024,1024,0.950,1.000,1
103
+ flat,1024,1024,jpeg,1024,1048576,14435,1024,1024,0.950,1.000,1
104
+ flat,1024,1024,webp,20,20480,4934,1024,1024,0.950,1.000,1
105
+ flat,1024,1024,webp,50,51200,4934,1024,1024,0.950,1.000,1
106
+ flat,1024,1024,webp,100,102400,4934,1024,1024,0.950,1.000,1
107
+ flat,1024,1024,webp,200,204800,4934,1024,1024,0.950,1.000,1
108
+ flat,1024,1024,webp,500,512000,4934,1024,1024,0.950,1.000,1
109
+ flat,1024,1024,webp,1024,1048576,4934,1024,1024,0.950,1.000,1