feat: add JSON.stringify benchmark
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 30 Mar 2024 20:51:29 +0000 (21:51 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 30 Mar 2024 20:51:29 +0000 (21:51 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
json-stringify.mjs [new file with mode: 0644]
package.json

diff --git a/json-stringify.mjs b/json-stringify.mjs
new file mode 100644 (file)
index 0000000..de8b81a
--- /dev/null
@@ -0,0 +1,22 @@
+import { bench, group, run } from 'mitata'
+
+const sampleObj = {
+  name: 'Sid',
+  age: 29,
+  engineer: true,
+  expertise: ['html', 'css', 'react'],
+  address: {
+    city: 'New york',
+    state: 'NY'
+  }
+}
+
+group('JSON stringify', () => {
+  bench('JSON.stringify', () => {
+    JSON.stringify(sampleObj)
+  })
+})
+
+await run({
+  units: true
+})
index a4ad1bc2a07405240815f09058bcf9fd7a1ee0c9..d8b4aad884f3a8d4cdf58822ef4c2001698d0342 100644 (file)
     "preinstall": "npx --yes only-allow pnpm",
     "prepare": "node prepare.mjs",
     "benchmark:busy-wait": "node busy-wait.mjs",
-    "benchmark:empty-array": "node empty-array.mjs",
     "benchmark:deep-clone-object": "node deep-clone-object.mjs",
     "benchmark:deep-merge-object": "node deep-merge-object.mjs",
+    "benchmark:json-stringify": "node json-stringify.mjs",
+    "benchmark:empty-array": "node empty-array.mjs",
     "benchmark:shallow-clone-object": "node shallow-clone-object.mjs",
     "benchmark:is-empty-object": "node is-empty-object.mjs",
     "benchmark:is-undefined": "node is-undefined.mjs",