From 4a3c66e1c292577a360c18e057de3c691b107a51 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Fri, 26 Jun 2026 09:07:04 +1000 Subject: [PATCH 1/2] chore: adds `object-identity` as known alternative --- compare.js | 33 ++++++++++++++++++++------------- package.json | 1 + readme.md | 16 +++++++++------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/compare.js b/compare.js index 6e7404f..2768707 100644 --- a/compare.js +++ b/compare.js @@ -13,22 +13,29 @@ const stringifyPackages = { 'faster-stable-stringify': true, 'json-stringify-deterministic': true, 'fast-safe-stringify': 'stable', + 'object-identity': import('object-identity').then(m => m.identify), 'safe-stable-stringify': require('.') } -for (const name in stringifyPackages) { - let fn - if (typeof stringifyPackages[name] === 'function') { - fn = stringifyPackages[name] - } else if (typeof stringifyPackages[name] === 'string') { - fn = require(name)[stringifyPackages[name]] - } else { - fn = require(name) - } +async function main () { + for (const name in stringifyPackages) { + let fn + if (typeof stringifyPackages[name] === 'function') { + fn = stringifyPackages[name] + } else if (typeof stringifyPackages[name] === 'string') { + fn = require(name)[stringifyPackages[name]] + } else if (typeof stringifyPackages[name].then === 'function') { + fn = await stringifyPackages[name] + } else { + fn = require(name) + } - suite.add(name, function () { - fn(testData) - }) + suite.add(name, function () { + fn(testData) + }) + } } -suite.run() +main().then(function () { + suite.run() +}) diff --git a/package.json b/package.json index 4739c69..10dc3c6 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "json-stable-stringify": "^1.3.0", "json-stringify-deterministic": "^1.0.12", "json-stringify-safe": "^5.0.1", + "object-identity": "^0.2.1", "bench-node": "^0.14.0", "standard": "^17.1.2", "tap": "^16.3.10", diff --git a/readme.md b/readme.md index 8f06f3d..211014f 100644 --- a/readme.md +++ b/readme.md @@ -162,13 +162,15 @@ indentation: deep circular x 16,443 ops/sec ±0.40% (97 runs sampled) Comparing `safe-stable-stringify` with known alternatives: ```md -fast-json-stable-stringify x 18,765 ops/sec ±0.71% (94 runs sampled) -json-stable-stringify x 13,870 ops/sec ±0.72% (94 runs sampled) -fast-stable-stringify x 21,343 ops/sec ±0.33% (95 runs sampled) -faster-stable-stringify x 17,707 ops/sec ±0.44% (97 runs sampled) -json-stringify-deterministic x 11,208 ops/sec ±0.57% (98 runs sampled) -fast-safe-stringify x 21,460 ops/sec ±0.75% (99 runs sampled) -this x 30,367 ops/sec ±0.39% (96 runs sampled) +fastest-stable-stringify x 53,720 ops/sec (11 runs sampled) +fast-json-stable-stringify x 48,530 ops/sec (11 runs sampled) +json-stable-stringify x 38,123 ops/sec (11 runs sampled) +fast-stable-stringify x 54,064 ops/sec (12 runs sampled) +faster-stable-stringify x 47,958 ops/sec (10 runs sampled) +json-stringify-deterministic x 35,306 ops/sec (10 runs sampled) +fast-safe-stringify x 44,133 ops/sec (10 runs sampled) +object-identity x 103,553 ops/sec (13 runs sampled) +this x 48,175 ops/sec (11 runs sampled) The fastest is this ``` From 5f4caf196a9225bcd514e39720f048d1e5f9d4a6 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Mon, 29 Jun 2026 19:38:37 +1000 Subject: [PATCH 2/2] chore: use object-identity cjs --- compare.js | 34 ++++++++++++++-------------------- package.json | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/compare.js b/compare.js index 2768707..190e4a2 100644 --- a/compare.js +++ b/compare.js @@ -13,29 +13,23 @@ const stringifyPackages = { 'faster-stable-stringify': true, 'json-stringify-deterministic': true, 'fast-safe-stringify': 'stable', - 'object-identity': import('object-identity').then(m => m.identify), + 'object-identity': 'identify', 'safe-stable-stringify': require('.') } -async function main () { - for (const name in stringifyPackages) { - let fn - if (typeof stringifyPackages[name] === 'function') { - fn = stringifyPackages[name] - } else if (typeof stringifyPackages[name] === 'string') { - fn = require(name)[stringifyPackages[name]] - } else if (typeof stringifyPackages[name].then === 'function') { - fn = await stringifyPackages[name] - } else { - fn = require(name) - } - - suite.add(name, function () { - fn(testData) - }) +for (const name in stringifyPackages) { + let fn + if (typeof stringifyPackages[name] === 'function') { + fn = stringifyPackages[name] + } else if (typeof stringifyPackages[name] === 'string') { + fn = require(name)[stringifyPackages[name]] + } else { + fn = require(name) } + + suite.add(name, function () { + fn(testData) + }) } -main().then(function () { - suite.run() -}) +suite.run() diff --git a/package.json b/package.json index 10dc3c6..6761dd2 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "json-stable-stringify": "^1.3.0", "json-stringify-deterministic": "^1.0.12", "json-stringify-safe": "^5.0.1", - "object-identity": "^0.2.1", + "object-identity": "^0.2.2", "bench-node": "^0.14.0", "standard": "^17.1.2", "tap": "^16.3.10",