From 5ae4976a09a655e3bca4616b2ec2103760ea6c97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Oct 2022 18:19:46 +0200 Subject: [PATCH] Add UUID v4 generators benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 60 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 5 +++- uuid-generator.js | 34 +++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 uuid-generator.js diff --git a/package-lock.json b/package-lock.json index ae3c79a..01c510d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,9 @@ "dependencies": { "benchmark": "^2.1.4", "benny": "^3.7.1", - "microtime": "^3.1.1" + "microtime": "^3.1.1", + "uuid": "^9.0.0", + "uuidv4": "^6.2.13" }, "devDependencies": { "eslint": "^8.26.0", @@ -176,6 +178,11 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" + }, "node_modules/acorn": { "version": "8.8.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", @@ -3537,6 +3544,31 @@ "punycode": "^2.1.0" } }, + "node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/uuidv4": { + "version": "6.2.13", + "resolved": "https://registry.npmjs.org/uuidv4/-/uuidv4-6.2.13.tgz", + "integrity": "sha512-AXyzMjazYB3ovL3q051VLH06Ixj//Knx7QnUSi1T//Ie3io6CpsPu9nVMOx5MoLWh6xV0B9J0hIaxungxXUbPQ==", + "dependencies": { + "@types/uuid": "8.3.4", + "uuid": "8.3.2" + } + }, + "node_modules/uuidv4/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -3814,6 +3846,11 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "@types/uuid": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", + "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==" + }, "acorn": { "version": "8.8.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", @@ -6180,6 +6217,27 @@ "punycode": "^2.1.0" } }, + "uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==" + }, + "uuidv4": { + "version": "6.2.13", + "resolved": "https://registry.npmjs.org/uuidv4/-/uuidv4-6.2.13.tgz", + "integrity": "sha512-AXyzMjazYB3ovL3q051VLH06Ixj//Knx7QnUSi1T//Ie3io6CpsPu9nVMOx5MoLWh6xV0B9J0hIaxungxXUbPQ==", + "requires": { + "@types/uuid": "8.3.4", + "uuid": "8.3.2" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" + } + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 303d0a6..ba94b0c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "benchmark:promise-handling": "node promise-handling.js", "benchmark:fibonacci": "node fibonacci.js", "benchmark:random": "node random.js", + "benchmark:uuid-generator": "node uuid-generator.js", "format": "prettier . --write; standard . --fix", "lint": "eslint . --cache", "lint:fix": "eslint . --cache --fix", @@ -25,7 +26,9 @@ "dependencies": { "benchmark": "^2.1.4", "benny": "^3.7.1", - "microtime": "^3.1.1" + "microtime": "^3.1.1", + "uuid": "^9.0.0", + "uuidv4": "^6.2.13" }, "devDependencies": { "eslint": "^8.26.0", diff --git a/uuid-generator.js b/uuid-generator.js new file mode 100644 index 0000000..11cf3c1 --- /dev/null +++ b/uuid-generator.js @@ -0,0 +1,34 @@ +const Benchmark = require('benny') +const crypto = require('crypto') +const { v4: uuidv4 } = require('uuid') +const { uuid } = require('uuidv4') + +Benchmark.suite( + 'UUIDv4 generator', + Benchmark.add('crypto randomUUID', () => { + crypto.randomUUID() + }), + Benchmark.add('uuid', () => { + uuidv4() + }), + Benchmark.add('uuidv4', () => { + uuid() + }), + Benchmark.cycle(), + Benchmark.complete(), + Benchmark.save({ + file: 'uuid-generator', + format: 'json', + details: true + }), + Benchmark.save({ + file: 'uuid-generator', + format: 'chart.html', + details: true + }), + Benchmark.save({ + file: 'uuid-generator', + format: 'table.html', + details: true + }) +) -- 2.34.1