cbor-x 1.6.9 vs. Node.js Built-in JSON: Serialization Speed and Size
In 7 isolated runs (1000 records, Node.js 24.21.0, 2026-11-17), cbor-x 1.6.9 was slower than built-in JSON (total median 622.876 ms vs 445.555 ms) but cut output: 208297 B to 161665 B (-22.387264%).
As of 2026-11-17, across 7 measured runs of a 1000-record array in this site's isolated environment (Node.js 24.21.0), cbor-x 1.6.9 increased combined elapsed time compared to built-in JSON from 445.555 ms → 622.876 ms (speed ratio 0.715319), while reducing output size from 208297 B → 161665 B (-22.387264%). Detailed records of the entire measurement process are available in the raw data (JSON).
Original claims and experimental hypothesis
In the cbor-x repository, the original README explains that in a Node.js environment, its processing speed is up to 10 times faster than other JavaScript CBOR implementations (such as cbor-js and cborg) and generally faster than built-in JSON.stringify and JSON.parse.
The experimental hypothesis formulated by this site is to verify whether cbor-x records a shorter elapsed time and a smaller output size than built-in JSON when serializing and deserializing an array of structured objects in a pure JavaScript sandbox without building the optional native addon. In other words, we directly tested whether the overall speed advantage claimed in the original documentation and the size reduction effect of binary serialization also appear under default function call conditions.
Measurement environment and condition differences from the original documentation
Prior to measurement, there are two condition differences between the optimal execution setup described in the original README and this site's isolated environment. The original README explains that in a Node.js environment, it uses a native addon as an optional dependency for additional performance gains, and that using the record extension to reuse repeating object structures requires creating a new Encoder() instance or streams (EncoderStream, DecoderStream).
By contrast, this site's experiment ran under sandbox conditions with installation scripts disabled, so it operated on the pure JavaScript execution path without the optional native addon. Furthermore, without a separate Encoder instance, it called the default encode and decode functions—which serialize into standard-compatible CBOR maps (map)—to compare against built-in JSON.stringify and JSON.parse.
The specifications of this site's isolated environment and the experimental conditions are as follows:
- Architecture and CPU:
aarch64,Neoverse-N1 x2, CPUQuota 150% - Memory and OS:
2048 MB,Ubuntu 24.04.4 LTS - Runtime and target versions:
Node.js 24.21.0,cbor-x 1.6.9(install time1.8 s, install size2461929 B) - Input data: Deterministically generated an array of 1000 object records, each structured with 8 keys including strings, numbers, booleans, and arrays
- Measurement method: After a pre-measurement warmup, repeatedly encoded and decoded the same input data multiple times to record the combined elapsed time and the serialized byte size
- Repetition count and evaluation criteria: Executed a total of 7 runs in this site's isolated environment; evaluated as the same direction if
totalSpeedup(the overall serialization and deserialization speed ratio) is greater than 1, and as a different direction if 1 or less
Results: measured serialization and deserialization time and byte size
Aggregating the raw data (JSON) from 7 repeated measurements in this site's isolated environment as of 2026-11-17 showed that built-in JSON had a shorter elapsed time than cbor-x 1.6.9 for both encoding and decoding. The median encoding time went from built-in JSON 183.624 ms → cbor-x 258.547 ms (encodeSpeedup 0.710215), and the median decoding time went from built-in JSON 261.82 ms → cbor-x 361.825 ms (decodeSpeedup 0.723609).
- OS
- Ubuntu 24.04.4 LTS
- Processor
- Neoverse-N1 x2, CPUQuota 150%aarch64
- Memory
- 2,048 MB
- Runtime
- Node.js 24.21.0
- Tool tested
- cbor-x 1.6.9
- Repeats
- 7×
- Measured on
- 2026-11-17
Figure. The same input was measured 7 times. Bars show the median, the line below shows min–max, and dots show each run. Sizes were identical in all 7 runs. Raw data (JSON)
View as table · raw data from 7 runs
| Run | cbor-x | Built-in JSON |
|---|---|---|
| 1 | 257.2 | 183.6 |
| 2 | 258.5 | 178.3 |
| 3 | 261.4 | 183.7 |
| 4 | 256.8 | 180.7 |
| 5 | 256.6 | 186.4 |
| 6 | 266.5 | 179.7 |
| 7 | 261.8 | 185.3 |
| Median | 258.5 | 183.6 |
| Min | 256.6 | 178.3 |
| Max | 266.5 | 186.4 |
| Run | cbor-x | Built-in JSON |
|---|---|---|
| 1 | 378.2 | 262.8 |
| 2 | 362.6 | 265.1 |
| 3 | 359.6 | 261.8 |
| 4 | 366.1 | 270.6 |
| 5 | 359.3 | 244.7 |
| 6 | 359.9 | 261.1 |
| 7 | 361.8 | 261.3 |
| Median | 361.8 | 261.8 |
| Min | 359.3 | 244.7 |
| Max | 378.2 | 270.6 |
| Run | cbor-x | Built-in JSON |
|---|---|---|
| 1 | 161,665 | 208,297 |
| 2 | 161,665 | 208,297 |
| 3 | 161,665 | 208,297 |
| 4 | 161,665 | 208,297 |
| 5 | 161,665 | 208,297 |
| 6 | 161,665 | 208,297 |
| 7 | 161,665 | 208,297 |
| Median | 161,665 | 208,297 |
| Min | 161,665 | 208,297 |
| Max | 161,665 | 208,297 |
The median combined total elapsed time (encoding plus decoding) went from built-in JSON 445.555 ms → cbor-x 622.876 ms, recording an overall speed ratio (totalSpeedup) of 0.715319. Conversely, the byte size of the serialized output decreased from built-in JSON 208297 B → cbor-x 161665 B, resulting in a size change rate (sizeChangePct) of -22.387264%.
| Metric | cbor-x 1.6.9 (Median / Min ~ Max) | Built-in JSON (Median / Min ~ Max) | Unit | Ratio and Change Rate |
|---|---|---|---|---|
Encoding Time (EncodeMs) | 258.547 (256.643 ~ 266.528) | 183.624 (178.332 ~ 186.418) | ms | encodeSpeedup 0.710215 |
Decoding Time (DecodeMs) | 361.825 (359.255 ~ 378.178) | 261.82 (244.709 ~ 270.6) | ms | decodeSpeedup 0.723609 |
Combined Time (TotalMs) | 622.876 (615.897 ~ 635.363) | 445.555 (431.128 ~ 451.259) | ms | totalSpeedup 0.715319 |
Serialized Output Size (Bytes) | 161665 (161665 ~ 161665) | 208297 (208297 ~ 208297) | B | sizeChangePct -22.387264% |
The same pattern was consistently observed across the individual measurements of each of the 7 runs. In every run, the combined time of built-in JSON (431.128 ms ~ 451.259 ms) was shorter than the combined time of cbor-x 1.6.9 (615.897 ms ~ 635.363 ms), and the serialized byte size remained identical at 161665 B vs. 208297 B across all runs.
Run (run) | cborEncodeMs (ms) | jsonEncodeMs (ms) | cborDecodeMs (ms) | jsonDecodeMs (ms) | cborTotalMs (ms) | jsonTotalMs (ms) | cborBytes (B) | jsonBytes (B) | wallMs (ms) |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 257.185 | 183.624 | 378.178 | 262.814 | 635.363 | 446.437 | 161665 | 208297 | 1319.252 |
| 2 | 258.547 | 178.332 | 362.638 | 265.121 | 621.186 | 443.453 | 161665 | 208297 | 1318.024 |
| 3 | 261.359 | 183.736 | 359.644 | 261.82 | 621.003 | 445.555 | 161665 | 208297 | 1267.426 |
| 4 | 256.764 | 180.659 | 366.112 | 270.6 | 622.876 | 451.259 | 161665 | 208297 | 1319.748 |
| 5 | 256.643 | 186.418 | 359.255 | 244.709 | 615.897 | 431.128 | 161665 | 208297 | 1318.258 |
| 6 | 266.528 | 179.723 | 359.92 | 261.055 | 626.448 | 440.777 | 161665 | 208297 | 1319.598 |
| 7 | 261.804 | 185.325 | 361.825 | 261.275 | 623.628 | 446.6 | 161665 | 208297 | 1267.251 |
Direction evaluation against original claims and condition comparison
Evaluated according to the pre-defined criteria (same direction if totalSpeedup is greater than 1, different direction if 1 or less), totalSpeedup under these conditions was 0.715319 (1 or less), pointing in a different direction from the original README description that it is generally faster than built-in JSON.stringify and JSON.parse. Both individual metrics—encoding (0.710215) and decoding (0.723609)—also showed shorter elapsed times for built-in JSON.
Meanwhile, the claim in the original README of being up to 10 times faster than other JavaScript CBOR implementations compares against external CBOR libraries (such as cbor-js and cborg). Because this experiment only compared against Node.js 24.21.0 built-in JSON, the up-to-10x figure cannot be directly compared in this measurement.
In terms of output size, it decreased by -22.387264% from 208297 B for built-in JSON → 161665 B for cbor-x, confirming the same direction as this site's hypothesis testing whether it records a smaller output size. Behind the speed result differing from the original documentation lies a difference in execution conditions: not using the optional native addon and calling the default encode and decode functions (standard CBOR map serialization). However, we cannot conclude definitively that this difference in conditions directly caused the speed reversal, and the exact reason cannot be determined from this measurement alone.
Measurement reproduction script
The benchmark code executed in this site's isolated environment is shown below. It generates a 1000-record array, runs a warmup, and measures encoding and decoding elapsed times and byte sizes.
import { encode, decode } from 'cbor-x';
import { performance } from 'node:perf_hooks';
const dataset = Array.from({ length: 1000 }, (_, i) => ({
id: i + 1,
name: `user_record_${i}`,
active: i % 2 === 0,
score: (i * 17 + 3) / 10,
category: i % 3 === 0 ? 'alpha' : i % 3 === 1 ? 'beta' : 'gamma',
tags: [`tag_${i % 5}`, `group_${i % 7}`, 'standard'],
createdAt: 1700000000000 + i * 60000,
meta: { retries: i % 4, verified: i % 5 !== 0, region: 'ap-northeast' }
}));
for (let w = 0; w < 5; w++) {
const b = encode(dataset);
const d1 = decode(b);
const s = JSON.stringify(dataset);
const d2 = JSON.parse(s);
if (d1.length !== d2.length) throw new Error('Mismatch');
}
const iterations = 200;
const cborBytes = encode(dataset).byteLength;
const jsonBytes = Buffer.byteLength(JSON.stringify(dataset), 'utf8');
const t0 = performance.now();
let lastCbor;
for (let i = 0; i < iterations; i++) {
lastCbor = encode(dataset);
}
const cborEncodeMs = performance.now() - t0;
const t1 = performance.now();
let lastDecodedCbor;
for (let i = 0; i < iterations; i++) {
lastDecodedCbor = decode(lastCbor);
}
const cborDecodeMs = performance.now() - t1;
const t2 = performance.now();
let lastJson;
for (let i = 0; i < iterations; i++) {
lastJson = JSON.stringify(dataset);
}
const jsonEncodeMs = performance.now() - t2;
const t3 = performance.now();
let lastDecodedJson;
for (let i = 0; i < iterations; i++) {
lastDecodedJson = JSON.parse(lastJson);
}
const jsonDecodeMs = performance.now() - t3;
if (lastDecodedCbor.length !== 1000 || lastDecodedJson.length !== 1000) {
throw new Error('Validation failed');
}
const cborTotalMs = cborEncodeMs + cborDecodeMs;
const jsonTotalMs = jsonEncodeMs + jsonDecodeMs;
const round = (n) => Number(n.toFixed(3));
console.log(JSON.stringify({
cborEncodeMs: round(cborEncodeMs),
jsonEncodeMs: round(jsonEncodeMs),
cborDecodeMs: round(cborDecodeMs),
jsonDecodeMs: round(jsonDecodeMs),
cborTotalMs: round(cborTotalMs),
jsonTotalMs: round(jsonTotalMs),
cborBytes,
jsonBytes
}));
Experimental limitations and serialization tool selection criteria
These measurement results hold only under the aarch64 architecture (Neoverse-N1 x2, CPUQuota 150%, 2048 MB memory, Ubuntu 24.04.4 LTS, Node.js 24.21.0) and pure JavaScript sandbox conditions with installation scripts disabled. In environments where the native addon is built, or in workloads using Encoder instance record structure sharing (structures), stream processing (EncoderStream, DecoderStream), or circular reference cloning (structuredClone), speed and compression ratios may differ.
Therefore, in container or serverless environments where installing native addons is restricted and you need to quickly process general JSON-compatible object arrays at a 1000-record scale using only default functions, it is advantageous to stick with Node.js built-in JSON.stringify and JSON.parse, which recorded a combined median of 445.555 ms. Conversely, in environments where reducing network transfer payload or storage size from 208297 B → 161665 B (-22.387264%) is the priority—even at the computational cost of combined serialization and deserialization time increasing from 445.555 ms → 622.876 ms—adopting cbor-x is a viable choice.
Related posts
Handlebars.js vs Mustache Rendering: Measured 1.172164x Faster
2026-11-21 (Node.js 24.21.0, 1000 records, 5 runs): Handlebars.js 4.7.10 median 186.439ms, 1.172164x faster than Mustache (218.537ms). 1 fixed template has a small gap; compatibility options decide.
Mutative vs. Immer Immutable State Update Speed Comparison
In 7 sandbox runs on 2026-11-16 (Mutative 2.0.2 vs Immer), median 1000-item array combined updates fell 295.462ms → 126.116ms (2.34x) and 500-record nested updates 470.486ms → 204.711ms (2.30x).
Pino와 Console JSON 로그, 이 조건에서는 Console이 빨랐어요
격리 환경에서 구조화 로그를 기록하자 Pino 중앙값은 46.348412ms, Console 기반 JSON 로그는 24.277994ms였어요. 출력 소비 비용을 뺀 이 비교에서는 Pino가 더 빨라야 한다는 가설과 반대 방향이었고, 로거 선택 전 워크로드를 분리해 재야 한다는 결과예요.
Written by AI from public sources; numbers and claims are checked against those sources before publishing.