New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add benchmark #430
Merged
test: add benchmark #430
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
efe24c5
test: add benchmark
ctavan caad105
Update examples/benchmark/benchmark.js
ctavan de5c6be
Update examples/benchmark/benchmark.js
ctavan 49a46aa
Update examples/benchmark/benchmark.js
ctavan bc99a4a
Update examples/benchmark/benchmark.js
ctavan 6a92ff1
fixup! test: add benchmark
ctavan f37461c
fixup! fixup! test: add benchmark
ctavan 73d5e7d
fixup! fixup! fixup! test: add benchmark
ctavan ecb7a5a
fixup! fixup! fixup! fixup! test: add benchmark
ctavan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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,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 | ||
``` |
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 UMD 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,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'; | ||
ctavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ctavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
}) | ||
ctavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.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); | ||
}) | ||
ctavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.on('cycle', function (event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
.run({ async: true }); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't of interest to most readers. Move to PR template (preferably the hidden
.github/pull_request_template.md
file).