From: Jérôme Benoit Date: Tue, 25 Oct 2022 15:57:13 +0000 (+0200) Subject: Tests cleanups X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bb578730a26e9d1ba7da2b40c084b5f70fa8f0c6;p=benchmarks-js.git Tests cleanups Signed-off-by: Jérôme Benoit --- diff --git a/empty-array.js b/empty-array.js index a6a8acd..a56a824 100644 --- a/empty-array.js +++ b/empty-array.js @@ -1,10 +1,11 @@ const Benchmark = require('benny') const { generateRandomNumberArray } = require('./benchmark-utils') -let testArray = generateRandomNumberArray(10000) +const size = 10000 +let testArray = generateRandomNumberArray(size) Benchmark.suite( - 'Empty array', + `Empty array with ${size} elements`, Benchmark.add('length = 0', () => { testArray.length = 0 }), diff --git a/fibonacci.js b/fibonacci.js index edde903..286c69c 100644 --- a/fibonacci.js +++ b/fibonacci.js @@ -48,7 +48,7 @@ function fibonacciRecursionMemoization (num, memo) { } Benchmark.suite( - 'Fibonacci', + `Fibonacci number ${number}`, Benchmark.add('fibonacciLoop', () => { fibonacciLoop(number) }), diff --git a/empty-object.js b/is-empty-object.js similarity index 58% rename from empty-object.js rename to is-empty-object.js index 17be7fe..b27dc10 100644 --- a/empty-object.js +++ b/is-empty-object.js @@ -1,13 +1,18 @@ const Benchmark = require('benny') +const { generateRandomInteger } = require('./benchmark-utils') -const emptyLiteral = {} +const size = generateRandomInteger(100000) +const testObject = {} +for (let i = 0; i < size; i++) { + testObject[i.toString()] = i +} Benchmark.suite( - 'Empty object', - Benchmark.add('Reflect keys', (obj = emptyLiteral) => { + `Is empty object with ${size} keys`, + Benchmark.add('Reflect keys', (obj = testObject) => { return Reflect.ownKeys(obj).length === 0 && obj.constructor === Object }), - Benchmark.add('Keys iteration ', (obj = emptyLiteral) => { + Benchmark.add('Keys iteration ', (obj = testObject) => { if (obj.constructor !== Object) return false // Iterates over the keys of an object, if // any exist, return false. @@ -15,23 +20,23 @@ Benchmark.suite( for (const _ in obj) return false return true }), - Benchmark.add('Object keys', (obj = emptyLiteral) => { + Benchmark.add('Object keys', (obj = testObject) => { return obj.constructor === Object && !Object.keys(obj).length }), Benchmark.cycle(), Benchmark.complete(), Benchmark.save({ - file: 'empty-object', + file: 'is-empty-object', format: 'json', details: true }), Benchmark.save({ - file: 'empty-object', + file: 'is-empty-object', format: 'chart.html', details: true }), Benchmark.save({ - file: 'empty-object', + file: 'is-empty-object', format: 'table.html', details: true }) diff --git a/max.js b/max.js index 74f6f43..be3f781 100644 --- a/max.js +++ b/max.js @@ -1,7 +1,8 @@ const Benchmark = require('benny') const { generateRandomNumberArray } = require('./benchmark-utils') -const testArray = generateRandomNumberArray(10000) +const size = 10000 +const testArray = generateRandomNumberArray(size) /** * @@ -44,7 +45,7 @@ function sortMax (values) { } Benchmark.suite( - 'max', + `Max from ${size} numbers`, Benchmark.add('Math.max', () => { Math.max(...testArray) }), diff --git a/package-lock.json b/package-lock.json index ed04714..0d482d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,9 +16,9 @@ "devDependencies": { "eslint": "^8.26.0", "eslint-config-standard": "^17.0.0", - "eslint-define-config": "^1.7.0", + "eslint-define-config": "^1.8.0", "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jsdoc": "^39.3.20", + "eslint-plugin-jsdoc": "^39.3.24", "eslint-plugin-n": "^15.3.0", "eslint-plugin-promise": "^6.1.1", "husky": "^8.0.1", @@ -838,9 +838,9 @@ } }, "node_modules/eslint-define-config": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/eslint-define-config/-/eslint-define-config-1.7.0.tgz", - "integrity": "sha512-13zk8z8eKO4tpPMvAGV0sa6ok0XuMeu7Zhcizu2bLwcLy1fbNt7/h8PU1wbp9IoIgQETggZJozU0nPXUXOao2g==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/eslint-define-config/-/eslint-define-config-1.8.0.tgz", + "integrity": "sha512-YibjbNkHKMo3QAnV3bgc+BdvmYCcCpuoRdAIc+6W/P91G02ZOrCVaPrco9Uf4md25NanjkV2bnfwce8XfPRS7A==", "dev": true, "funding": [ { @@ -958,9 +958,9 @@ "dev": true }, "node_modules/eslint-plugin-jsdoc": { - "version": "39.3.20", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.3.20.tgz", - "integrity": "sha512-A9pAm4lQeDKyzu6wuMUZS+FQceu6S2G18o9Mld0a48NAeLaLPg9TpoXM2Xv85LZ3AnKUtx+jR9SxXJLgCQiifQ==", + "version": "39.3.24", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.3.24.tgz", + "integrity": "sha512-ePTnAvTKc/Ux97PgffhsgJcQVJimaNxb5yA4nwhHg+gZ21rjFQmOyowDDYe2u/L9ClwRGmwLq7/K422bTh+2Zg==", "dev": true, "dependencies": { "@es-joy/jsdoccomment": "~0.33.0", @@ -4317,9 +4317,9 @@ "dev": true }, "eslint-define-config": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/eslint-define-config/-/eslint-define-config-1.7.0.tgz", - "integrity": "sha512-13zk8z8eKO4tpPMvAGV0sa6ok0XuMeu7Zhcizu2bLwcLy1fbNt7/h8PU1wbp9IoIgQETggZJozU0nPXUXOao2g==", + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/eslint-define-config/-/eslint-define-config-1.8.0.tgz", + "integrity": "sha512-YibjbNkHKMo3QAnV3bgc+BdvmYCcCpuoRdAIc+6W/P91G02ZOrCVaPrco9Uf4md25NanjkV2bnfwce8XfPRS7A==", "dev": true }, "eslint-import-resolver-node": { @@ -4411,9 +4411,9 @@ } }, "eslint-plugin-jsdoc": { - "version": "39.3.20", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.3.20.tgz", - "integrity": "sha512-A9pAm4lQeDKyzu6wuMUZS+FQceu6S2G18o9Mld0a48NAeLaLPg9TpoXM2Xv85LZ3AnKUtx+jR9SxXJLgCQiifQ==", + "version": "39.3.24", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-39.3.24.tgz", + "integrity": "sha512-ePTnAvTKc/Ux97PgffhsgJcQVJimaNxb5yA4nwhHg+gZ21rjFQmOyowDDYe2u/L9ClwRGmwLq7/K422bTh+2Zg==", "dev": true, "requires": { "@es-joy/jsdoccomment": "~0.33.0", diff --git a/package.json b/package.json index 74f6bcd..53fbf27 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "prepare": "node prepare.js", "benchmark:busy-wait": "node busy-wait.js", "benchmark:empty-array": "node empty-array.js", - "benchmark:empty-object": "node empty-object.js", + "benchmark:is-empty-object": "node is-empty-object.js", "benchmark:quick-select": "node quick-select.js", "benchmark:max": "node max.js", "benchmark:promise-handling": "node promise-handling.js", @@ -32,9 +32,9 @@ "devDependencies": { "eslint": "^8.26.0", "eslint-config-standard": "^17.0.0", - "eslint-define-config": "^1.7.0", + "eslint-define-config": "^1.8.0", "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jsdoc": "^39.3.20", + "eslint-plugin-jsdoc": "^39.3.24", "eslint-plugin-n": "^15.3.0", "eslint-plugin-promise": "^6.1.1", "husky": "^8.0.1",