All posts
Lab Reports

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%).

Nov 17, 2026 4 min read

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 time 1.8 s, install size 2461929 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).

Experiment conditions
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
Serialization and deserialization time and output size
cbor-x 1.6.9 (tested)Built-in JSON (baseline)
MedianMin–maxPer-run value
Encoding time ms · shorter is better
CBOR-X 1.41× slower
cbor-x7 runs
Built-in JSON7 runs
Decoding time ms · shorter is better
CBOR-X 1.38× slower
cbor-x7 runs
Built-in JSON7 runs
Serialized output size bytes · smaller is better
CBOR-X = 77.6% of JSON
cbor-x7 runs
Built-in JSON7 runs

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
Encoding time (ms)
Runcbor-xBuilt-in JSON
1257.2183.6
2258.5178.3
3261.4183.7
4256.8180.7
5256.6186.4
6266.5179.7
7261.8185.3
Median258.5183.6
Min256.6178.3
Max266.5186.4
Decoding time (ms)
Runcbor-xBuilt-in JSON
1378.2262.8
2362.6265.1
3359.6261.8
4366.1270.6
5359.3244.7
6359.9261.1
7361.8261.3
Median361.8261.8
Min359.3244.7
Max378.2270.6
Serialized output size (bytes)
Runcbor-xBuilt-in JSON
1161,665208,297
2161,665208,297
3161,665208,297
4161,665208,297
5161,665208,297
6161,665208,297
7161,665208,297
Median161,665208,297
Min161,665208,297
Max161,665208,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%.

Metriccbor-x 1.6.9 (Median / Min ~ Max)Built-in JSON (Median / Min ~ Max)UnitRatio and Change Rate
Encoding Time (EncodeMs)258.547 (256.643 ~ 266.528)183.624 (178.332 ~ 186.418)msencodeSpeedup 0.710215
Decoding Time (DecodeMs)361.825 (359.255 ~ 378.178)261.82 (244.709 ~ 270.6)msdecodeSpeedup 0.723609
Combined Time (TotalMs)622.876 (615.897 ~ 635.363)445.555 (431.128 ~ 451.259)mstotalSpeedup 0.715319
Serialized Output Size (Bytes)161665 (161665 ~ 161665)208297 (208297 ~ 208297)BsizeChangePct -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)
1257.185183.624378.178262.814635.363446.4371616652082971319.252
2258.547178.332362.638265.121621.186443.4531616652082971318.024
3261.359183.736359.644261.82621.003445.5551616652082971267.426
4256.764180.659366.112270.6622.876451.2591616652082971319.748
5256.643186.418359.255244.709615.897431.1281616652082971318.258
6266.528179.723359.92261.055626.448440.7771616652082971319.598
7261.804185.325361.825261.275623.628446.61616652082971267.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.

#cbor-x#JSON#Node.js#serialization#CBOR#benchmark
Robeedau

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