switch to ESM
[benchmarks-js.git] / uuid-generator.mjs
diff --git a/uuid-generator.mjs b/uuid-generator.mjs
new file mode 100644 (file)
index 0000000..92e15d8
--- /dev/null
@@ -0,0 +1,32 @@
+import crypto from 'crypto'
+import Benchmark from 'benny'
+import { v4 as uuid } from 'uuid'
+
+Benchmark.suite(
+  'UUIDv4 generator',
+  Benchmark.add('crypto randomUUID', () => {
+    crypto.randomUUID()
+  }),
+  Benchmark.add('uuid', () => {
+    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
+  })
+).catch(err => {
+  console.error(err)
+})