Add is undefined benchmark
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 26 Oct 2022 21:28:27 +0000 (23:28 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 26 Oct 2022 21:28:27 +0000 (23:28 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
is-empty-object.js
is-undefined.js [new file with mode: 0644]
package.json

index 2b3be462a39bb89952f669219c99969985617998..d5d7fd7013a1a42bb4b648ba32fa044ed66a501c 100644 (file)
@@ -12,7 +12,7 @@ Benchmark.suite(
   Benchmark.add('Reflect keys', (obj = testObject) => {
     return Reflect.ownKeys(obj).length === 0 && obj?.constructor === Object
   }),
-  Benchmark.add('Keys iteration ', (obj = testObject) => {
+  Benchmark.add('Keys iteration', (obj = testObject) => {
     if (obj?.constructor !== Object) return false
     // Iterates over the keys of an object, if
     // any exist, return false.
diff --git a/is-undefined.js b/is-undefined.js
new file mode 100644 (file)
index 0000000..bc00933
--- /dev/null
@@ -0,0 +1,28 @@
+const Benchmark = require('benny')
+
+Benchmark.suite(
+  'Is undefined',
+  Benchmark.add('=== undefined', (value = undefined) => {
+    return value === undefined
+  }),
+  Benchmark.add("typeof === 'undefined'", (value = undefined) => {
+    return typeof value === 'undefined'
+  }),
+  Benchmark.cycle(),
+  Benchmark.complete(),
+  Benchmark.save({
+    file: 'is-undefined',
+    format: 'json',
+    details: true
+  }),
+  Benchmark.save({
+    file: 'is-undefined',
+    format: 'chart.html',
+    details: true
+  }),
+  Benchmark.save({
+    file: 'is-undefined',
+    format: 'table.html',
+    details: true
+  })
+)
index 52466601c42aa9dd31c288c624f6e2a7c63dc1c8..343d9101d0922d2aa1a5d580359bb7b6995eee96 100644 (file)
@@ -14,6 +14,7 @@
     "benchmark:busy-wait": "node busy-wait.js",
     "benchmark:empty-array": "node empty-array.js",
     "benchmark:is-empty-object": "node is-empty-object.js",
+    "benchmark:is-undefined": "node is-undefined.js",
     "benchmark:quick-select": "node quick-select.js",
     "benchmark:max": "node max.js",
     "benchmark:promise-handling": "node promise-handling.js",