-
-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple benchmark to be able to catch order-of-magnitude performance regressions. Co-authored-by: Robert Kieffer <robert@broofa.com>
- Loading branch information
Showing
7 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- | ||
Thank you for your contribution! | ||
If your pull request contains considerable changes please run the benchmark before and after your | ||
changes and include the results in the pull request description. To run the benchmark execute: | ||
npm run test:benchmark | ||
from the root of this repository. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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): | ||
|
||
``` | ||
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<title>UUID Benchmark</title> | ||
<p>Please open the Developer Console to view output</p> | ||
<script src="./node_modules/uuid/dist/umd/uuidv1.min.js"></script> | ||
<script src="./node_modules/uuid/dist/umd/uuidv3.min.js"></script> | ||
<script src="./node_modules/uuid/dist/umd/uuidv4.min.js"></script> | ||
<script src="./node_modules/uuid/dist/umd/uuidv5.min.js"></script> | ||
<script src="./node_modules/lodash/lodash.js"></script> | ||
<script src="./node_modules/benchmark/benchmark.js"></script> | ||
<script src="./benchmark.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* 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; | ||
|
||
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 () { | ||
uuidv1(null, array, 0); | ||
}) | ||
.add('uuidv4()', function () { | ||
uuidv4(); | ||
}) | ||
.add('uuidv4() fill existing array', function () { | ||
uuidv4(null, array, 0); | ||
}) | ||
.add('uuidv3()', function () { | ||
uuidv3('hello.example.com', uuidv3.DNS); | ||
}) | ||
.add('uuidv5()', function () { | ||
uuidv5('hello.example.com', uuidv5.DNS); | ||
}) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
.run(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters