typia icon indicating copy to clipboard operation
typia copied to clipboard

https://typia.io/docs/json/stringify/ performance claims are at least misleading

Open alpharder opened this issue 2 years ago • 3 comments

a) Every single benchmark result demonstrates clear superiority of typia.stringify() over JSON.stringify() while its only true for small payloads. Please add benchmarks for larger payloads. b) Unlike https://www.npmjs.com/package/fast-json-stringify, your website never mentions that JSON.stringify() will always be faster for larger payloads.

For reference, my benchmarking results. For 3MB of JSON:

cpu: Apple M1
runtime: node v20.8.1 (arm64-darwin)

benchmark                time (avg)             (min … max)
-----------------------------------------------------------
• JSON stringification
-----------------------------------------------------------
baseline noop        319.35 ps/iter   (304.1 ps … 12.77 ns)
V8 JSON.stringify()    2.85 ms/iter     (2.76 ms … 5.01 ms)
typia.stringify()      4.53 ms/iter     (3.84 ms … 5.74 ms)

summary for JSON stringification
  baseline noop
   8932241.9x faster than V8 JSON.stringify()
   14197504.04x faster than typia.stringify()

For 37Kb of JSON:

cpu: Apple M1
runtime: node v20.8.1 (arm64-darwin)

benchmark                time (avg)             (min … max)
-----------------------------------------------------------
• JSON stringification
-----------------------------------------------------------
baseline noop        318.77 ps/iter    (304.1 ps … 10.5 ns)
V8 JSON.stringify()   35.57 µs/iter     (34.5 µs … 1.21 ms)
typia.stringify()     49.44 µs/iter   (37.63 µs … 12.18 ms)

summary for JSON stringification
  baseline noop
   111575.59x faster than V8 JSON.stringify()
   155086.52x faster than typia.stringify()

For 9Kb of JSON:

cpu: Apple M1
runtime: node v20.8.1 (arm64-darwin)

benchmark                time (avg)             (min … max)
-----------------------------------------------------------
• JSON stringification
-----------------------------------------------------------
baseline noop        444.66 ps/iter    (304.1 ps … 2.61 µs)
V8 JSON.stringify()    9.01 µs/iter   (8.58 µs … 387.21 µs)
typia.stringify()     12.66 µs/iter     (9.88 µs … 1.65 ms)

summary for JSON stringification
  baseline noop
   20253.66x faster than V8 JSON.stringify()
   28480.16x faster than typia.stringify()

Benchmark source code:

import {run, bench, group, baseline} from 'mitata';
import {readFileSync} from "fs";
import {Doc} from './type.js'; // imported TS type
import * as typia from "typia";

const inMemParsedJson = JSON.parse(readFileSync('./doc3mb.json').toString()); // imported JSON file

const typiaStringifyFn = typia.json.createStringify<Doc>();


group('JSON stringification', () => {
    baseline('baseline noop', () => {
    });
    bench('V8 JSON.stringify()', () => JSON.stringify(inMemParsedJson));

    bench('typia.stringify()', () => typiaStringifyFn(inMemParsedJson));
});

await run({
    avg: true, // enable/disable avg column (default: true)
    json: false, // enable/disable json output (default: false)
    colors: true, // enable/disable colors (default: true)
    min_max: true, // enable/disable min/max column (default: true)
    collect: false, // enable/disable collecting returned values into an array during the benchmark (default: false)
    percentiles: false, // enable/disable percentiles column (default: true)
});

alpharder avatar Oct 27 '23 03:10 alpharder

Okay, wait your PR about Doc type and its data

samchon avatar Oct 27 '23 03:10 samchon

Not yet?

samchon avatar Jan 19 '24 17:01 samchon

This also should be moved to discussion

ryoppippi avatar Jun 21 '24 15:06 ryoppippi