From efe24c51efd8bb1a9f4906d0f9ebd4519bd079e2 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Thu, 30 Apr 2020 14:15:38 +0200 Subject: [PATCH 1/9] test: add benchmark Add a simple benchmark to be able to catch order-of-magnitude performance regressions. --- README.md | 11 +++++ README_js.md | 11 +++++ examples/benchmark/README.md | 24 +++++++++++ examples/benchmark/benchmark.html | 10 +++++ examples/benchmark/benchmark.js | 62 ++++++++++++++++++++++++++++ examples/benchmark/package-lock.json | 33 +++++++++++++++ examples/benchmark/package.json | 14 +++++++ package.json | 2 + 8 files changed, 167 insertions(+) create mode 100644 examples/benchmark/README.md create mode 100644 examples/benchmark/benchmark.html create mode 100644 examples/benchmark/benchmark.js create mode 100644 examples/benchmark/package-lock.json create mode 100644 examples/benchmark/package.json diff --git a/README.md b/README.md index c550e2ec..ea80c9f3 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,17 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). +## Developing + +We happily accept pull requests! + +If you do considerable changes please [run the benchmark](./examples/benchmark/) before and after +your changes and include the results in the pull request description: + +``` +npm run test:benchmark +``` + ## Upgrading From uuid\@7 ### Only Named Exports Supported When Using with Node.js ESM diff --git a/README_js.md b/README_js.md index b0442aa0..b20f5601 100644 --- a/README_js.md +++ b/README_js.md @@ -353,6 +353,17 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). +## Developing + +We happily accept pull requests! + +If you do considerable changes please [run the benchmark](./examples/benchmark/) before and after +your changes and include the results in the pull request description: + +``` +npm run test:benchmark +``` + ## Upgrading From uuid\@7 ### Only Named Exports Supported When Using with Node.js ESM diff --git a/examples/benchmark/README.md b/examples/benchmark/README.md new file mode 100644 index 00000000..a6d61e2e --- /dev/null +++ b/examples/benchmark/README.md @@ -0,0 +1,24 @@ +# uuid Benchmark + +``` +npm install +npm test +``` + +To run the benchmark in the browser open `benchmark.html` and check the console. + +Example output (`uuid@8.0.0`, MacBook Pro (Retina, 13-inch, Early 2015), 3.1 GHz Dual-Core Intel Core i7): + +``` +uuidv1() x 1,329,774 ops/sec ±1.67% (87 runs sampled) +uuidv1() fill existing array x 3,568,608 ops/sec ±1.67% (89 runs sampled) +uuidv4() x 305,160 ops/sec ±1.86% (85 runs sampled) +uuidv4() fill existing array x 352,852 ops/sec ±1.92% (85 runs sampled) +uuidv3() DNS x 115,482 ops/sec ±1.55% (80 runs sampled) +uuidv3() URL x 103,127 ops/sec ±1.49% (81 runs sampled) +uuidv3() MY_NAMESPACE x 107,009 ops/sec ±1.59% (80 runs sampled) +uuidv5() DNS x 113,219 ops/sec ±1.66% (82 runs sampled) +uuidv5() URL x 100,618 ops/sec ±4.13% (81 runs sampled) +uuidv5() MY_NAMESPACE x 95,596 ops/sec ±4.24% (74 runs sampled) +Fastest is uuidv1() fill existing array +``` diff --git a/examples/benchmark/benchmark.html b/examples/benchmark/benchmark.html new file mode 100644 index 00000000..2fc6b457 --- /dev/null +++ b/examples/benchmark/benchmark.html @@ -0,0 +1,10 @@ + +UUID UMD benchmark +

Please open the Developer Console to view output

+ + + + + + + diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js new file mode 100644 index 00000000..fccec16d --- /dev/null +++ b/examples/benchmark/benchmark.js @@ -0,0 +1,62 @@ +/* global Benchmark:false, uuidv1:false, uuidv3:false, uuidv4:false, uuidv5:false */ +const Benchmark = (typeof window !== 'undefined' && window.Benchmark) || require('benchmark'); +const uuidv1 = (typeof window !== 'undefined' && window.uuidv1) || require('uuid').v1; +const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid').v4; +const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3; +const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5; + +const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c'; + +const suite = new Benchmark.Suite(); +suite + .add('uuidv1()', function () { + uuidv1(); + }) + .add('uuidv1() fill existing array', function () { + const array = new Array(); + uuidv1(null, array, 0); + }) + .add('uuidv4()', function () { + uuidv4(); + }) + .add('uuidv4() fill existing array', function () { + const array = new Array(); + uuidv4(null, array, 0); + }) + .add('uuidv3() DNS', function () { + uuidv3('hello.example.com', uuidv3.DNS); + }) + .add('uuidv3() URL', function () { + // ... using predefined URL namespace (for, well, URLs) + uuidv3('http://example.com/hello', uuidv3.URL); + }) + .add('uuidv3() MY_NAMESPACE', function () { + // ... using a custom namespace + // + // Note: Custom namespaces should be a UUID string specific to your application! + // E.g. the one here was generated using this modules `uuid` CLI. + uuidv3('Hello, World!', MY_NAMESPACE); + }) + .add('uuidv5() DNS', function () { + // ... using predefined DNS namespace (for domain names) + uuidv5('hello.example.com', uuidv5.DNS); + }) + .add('uuidv5() URL', function () { + // ... using predefined URL namespace (for, well, URLs) + uuidv5('http://example.com/hello', uuidv5.URL); + }) + .add('uuidv5() MY_NAMESPACE', function () { + // ... using a custom namespace + // + // Note: Custom namespaces should be a UUID string specific to your application! + // E.g. the one here was generated using this modules `uuid` CLI. + // const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341'; + uuidv5('Hello, World!', MY_NAMESPACE); + }) + .on('cycle', function (event) { + console.log(String(event.target)); + }) + .on('complete', function () { + console.log('Fastest is ' + this.filter('fastest').map('name')); + }) + .run({ async: true }); diff --git a/examples/benchmark/package-lock.json b/examples/benchmark/package-lock.json new file mode 100644 index 00000000..b8c33171 --- /dev/null +++ b/examples/benchmark/package-lock.json @@ -0,0 +1,33 @@ +{ + "name": "uuid-benchmark", + "version": "0.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "benchmark": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", + "integrity": "sha1-CfPeMckWQl1JjMLuVloOvzwqVik=", + "dev": true, + "requires": { + "lodash": "^4.17.4", + "platform": "^1.3.3" + } + }, + "lodash": { + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", + "dev": true + }, + "platform": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.5.tgz", + "integrity": "sha512-TuvHS8AOIZNAlE77WUDiR4rySV/VMptyMfcfeoMgs4P8apaZM3JrnbzBiixKUv+XR6i+BXrQh8WAnjaSPFO65Q==", + "dev": true + }, + "uuid": { + "version": "file:../../.local" + } + } +} diff --git a/examples/benchmark/package.json b/examples/benchmark/package.json new file mode 100644 index 00000000..0d2ee0ee --- /dev/null +++ b/examples/benchmark/package.json @@ -0,0 +1,14 @@ +{ + "name": "uuid-benchmark", + "version": "0.0.0", + "private": true, + "scripts": { + "test": "node benchmark.js" + }, + "dependencies": { + "uuid": "file:../../.local" + }, + "devDependencies": { + "benchmark": "^2.1.4" + } +} diff --git a/package.json b/package.json index ee5e0791..a3be3513 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,8 @@ "pretest:node": "npm run build", "test:node": "npm-run-all --parallel examples:node:**", "test:pack": "./scripts/testpack.sh", + "pretest:benchmark": "npm run build", + "test:benchmark": "cd examples/benchmark && npm install && npm test", "prettier:check": "prettier --ignore-path .prettierignore --check '**/*.{js,jsx,json,md}'", "prettier:fix": "prettier --ignore-path .prettierignore --write '**/*.{js,jsx,json,md}'", "bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json", From caad105a4fc799f453cac4980e3e0c51ffe6bfc1 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:02:07 +0200 Subject: [PATCH 2/9] Update examples/benchmark/benchmark.js Co-authored-by: Robert Kieffer --- examples/benchmark/benchmark.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index fccec16d..f794c5be 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -5,7 +5,6 @@ const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3; const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5; -const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c'; const suite = new Benchmark.Suite(); suite From de5c6be5aa57ab79473d1937d7b29d718cbf96ec Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:02:18 +0200 Subject: [PATCH 3/9] Update examples/benchmark/benchmark.js Co-authored-by: Robert Kieffer --- examples/benchmark/benchmark.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index f794c5be..63c2958a 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -25,17 +25,6 @@ suite .add('uuidv3() DNS', function () { uuidv3('hello.example.com', uuidv3.DNS); }) - .add('uuidv3() URL', function () { - // ... using predefined URL namespace (for, well, URLs) - uuidv3('http://example.com/hello', uuidv3.URL); - }) - .add('uuidv3() MY_NAMESPACE', function () { - // ... using a custom namespace - // - // Note: Custom namespaces should be a UUID string specific to your application! - // E.g. the one here was generated using this modules `uuid` CLI. - uuidv3('Hello, World!', MY_NAMESPACE); - }) .add('uuidv5() DNS', function () { // ... using predefined DNS namespace (for domain names) uuidv5('hello.example.com', uuidv5.DNS); From 49a46aacff283379843a64751fac096eef54739b Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:02:28 +0200 Subject: [PATCH 4/9] Update examples/benchmark/benchmark.js Co-authored-by: Robert Kieffer --- examples/benchmark/benchmark.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index 63c2958a..d20f19c1 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -29,18 +29,6 @@ suite // ... using predefined DNS namespace (for domain names) uuidv5('hello.example.com', uuidv5.DNS); }) - .add('uuidv5() URL', function () { - // ... using predefined URL namespace (for, well, URLs) - uuidv5('http://example.com/hello', uuidv5.URL); - }) - .add('uuidv5() MY_NAMESPACE', function () { - // ... using a custom namespace - // - // Note: Custom namespaces should be a UUID string specific to your application! - // E.g. the one here was generated using this modules `uuid` CLI. - // const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341'; - uuidv5('Hello, World!', MY_NAMESPACE); - }) .on('cycle', function (event) { console.log(String(event.target)); }) From bc99a4accae3be927887e431c0e5294f8f081b81 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:02:39 +0200 Subject: [PATCH 5/9] Update examples/benchmark/benchmark.js Co-authored-by: Robert Kieffer --- examples/benchmark/benchmark.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index d20f19c1..af9155d9 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -5,6 +5,7 @@ const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3; const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5; +console.log('Starting. Tests take ~1 minute to run ...'); const suite = new Benchmark.Suite(); suite From 6a92ff12368fb0afef341ba84c3e6a88a0a91d4c Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:12:07 +0200 Subject: [PATCH 6/9] fixup! test: add benchmark --- examples/benchmark/benchmark.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/benchmark/benchmark.js b/examples/benchmark/benchmark.js index af9155d9..9e8bdca4 100644 --- a/examples/benchmark/benchmark.js +++ b/examples/benchmark/benchmark.js @@ -5,29 +5,27 @@ const uuidv4 = (typeof window !== 'undefined' && window.uuidv4) || require('uuid const uuidv3 = (typeof window !== 'undefined' && window.uuidv3) || require('uuid').v3; const uuidv5 = (typeof window !== 'undefined' && window.uuidv5) || require('uuid').v5; -console.log('Starting. Tests take ~1 minute to run ...'); +console.log('Starting. Tests take ~1 minute to run ...'); +const array = new Array(16); const suite = new Benchmark.Suite(); suite .add('uuidv1()', function () { uuidv1(); }) .add('uuidv1() fill existing array', function () { - const array = new Array(); uuidv1(null, array, 0); }) .add('uuidv4()', function () { uuidv4(); }) .add('uuidv4() fill existing array', function () { - const array = new Array(); uuidv4(null, array, 0); }) - .add('uuidv3() DNS', function () { + .add('uuidv3()', function () { uuidv3('hello.example.com', uuidv3.DNS); }) - .add('uuidv5() DNS', function () { - // ... using predefined DNS namespace (for domain names) + .add('uuidv5()', function () { uuidv5('hello.example.com', uuidv5.DNS); }) .on('cycle', function (event) { @@ -36,4 +34,4 @@ suite .on('complete', function () { console.log('Fastest is ' + this.filter('fastest').map('name')); }) - .run({ async: true }); + .run(); From f37461c4eab5f2d4921585a355ae1e18d7aa75d4 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:20:43 +0200 Subject: [PATCH 7/9] fixup! fixup! test: add benchmark --- .github/PULL_REQUEST_TEMPLATE.md | 10 ++++++++++ README.md | 11 ----------- README_js.md | 11 ----------- 3 files changed, 10 insertions(+), 22 deletions(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..3e0532ce --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,10 @@ + diff --git a/README.md b/README.md index ea80c9f3..c550e2ec 100644 --- a/README.md +++ b/README.md @@ -363,17 +363,6 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). -## Developing - -We happily accept pull requests! - -If you do considerable changes please [run the benchmark](./examples/benchmark/) before and after -your changes and include the results in the pull request description: - -``` -npm run test:benchmark -``` - ## Upgrading From uuid\@7 ### Only Named Exports Supported When Using with Node.js ESM diff --git a/README_js.md b/README_js.md index b20f5601..b0442aa0 100644 --- a/README_js.md +++ b/README_js.md @@ -353,17 +353,6 @@ import { v4 as uuidv4 } from 'uuid'; Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please). -## Developing - -We happily accept pull requests! - -If you do considerable changes please [run the benchmark](./examples/benchmark/) before and after -your changes and include the results in the pull request description: - -``` -npm run test:benchmark -``` - ## Upgrading From uuid\@7 ### Only Named Exports Supported When Using with Node.js ESM From 73d5e7d58b5780d151537ccef4ca234407bb8dbb Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:22:18 +0200 Subject: [PATCH 8/9] fixup! fixup! fixup! test: add benchmark --- examples/benchmark/README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/benchmark/README.md b/examples/benchmark/README.md index a6d61e2e..805f182e 100644 --- a/examples/benchmark/README.md +++ b/examples/benchmark/README.md @@ -10,15 +10,12 @@ To run the benchmark in the browser open `benchmark.html` and check the console. Example output (`uuid@8.0.0`, MacBook Pro (Retina, 13-inch, Early 2015), 3.1 GHz Dual-Core Intel Core i7): ``` -uuidv1() x 1,329,774 ops/sec ±1.67% (87 runs sampled) -uuidv1() fill existing array x 3,568,608 ops/sec ±1.67% (89 runs sampled) -uuidv4() x 305,160 ops/sec ±1.86% (85 runs sampled) -uuidv4() fill existing array x 352,852 ops/sec ±1.92% (85 runs sampled) -uuidv3() DNS x 115,482 ops/sec ±1.55% (80 runs sampled) -uuidv3() URL x 103,127 ops/sec ±1.49% (81 runs sampled) -uuidv3() MY_NAMESPACE x 107,009 ops/sec ±1.59% (80 runs sampled) -uuidv5() DNS x 113,219 ops/sec ±1.66% (82 runs sampled) -uuidv5() URL x 100,618 ops/sec ±4.13% (81 runs sampled) -uuidv5() MY_NAMESPACE x 95,596 ops/sec ±4.24% (74 runs sampled) +Starting. Tests take ~1 minute to run ... +uuidv1() x 1,306,861 ops/sec ±2.62% (85 runs sampled) +uuidv1() fill existing array x 4,750,515 ops/sec ±2.76% (88 runs sampled) +uuidv4() x 302,174 ops/sec ±3.06% (81 runs sampled) +uuidv4() fill existing array x 359,703 ops/sec ±3.67% (82 runs sampled) +uuidv3() x 105,667 ops/sec ±3.84% (79 runs sampled) +uuidv5() x 110,886 ops/sec ±2.55% (81 runs sampled) Fastest is uuidv1() fill existing array ``` From ecb7a5adf41c25b21bd980a7f545f3a1dc920cd6 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Fri, 1 May 2020 14:22:40 +0200 Subject: [PATCH 9/9] fixup! fixup! fixup! fixup! test: add benchmark --- examples/benchmark/benchmark.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/benchmark/benchmark.html b/examples/benchmark/benchmark.html index 2fc6b457..54be63f8 100644 --- a/examples/benchmark/benchmark.html +++ b/examples/benchmark/benchmark.html @@ -1,5 +1,5 @@ -UUID UMD benchmark +UUID Benchmark

Please open the Developer Console to view output