From 5a2ce48e8284202e29a0212708ccd004c18f91de Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 3 Sep 2017 13:54:29 -0700 Subject: [PATCH 1/3] benchmark: enable assert benchmark with short len `deepequal-typedarrays.js` throws if `len` is set to 100 or less due to a hardcoded index. Calculate the index based on `len` so benchmark can be run with small `len` values if desired. --- benchmark/assert/deepequal-typedarrays.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 5d51d53d13e70f..6794ced081f1d3 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -33,7 +33,8 @@ function main(conf) { const actual = new clazz(len); const expected = new clazz(len); const expectedWrong = Buffer.alloc(len); - expectedWrong[100] = 123; + const wrongIndex = Math.floor(len / 2); + expectedWrong[wrongIndex] = 123; var i; switch (conf.method) { From 9e3098cf226be7e778c765c7e71dff9bcdb075d6 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 3 Sep 2017 14:06:09 -0700 Subject: [PATCH 2/3] benchmark: provide default methods for assert The benchmarks for `assert` all take a `method` configuration option, but the allowable values are different across the files. For each benchmark, provide an arbitrary default if `method` is set to an empty string. This allows all the `assert` benchmarks to be run with a single command but only on a single method. This is primarily useful for testing that the assert benchmark files don't contain egregious errors. (In other words, it's useful for testing.) --- benchmark/assert/deepequal-buffer.js | 2 ++ benchmark/assert/deepequal-map.js | 2 ++ benchmark/assert/deepequal-object.js | 2 ++ benchmark/assert/deepequal-prims-and-objs-big-array-set.js | 2 ++ benchmark/assert/deepequal-prims-and-objs-big-loop.js | 2 ++ benchmark/assert/deepequal-set.js | 2 ++ benchmark/assert/deepequal-typedarrays.js | 2 ++ benchmark/assert/throws.js | 2 ++ 8 files changed, 16 insertions(+) diff --git a/benchmark/assert/deepequal-buffer.js b/benchmark/assert/deepequal-buffer.js index 9e86aa231e69d2..d4495af69b48ef 100644 --- a/benchmark/assert/deepequal-buffer.js +++ b/benchmark/assert/deepequal-buffer.js @@ -27,6 +27,8 @@ function main(conf) { data.copy(expectedWrong); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-map.js b/benchmark/assert/deepequal-map.js index eae4a20605ca70..4976f2619834bf 100644 --- a/benchmark/assert/deepequal-map.js +++ b/benchmark/assert/deepequal-map.js @@ -46,6 +46,8 @@ function main(conf) { var values, values2; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': values = array.map((_, i) => [`str_${i}`, 123]); benchmark(assert.deepEqual, n, values); diff --git a/benchmark/assert/deepequal-object.js b/benchmark/assert/deepequal-object.js index d1a6cb69944055..2efa9452af88e1 100644 --- a/benchmark/assert/deepequal-object.js +++ b/benchmark/assert/deepequal-object.js @@ -37,6 +37,8 @@ function main(conf) { const expectedWrong = createObj(source, '4'); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js index 1e356cea51efd6..19337d7828236d 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-array-set.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-array-set.js @@ -53,6 +53,8 @@ function main(conf) { const expectedWrongSet = new Set(expectedWrong); switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_Array': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-prims-and-objs-big-loop.js b/benchmark/assert/deepequal-prims-and-objs-big-loop.js index 2800b51c491bcf..4a345f27c20f0e 100644 --- a/benchmark/assert/deepequal-prims-and-objs-big-loop.js +++ b/benchmark/assert/deepequal-prims-and-objs-big-loop.js @@ -34,6 +34,8 @@ function main(conf) { // Creates new array to avoid loop invariant code motion switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/deepequal-set.js b/benchmark/assert/deepequal-set.js index ecf44c063dfecf..aa0ebc064886a2 100644 --- a/benchmark/assert/deepequal-set.js +++ b/benchmark/assert/deepequal-set.js @@ -47,6 +47,8 @@ function main(conf) { var values, values2; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual_primitiveOnly': values = array.map((_, i) => `str_${i}`); benchmark(assert.deepEqual, n, values); diff --git a/benchmark/assert/deepequal-typedarrays.js b/benchmark/assert/deepequal-typedarrays.js index 6794ced081f1d3..8e8cc4b083a73e 100644 --- a/benchmark/assert/deepequal-typedarrays.js +++ b/benchmark/assert/deepequal-typedarrays.js @@ -38,6 +38,8 @@ function main(conf) { var i; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'deepEqual': bench.start(); for (i = 0; i < n; ++i) { diff --git a/benchmark/assert/throws.js b/benchmark/assert/throws.js index 9043799256e196..075e227f886acc 100644 --- a/benchmark/assert/throws.js +++ b/benchmark/assert/throws.js @@ -22,6 +22,8 @@ function main(conf) { var i; switch (conf.method) { + case '': + // Empty string falls through to next line as default, mostly for tests. case 'doesNotThrow': bench.start(); for (i = 0; i < n; ++i) { From 2405a3f08dffa393627c4abc1ef7d33bf3cc3ef0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 3 Sep 2017 14:13:55 -0700 Subject: [PATCH 3/3] test: add test-benchmark-assert Add minimal test for `assert` benchmarks. --- test/parallel/test-benchmark-assert.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/parallel/test-benchmark-assert.js diff --git a/test/parallel/test-benchmark-assert.js b/test/parallel/test-benchmark-assert.js new file mode 100644 index 00000000000000..a83bbf8ad8cf41 --- /dev/null +++ b/test/parallel/test-benchmark-assert.js @@ -0,0 +1,12 @@ +'use strict'; + +require('../common'); + +// Minimal test for assert benchmarks. This makes sure the benchmarks aren't +// completely broken but nothing more than that. + +const runBenchmark = require('../common/benchmark'); + +runBenchmark( + 'assert', ['len=1', 'method=', 'n=1', 'prim=null', 'size=1', 'type=Int8Array'] +);