From: Jérôme Benoit Date: Wed, 26 Oct 2022 21:28:27 +0000 (+0200) Subject: Add is undefined benchmark X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=adad2e802d5120d237bb9620a1987535271f9784;p=benchmarks-js.git Add is undefined benchmark Signed-off-by: Jérôme Benoit --- diff --git a/is-empty-object.js b/is-empty-object.js index 2b3be46..d5d7fd7 100644 --- a/is-empty-object.js +++ b/is-empty-object.js @@ -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 index 0000000..bc00933 --- /dev/null +++ b/is-undefined.js @@ -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 + }) +) diff --git a/package.json b/package.json index 5246660..343d910 100644 --- a/package.json +++ b/package.json @@ -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",