Add UUID v4 generators benchmark
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Oct 2022 16:19:46 +0000 (18:19 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 24 Oct 2022 16:19:46 +0000 (18:19 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package-lock.json
package.json
uuid-generator.js [new file with mode: 0644]

index ae3c79a41808bce0d710362492c4ae6df168255b..01c510de8324675d86864bd9c7ea345f433de9b9 100644 (file)
@@ -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",
       "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",
         "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",
       "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",
         "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",
index 303d0a678bac5c532cf1f499d475bb82ee3efe5c..ba94b0cd4892381d47633b7bbd20bfc7b82d8f97 100644 (file)
@@ -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 (file)
index 0000000..11cf3c1
--- /dev/null
@@ -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
+  })
+)