-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jchook/15-ios-9
Fixes iOS 9 issue and improves benchmarks
- Loading branch information
Showing
9 changed files
with
135 additions
and
60 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
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 was deleted.
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,23 @@ | ||
<html> | ||
<head> | ||
<script src="node_modules/lodash/lodash.js"></script> | ||
<script src="node_modules/benchmark/benchmark.js"></script> | ||
<script src="../index.js"></script> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
var suite = new Benchmark.Suite() | ||
console.log('Starting benchmark...') | ||
suite | ||
.add('uuid-random', uuid) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: true }) | ||
</script> | ||
</body> | ||
</html> |
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,28 @@ | ||
/** | ||
* | ||
* Benchmark using the `benchmark` module. | ||
* | ||
* Unfortunately this module somehow adds overhead to the function calls | ||
* so the true ops/sec cannot be determined. | ||
* | ||
*/ | ||
|
||
var Benchmark = require('benchmark') | ||
var suite = new Benchmark.Suite() | ||
var id128 = require('id128') | ||
|
||
suite | ||
.add('uuid-random', require('..')) | ||
.add('id128', function () { id128.Uuid4.generate().toCanonical() }) | ||
.add('portable-uuid', require('portable-uuid')) | ||
.add('uuid', require('uuid').v4) | ||
.add('nanoid', require('nanoid').nanoid) | ||
.on('cycle', function (event) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: true }) | ||
|
||
|
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,46 @@ | ||
<html> | ||
<body> | ||
<script type="text/javascript"> | ||
|
||
const HEIGHT = 250; | ||
const WIDTH = 250; | ||
const ITERS = 250000; | ||
const AREA = HEIGHT * WIDTH; | ||
|
||
function cryptoRandom() { | ||
// Divide a random UInt32 by the maximum value (2^32 -1) to get a result between 0 and 1 | ||
return window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295; | ||
} | ||
|
||
function randomCoords(rnd) { | ||
var num = Math.floor(rnd() * AREA); | ||
var xx = Math.floor(num / WIDTH); | ||
var yy = num % HEIGHT; | ||
return [xx, yy]; | ||
} | ||
|
||
function doRender(id, rnd) { | ||
var h1 = document.createElement('h1'); | ||
h1.innerHTML = id; | ||
document.body.appendChild(h1); | ||
var canvas = document.createElement('canvas'); | ||
document.body.appendChild(canvas); | ||
var ctx = canvas.getContext('2d'); | ||
canvas.setAttribute('height', HEIGHT); | ||
canvas.setAttribute('width', WIDTH); | ||
|
||
var xx, yy, ii; | ||
|
||
for (var ii = 0; ii < ITERS; ii++) { | ||
|
||
[xx, yy] = randomCoords(rnd); | ||
ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; | ||
ctx.fillRect(xx, yy, 1, 1); | ||
} | ||
} | ||
|
||
doRender('mathRandom', Math.random); | ||
doRender('cryptoRandom', cryptoRandom); | ||
</script> | ||
</body> | ||
</html> |
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,18 @@ | ||
{ | ||
"name": "uuid-random-benchmark", | ||
"version": "1.0.0", | ||
"description": "Benchmarking various uuid libraries", | ||
"main": "index.js", | ||
"author": "Wes Roberts", | ||
"license": "MIT", | ||
"dependencies": { | ||
"benchmark": "^2.1.4", | ||
"fast-stats": "^0.0.5", | ||
"id128": "^1.5.0", | ||
"microtime": "^3.0.0", | ||
"nanoid": "^3.1.10", | ||
"platform.js": "^1.0.0", | ||
"portable-uuid": "^0.3.0", | ||
"uuid": "^8.1.0" | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.