viewof gzp_batchSize = Inputs.range([10, 1000], {value: 100, step: 10, label: "Readings per Batch"})
viewof gzp_compLevel = Inputs.range([1, 9], {value: 6, step: 1, label: "GZIP Compression Level"})
viewof gzp_dataFormat = Inputs.select(
["JSON (verbose)", "CSV (compact)", "Binary (minimal)"],
{value: "JSON (verbose)", label: "Data Format"}
)
viewof gzp_valueVariance = Inputs.select(
["Low (steady state)", "Medium (gradual drift)", "High (volatile)"],
{value: "Low (steady state)", label: "Value Variance"}
)Try It: GZIP Compression Estimator
Try It: GZIP Compression Estimator
animation
analytics-ml
edge-acquisition
Try Change GZIP Compression Level from 6 to 9.
Observe Compare Compressed, Ratio, ESP32 Compress Time, and Energy Cost at levels 6 and 9.
Explain Explain why levels 7-9 provide diminishing returns while increasing CPU time.
Technical boundaries. Raw bytes per reading are fixed by format. Compression ratio and CPU time are estimates; CPU time assumes an ESP32 at 240 MHz.
NoteTry It: GZIP Compression Estimator
Explore how batch size, data format, and compression level affect lossless GZIP compression of IoT sensor readings.
gzp_bytesPerReading = gzp_dataFormat === "JSON (verbose)" ? 45 : gzp_dataFormat === "CSV (compact)" ? 18 : 10
gzp_rawBytes = gzp_batchSize * gzp_bytesPerReading
// Compression ratio depends on level, format, and variance
gzp_baseRatio = gzp_dataFormat === "JSON (verbose)" ? 3.5 : gzp_dataFormat === "CSV (compact)" ? 2.5 : 1.8
gzp_levelMultiplier = 0.8 + (gzp_compLevel / 9) * 0.4 // 0.8 at level 1, 1.2 at level 9
gzp_varianceMultiplier = gzp_valueVariance === "Low (steady state)" ? 1.3 : gzp_valueVariance === "Medium (gradual drift)" ? 1.0 : 0.7
gzp_effectiveRatio = gzp_baseRatio * gzp_levelMultiplier * gzp_varianceMultiplier
gzp_compressedBytes = Math.round(gzp_rawBytes / gzp_effectiveRatio)
// CPU time estimate (ms on ESP32 at 240 MHz)
gzp_cpuMs = gzp_compLevel <= 3 ? gzp_rawBytes * 0.003 : gzp_compLevel <= 6 ? gzp_rawBytes * 0.006 : gzp_rawBytes * 0.015
gzp_cpuLabel = gzp_compLevel <= 3 ? "Low" : gzp_compLevel <= 6 ? "Medium" : "High"
gzp_energyMj = gzp_cpuMs * 0.1html`<div style="background: var(--bs-light, #f8f9fa); border: 1px solid var(--bs-border-color, #dee2e6); border-radius: 8px; padding: 1.2rem; color: var(--bs-body-color);">
<h4 style="margin-top:0; color: #2C3E50;">GZIP Compression Estimate</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.8rem; margin-bottom: 1rem;">
<div style="text-align: center; padding: 0.6rem; background: rgba(231,76,60,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">Raw Size</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #9f1d1d;">${(gzp_rawBytes/1024).toFixed(1)} KB</div>
</div>
<div style="text-align: center; padding: 0.6rem; background: rgba(22,160,133,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">Compressed</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #0f6b5c;">${(gzp_compressedBytes/1024).toFixed(1)} KB</div>
</div>
<div style="text-align: center; padding: 0.6rem; background: rgba(230,126,34,0.08); border-radius: 6px;">
<div style="font-size: 0.8rem; color: #374151;">Ratio</div>
<div style="font-size: 1.3rem; font-weight: bold; color: #8a4a00;">${gzp_effectiveRatio.toFixed(1)}:1</div>
</div>
</div>
<table style="width:100%; border-collapse: collapse; font-size: 0.9rem;">
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Format</strong></th>
<td style="padding: 5px 8px; text-align: right;">${gzp_dataFormat} (~${gzp_bytesPerReading} B/reading)</td>
</tr>
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Compression Level</strong></th>
<td style="padding: 5px 8px; text-align: right;">Level ${gzp_compLevel} (CPU: ${gzp_cpuLabel})</td>
</tr>
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>ESP32 Compress Time</strong></th>
<td style="padding: 5px 8px; text-align: right;">${gzp_cpuMs.toFixed(1)} ms</td>
</tr>
<tr style="border-bottom: 1px solid var(--bs-border-color, #dee2e6);">
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Energy Cost</strong></th>
<td style="padding: 5px 8px; text-align: right;">${gzp_energyMj.toFixed(2)} mJ</td>
</tr>
<tr>
<th scope="row" style="padding: 5px 8px; font-weight: normal; text-align: left;"><strong>Information Loss</strong></th>
<td style="padding: 5px 8px; text-align: right; color: #0f6b5c; font-weight: bold;">None (lossless)</td>
</tr>
</table>
<p style="margin-top: 0.8rem; padding: 0.5rem; background: rgba(52,152,219,0.06); border-radius: 4px; font-size: 0.85rem;">
<strong>Tip:</strong> ${gzp_compLevel <= 3 ? "Low compression levels (1-3) are best for real-time edge processing where CPU budget is tight." : gzp_compLevel <= 6 ? "Level 6 is the default sweet spot -- good compression with moderate CPU cost." : "Levels 7-9 provide diminishing returns. On an ESP32, the extra CPU time may cost more energy than the bandwidth saved."}
${gzp_dataFormat === "JSON (verbose)" ? " JSON's redundant keys and formatting compress well -- consider CSV or binary to reduce raw size before compression." : gzp_dataFormat === "Binary (minimal)" ? " Binary data is already compact -- GZIP yields smaller improvements. Focus on lossy techniques for further reduction." : ""}
</p>
</div>`