uuid 2.0.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +47 -0
- package/AUTHORS +5 -0
- package/CHANGELOG.md +47 -0
- package/LICENSE.md +21 -2
- package/README.md +195 -107
- package/README_js.md +280 -0
- package/bin/uuid +65 -0
- package/index.js +8 -0
- package/lib/bytesToUuid.js +23 -0
- package/lib/md5-browser.js +216 -0
- package/lib/md5.js +25 -0
- package/lib/rng-browser.js +31 -0
- package/lib/rng.js +8 -0
- package/lib/sha1-browser.js +89 -0
- package/lib/sha1.js +25 -0
- package/lib/v35.js +53 -0
- package/package.json +18 -28
- package/v1.js +109 -0
- package/v3.js +4 -0
- package/v4.js +29 -0
- package/v5.js +3 -0
- package/.npmignore +0 -2
- package/.travis.yml +0 -5
- package/benchmark/README.md +0 -53
- package/benchmark/bench.gnu +0 -174
- package/benchmark/bench.sh +0 -34
- package/benchmark/benchmark-native.c +0 -34
- package/benchmark/benchmark.js +0 -84
- package/benchmark/package.json +0 -9
- package/misc/compare.js +0 -62
- package/misc/perf.js +0 -102
- package/rng-browser.js +0 -32
- package/rng.js +0 -4
- package/test/mocha.opts +0 -1
- package/test/test.js +0 -105
- package/uuid.js +0 -183
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Adapted from Chris Veness' SHA1 code at
|
|
2
|
+
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
function f(s, x, y, z) {
|
|
6
|
+
switch (s) {
|
|
7
|
+
case 0: return (x & y) ^ (~x & z);
|
|
8
|
+
case 1: return x ^ y ^ z;
|
|
9
|
+
case 2: return (x & y) ^ (x & z) ^ (y & z);
|
|
10
|
+
case 3: return x ^ y ^ z;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ROTL(x, n) {
|
|
15
|
+
return (x << n) | (x>>> (32 - n));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function sha1(bytes) {
|
|
19
|
+
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
20
|
+
var H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
21
|
+
|
|
22
|
+
if (typeof(bytes) == 'string') {
|
|
23
|
+
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
|
|
24
|
+
bytes = new Array(msg.length);
|
|
25
|
+
for (var i = 0; i < msg.length; i++) bytes[i] = msg.charCodeAt(i);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bytes.push(0x80);
|
|
29
|
+
|
|
30
|
+
var l = bytes.length/4 + 2;
|
|
31
|
+
var N = Math.ceil(l/16);
|
|
32
|
+
var M = new Array(N);
|
|
33
|
+
|
|
34
|
+
for (var i=0; i<N; i++) {
|
|
35
|
+
M[i] = new Array(16);
|
|
36
|
+
for (var j=0; j<16; j++) {
|
|
37
|
+
M[i][j] =
|
|
38
|
+
bytes[i * 64 + j * 4] << 24 |
|
|
39
|
+
bytes[i * 64 + j * 4 + 1] << 16 |
|
|
40
|
+
bytes[i * 64 + j * 4 + 2] << 8 |
|
|
41
|
+
bytes[i * 64 + j * 4 + 3];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
M[N - 1][14] = ((bytes.length - 1) * 8) /
|
|
46
|
+
Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
47
|
+
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;
|
|
48
|
+
|
|
49
|
+
for (var i=0; i<N; i++) {
|
|
50
|
+
var W = new Array(80);
|
|
51
|
+
|
|
52
|
+
for (var t=0; t<16; t++) W[t] = M[i][t];
|
|
53
|
+
for (var t=16; t<80; t++) {
|
|
54
|
+
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var a = H[0];
|
|
58
|
+
var b = H[1];
|
|
59
|
+
var c = H[2];
|
|
60
|
+
var d = H[3];
|
|
61
|
+
var e = H[4];
|
|
62
|
+
|
|
63
|
+
for (var t=0; t<80; t++) {
|
|
64
|
+
var s = Math.floor(t/20);
|
|
65
|
+
var T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0;
|
|
66
|
+
e = d;
|
|
67
|
+
d = c;
|
|
68
|
+
c = ROTL(b, 30) >>> 0;
|
|
69
|
+
b = a;
|
|
70
|
+
a = T;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
H[0] = (H[0] + a) >>> 0;
|
|
74
|
+
H[1] = (H[1] + b) >>> 0;
|
|
75
|
+
H[2] = (H[2] + c) >>> 0;
|
|
76
|
+
H[3] = (H[3] + d) >>> 0;
|
|
77
|
+
H[4] = (H[4] + e) >>> 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return [
|
|
81
|
+
H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff,
|
|
82
|
+
H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff,
|
|
83
|
+
H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff,
|
|
84
|
+
H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff,
|
|
85
|
+
H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = sha1;
|
package/lib/sha1.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
|
|
5
|
+
function sha1(bytes) {
|
|
6
|
+
if (typeof Buffer.from === 'function') {
|
|
7
|
+
// Modern Buffer API
|
|
8
|
+
if (Array.isArray(bytes)) {
|
|
9
|
+
bytes = Buffer.from(bytes);
|
|
10
|
+
} else if (typeof bytes === 'string') {
|
|
11
|
+
bytes = Buffer.from(bytes, 'utf8');
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
// Pre-v4 Buffer API
|
|
15
|
+
if (Array.isArray(bytes)) {
|
|
16
|
+
bytes = new Buffer(bytes);
|
|
17
|
+
} else if (typeof bytes === 'string') {
|
|
18
|
+
bytes = new Buffer(bytes, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return crypto.createHash('sha1').update(bytes).digest();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = sha1;
|
package/lib/v35.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var bytesToUuid = require('./bytesToUuid');
|
|
2
|
+
|
|
3
|
+
function uuidToBytes(uuid) {
|
|
4
|
+
// Note: We assume we're being passed a valid uuid string
|
|
5
|
+
var bytes = [];
|
|
6
|
+
uuid.replace(/[a-fA-F0-9]{2}/g, function(hex) {
|
|
7
|
+
bytes.push(parseInt(hex, 16));
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function stringToBytes(str) {
|
|
14
|
+
str = unescape(encodeURIComponent(str)); // UTF8 escape
|
|
15
|
+
var bytes = new Array(str.length);
|
|
16
|
+
for (var i = 0; i < str.length; i++) {
|
|
17
|
+
bytes[i] = str.charCodeAt(i);
|
|
18
|
+
}
|
|
19
|
+
return bytes;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = function(name, version, hashfunc) {
|
|
23
|
+
var generateUUID = function(value, namespace, buf, offset) {
|
|
24
|
+
var off = buf && offset || 0;
|
|
25
|
+
|
|
26
|
+
if (typeof(value) == 'string') value = stringToBytes(value);
|
|
27
|
+
if (typeof(namespace) == 'string') namespace = uuidToBytes(namespace);
|
|
28
|
+
|
|
29
|
+
if (!Array.isArray(value)) throw TypeError('value must be an array of bytes');
|
|
30
|
+
if (!Array.isArray(namespace) || namespace.length !== 16) throw TypeError('namespace must be uuid string or an Array of 16 byte values');
|
|
31
|
+
|
|
32
|
+
// Per 4.3
|
|
33
|
+
var bytes = hashfunc(namespace.concat(value));
|
|
34
|
+
bytes[6] = (bytes[6] & 0x0f) | version;
|
|
35
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
36
|
+
|
|
37
|
+
if (buf) {
|
|
38
|
+
for (var idx = 0; idx < 16; ++idx) {
|
|
39
|
+
buf[off+idx] = bytes[idx];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return buf || bytesToUuid(bytes);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
generateUUID.name = name;
|
|
47
|
+
|
|
48
|
+
// Pre-defined namespaces, per Appendix C
|
|
49
|
+
generateUUID.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
50
|
+
generateUUID.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
51
|
+
|
|
52
|
+
return generateUUID;
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,46 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uuid",
|
|
3
|
-
"version": "2.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "RFC4122 (v1, v4, and v5) UUIDs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"uuid",
|
|
7
7
|
"guid",
|
|
8
8
|
"rfc4122"
|
|
9
9
|
],
|
|
10
|
-
"author": "Robert Kieffer <robert@broofa.com>",
|
|
11
|
-
"contributors": [
|
|
12
|
-
{
|
|
13
|
-
"name": "Christoph Tavan <dev@tavan.de>",
|
|
14
|
-
"github": "https://github.com/ctavan"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"name": "Vincent Voyer <vincent@zeroload.net>",
|
|
18
|
-
"github": "https://github.com/vvo"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
10
|
"license": "MIT",
|
|
22
|
-
"
|
|
11
|
+
"bin": {
|
|
12
|
+
"uuid": "./bin/uuid"
|
|
13
|
+
},
|
|
23
14
|
"devDependencies": {
|
|
24
|
-
"
|
|
15
|
+
"eslint": "4.5.0",
|
|
16
|
+
"mocha": "3.1.2",
|
|
17
|
+
"runmd": "1.0.1",
|
|
18
|
+
"standard-version": "4.2.0"
|
|
25
19
|
},
|
|
26
20
|
"scripts": {
|
|
27
|
-
"test": "mocha test/test.js"
|
|
21
|
+
"test": "mocha test/test.js",
|
|
22
|
+
"md": "runmd --watch --output=README.md README_js.md",
|
|
23
|
+
"release": "standard-version",
|
|
24
|
+
"prepare": "runmd --output=README.md README_js.md"
|
|
28
25
|
},
|
|
29
26
|
"browser": {
|
|
30
|
-
"./rng.js": "./rng-browser.js"
|
|
27
|
+
"./lib/rng.js": "./lib/rng-browser.js",
|
|
28
|
+
"./lib/sha1.js": "./lib/sha1-browser.js",
|
|
29
|
+
"./lib/md5.js": "./lib/md5-browser.js"
|
|
31
30
|
},
|
|
32
31
|
"repository": {
|
|
33
32
|
"type": "git",
|
|
34
|
-
"url": "https://github.com/
|
|
33
|
+
"url": "https://github.com/kelektiv/node-uuid.git"
|
|
35
34
|
},
|
|
36
|
-
"
|
|
37
|
-
"browsers": [
|
|
38
|
-
"ie6..latest",
|
|
39
|
-
"firefox/3.6..latest",
|
|
40
|
-
"chrome/22..latest",
|
|
41
|
-
"safari/5.1..latest"
|
|
42
|
-
],
|
|
43
|
-
"harness": "mocha-tdd",
|
|
44
|
-
"files": "test/*.js"
|
|
45
|
-
}
|
|
35
|
+
"dependencies": {}
|
|
46
36
|
}
|
package/v1.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var rng = require('./lib/rng');
|
|
2
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
3
|
+
|
|
4
|
+
// **`v1()` - Generate time-based UUID**
|
|
5
|
+
//
|
|
6
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
7
|
+
// and http://docs.python.org/library/uuid.html
|
|
8
|
+
|
|
9
|
+
var _nodeId;
|
|
10
|
+
var _clockseq;
|
|
11
|
+
|
|
12
|
+
// Previous uuid creation time
|
|
13
|
+
var _lastMSecs = 0;
|
|
14
|
+
var _lastNSecs = 0;
|
|
15
|
+
|
|
16
|
+
// See https://github.com/broofa/node-uuid for API details
|
|
17
|
+
function v1(options, buf, offset) {
|
|
18
|
+
var i = buf && offset || 0;
|
|
19
|
+
var b = buf || [];
|
|
20
|
+
|
|
21
|
+
options = options || {};
|
|
22
|
+
var node = options.node || _nodeId;
|
|
23
|
+
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
|
24
|
+
|
|
25
|
+
// node and clockseq need to be initialized to random values if they're not
|
|
26
|
+
// specified. We do this lazily to minimize issues related to insufficient
|
|
27
|
+
// system entropy. See #189
|
|
28
|
+
if (node == null || clockseq == null) {
|
|
29
|
+
var seedBytes = rng();
|
|
30
|
+
if (node == null) {
|
|
31
|
+
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
32
|
+
node = _nodeId = [
|
|
33
|
+
seedBytes[0] | 0x01,
|
|
34
|
+
seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
if (clockseq == null) {
|
|
38
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
39
|
+
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
44
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
45
|
+
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
46
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
47
|
+
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
|
48
|
+
|
|
49
|
+
// Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
50
|
+
// cycle to simulate higher resolution clock
|
|
51
|
+
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
|
52
|
+
|
|
53
|
+
// Time since last uuid creation (in msecs)
|
|
54
|
+
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
|
55
|
+
|
|
56
|
+
// Per 4.2.1.2, Bump clockseq on clock regression
|
|
57
|
+
if (dt < 0 && options.clockseq === undefined) {
|
|
58
|
+
clockseq = clockseq + 1 & 0x3fff;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
62
|
+
// time interval
|
|
63
|
+
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
|
64
|
+
nsecs = 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Per 4.2.1.2 Throw error if too many uuids are requested
|
|
68
|
+
if (nsecs >= 10000) {
|
|
69
|
+
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
_lastMSecs = msecs;
|
|
73
|
+
_lastNSecs = nsecs;
|
|
74
|
+
_clockseq = clockseq;
|
|
75
|
+
|
|
76
|
+
// Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
77
|
+
msecs += 12219292800000;
|
|
78
|
+
|
|
79
|
+
// `time_low`
|
|
80
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
81
|
+
b[i++] = tl >>> 24 & 0xff;
|
|
82
|
+
b[i++] = tl >>> 16 & 0xff;
|
|
83
|
+
b[i++] = tl >>> 8 & 0xff;
|
|
84
|
+
b[i++] = tl & 0xff;
|
|
85
|
+
|
|
86
|
+
// `time_mid`
|
|
87
|
+
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
|
88
|
+
b[i++] = tmh >>> 8 & 0xff;
|
|
89
|
+
b[i++] = tmh & 0xff;
|
|
90
|
+
|
|
91
|
+
// `time_high_and_version`
|
|
92
|
+
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
|
93
|
+
b[i++] = tmh >>> 16 & 0xff;
|
|
94
|
+
|
|
95
|
+
// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
96
|
+
b[i++] = clockseq >>> 8 | 0x80;
|
|
97
|
+
|
|
98
|
+
// `clock_seq_low`
|
|
99
|
+
b[i++] = clockseq & 0xff;
|
|
100
|
+
|
|
101
|
+
// `node`
|
|
102
|
+
for (var n = 0; n < 6; ++n) {
|
|
103
|
+
b[i + n] = node[n];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return buf ? buf : bytesToUuid(b);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = v1;
|
package/v3.js
ADDED
package/v4.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var rng = require('./lib/rng');
|
|
2
|
+
var bytesToUuid = require('./lib/bytesToUuid');
|
|
3
|
+
|
|
4
|
+
function v4(options, buf, offset) {
|
|
5
|
+
var i = buf && offset || 0;
|
|
6
|
+
|
|
7
|
+
if (typeof(options) == 'string') {
|
|
8
|
+
buf = options === 'binary' ? new Array(16) : null;
|
|
9
|
+
options = null;
|
|
10
|
+
}
|
|
11
|
+
options = options || {};
|
|
12
|
+
|
|
13
|
+
var rnds = options.random || (options.rng || rng)();
|
|
14
|
+
|
|
15
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
16
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
17
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
18
|
+
|
|
19
|
+
// Copy bytes to buffer, if provided
|
|
20
|
+
if (buf) {
|
|
21
|
+
for (var ii = 0; ii < 16; ++ii) {
|
|
22
|
+
buf[i + ii] = rnds[ii];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return buf || bytesToUuid(rnds);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = v4;
|
package/v5.js
ADDED
package/.npmignore
DELETED
package/.travis.yml
DELETED
package/benchmark/README.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# node-uuid Benchmarks
|
|
2
|
-
|
|
3
|
-
### Results
|
|
4
|
-
|
|
5
|
-
To see the results of our benchmarks visit https://github.com/broofa/node-uuid/wiki/Benchmark
|
|
6
|
-
|
|
7
|
-
### Run them yourself
|
|
8
|
-
|
|
9
|
-
node-uuid comes with some benchmarks to measure performance of generating UUIDs. These can be run using node.js. node-uuid is being benchmarked against some other uuid modules, that are available through npm namely `uuid` and `uuid-js`.
|
|
10
|
-
|
|
11
|
-
To prepare and run the benchmark issue;
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
npm install uuid uuid-js
|
|
15
|
-
node benchmark/benchmark.js
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
You'll see an output like this one:
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
# v4
|
|
22
|
-
nodeuuid.v4(): 854700 uuids/second
|
|
23
|
-
nodeuuid.v4('binary'): 788643 uuids/second
|
|
24
|
-
nodeuuid.v4('binary', buffer): 1336898 uuids/second
|
|
25
|
-
uuid(): 479386 uuids/second
|
|
26
|
-
uuid('binary'): 582072 uuids/second
|
|
27
|
-
uuidjs.create(4): 312304 uuids/second
|
|
28
|
-
|
|
29
|
-
# v1
|
|
30
|
-
nodeuuid.v1(): 938086 uuids/second
|
|
31
|
-
nodeuuid.v1('binary'): 683060 uuids/second
|
|
32
|
-
nodeuuid.v1('binary', buffer): 1644736 uuids/second
|
|
33
|
-
uuidjs.create(1): 190621 uuids/second
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
* The `uuid()` entries are for Nikhil Marathe's [uuid module](https://bitbucket.org/nikhilm/uuidjs) which is a wrapper around the native libuuid library.
|
|
37
|
-
* The `uuidjs()` entries are for Patrick Negri's [uuid-js module](https://github.com/pnegri/uuid-js) which is a pure javascript implementation based on [UUID.js](https://github.com/LiosK/UUID.js) by LiosK.
|
|
38
|
-
|
|
39
|
-
If you want to get more reliable results you can run the benchmark multiple times and write the output into a log file:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
for i in {0..9}; do node benchmark/benchmark.js >> benchmark/bench_0.4.12.log; done;
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
If you're interested in how performance varies between different node versions, you can issue the above command multiple times.
|
|
46
|
-
|
|
47
|
-
You can then use the shell script `bench.sh` provided in this directory to calculate the averages over all benchmark runs and draw a nice plot:
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
(cd benchmark/ && ./bench.sh)
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
This assumes you have [gnuplot](http://www.gnuplot.info/) and [ImageMagick](http://www.imagemagick.org/) installed. You'll find a nice `bench.png` graph in the `benchmark/` directory then.
|
package/benchmark/bench.gnu
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
#!/opt/local/bin/gnuplot -persist
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
# G N U P L O T
|
|
5
|
-
# Version 4.4 patchlevel 3
|
|
6
|
-
# last modified March 2011
|
|
7
|
-
# System: Darwin 10.8.0
|
|
8
|
-
#
|
|
9
|
-
# Copyright (C) 1986-1993, 1998, 2004, 2007-2010
|
|
10
|
-
# Thomas Williams, Colin Kelley and many others
|
|
11
|
-
#
|
|
12
|
-
# gnuplot home: http://www.gnuplot.info
|
|
13
|
-
# faq, bugs, etc: type "help seeking-assistance"
|
|
14
|
-
# immediate help: type "help"
|
|
15
|
-
# plot window: hit 'h'
|
|
16
|
-
set terminal postscript eps noenhanced defaultplex \
|
|
17
|
-
leveldefault color colortext \
|
|
18
|
-
solid linewidth 1.2 butt noclip \
|
|
19
|
-
palfuncparam 2000,0.003 \
|
|
20
|
-
"Helvetica" 14
|
|
21
|
-
set output 'bench.eps'
|
|
22
|
-
unset clip points
|
|
23
|
-
set clip one
|
|
24
|
-
unset clip two
|
|
25
|
-
set bar 1.000000 front
|
|
26
|
-
set border 31 front linetype -1 linewidth 1.000
|
|
27
|
-
set xdata
|
|
28
|
-
set ydata
|
|
29
|
-
set zdata
|
|
30
|
-
set x2data
|
|
31
|
-
set y2data
|
|
32
|
-
set timefmt x "%d/%m/%y,%H:%M"
|
|
33
|
-
set timefmt y "%d/%m/%y,%H:%M"
|
|
34
|
-
set timefmt z "%d/%m/%y,%H:%M"
|
|
35
|
-
set timefmt x2 "%d/%m/%y,%H:%M"
|
|
36
|
-
set timefmt y2 "%d/%m/%y,%H:%M"
|
|
37
|
-
set timefmt cb "%d/%m/%y,%H:%M"
|
|
38
|
-
set boxwidth
|
|
39
|
-
set style fill empty border
|
|
40
|
-
set style rectangle back fc lt -3 fillstyle solid 1.00 border lt -1
|
|
41
|
-
set style circle radius graph 0.02, first 0, 0
|
|
42
|
-
set dummy x,y
|
|
43
|
-
set format x "% g"
|
|
44
|
-
set format y "% g"
|
|
45
|
-
set format x2 "% g"
|
|
46
|
-
set format y2 "% g"
|
|
47
|
-
set format z "% g"
|
|
48
|
-
set format cb "% g"
|
|
49
|
-
set angles radians
|
|
50
|
-
unset grid
|
|
51
|
-
set key title ""
|
|
52
|
-
set key outside left top horizontal Right noreverse enhanced autotitles columnhead nobox
|
|
53
|
-
set key noinvert samplen 4 spacing 1 width 0 height 0
|
|
54
|
-
set key maxcolumns 2 maxrows 0
|
|
55
|
-
unset label
|
|
56
|
-
unset arrow
|
|
57
|
-
set style increment default
|
|
58
|
-
unset style line
|
|
59
|
-
set style line 1 linetype 1 linewidth 2.000 pointtype 1 pointsize default pointinterval 0
|
|
60
|
-
unset style arrow
|
|
61
|
-
set style histogram clustered gap 2 title offset character 0, 0, 0
|
|
62
|
-
unset logscale
|
|
63
|
-
set offsets graph 0.05, 0.15, 0, 0
|
|
64
|
-
set pointsize 1.5
|
|
65
|
-
set pointintervalbox 1
|
|
66
|
-
set encoding default
|
|
67
|
-
unset polar
|
|
68
|
-
unset parametric
|
|
69
|
-
unset decimalsign
|
|
70
|
-
set view 60, 30, 1, 1
|
|
71
|
-
set samples 100, 100
|
|
72
|
-
set isosamples 10, 10
|
|
73
|
-
set surface
|
|
74
|
-
unset contour
|
|
75
|
-
set clabel '%8.3g'
|
|
76
|
-
set mapping cartesian
|
|
77
|
-
set datafile separator whitespace
|
|
78
|
-
unset hidden3d
|
|
79
|
-
set cntrparam order 4
|
|
80
|
-
set cntrparam linear
|
|
81
|
-
set cntrparam levels auto 5
|
|
82
|
-
set cntrparam points 5
|
|
83
|
-
set size ratio 0 1,1
|
|
84
|
-
set origin 0,0
|
|
85
|
-
set style data points
|
|
86
|
-
set style function lines
|
|
87
|
-
set xzeroaxis linetype -2 linewidth 1.000
|
|
88
|
-
set yzeroaxis linetype -2 linewidth 1.000
|
|
89
|
-
set zzeroaxis linetype -2 linewidth 1.000
|
|
90
|
-
set x2zeroaxis linetype -2 linewidth 1.000
|
|
91
|
-
set y2zeroaxis linetype -2 linewidth 1.000
|
|
92
|
-
set ticslevel 0.5
|
|
93
|
-
set mxtics default
|
|
94
|
-
set mytics default
|
|
95
|
-
set mztics default
|
|
96
|
-
set mx2tics default
|
|
97
|
-
set my2tics default
|
|
98
|
-
set mcbtics default
|
|
99
|
-
set xtics border in scale 1,0.5 mirror norotate offset character 0, 0, 0
|
|
100
|
-
set xtics norangelimit
|
|
101
|
-
set xtics ()
|
|
102
|
-
set ytics border in scale 1,0.5 mirror norotate offset character 0, 0, 0
|
|
103
|
-
set ytics autofreq norangelimit
|
|
104
|
-
set ztics border in scale 1,0.5 nomirror norotate offset character 0, 0, 0
|
|
105
|
-
set ztics autofreq norangelimit
|
|
106
|
-
set nox2tics
|
|
107
|
-
set noy2tics
|
|
108
|
-
set cbtics border in scale 1,0.5 mirror norotate offset character 0, 0, 0
|
|
109
|
-
set cbtics autofreq norangelimit
|
|
110
|
-
set title ""
|
|
111
|
-
set title offset character 0, 0, 0 font "" norotate
|
|
112
|
-
set timestamp bottom
|
|
113
|
-
set timestamp ""
|
|
114
|
-
set timestamp offset character 0, 0, 0 font "" norotate
|
|
115
|
-
set rrange [ * : * ] noreverse nowriteback # (currently [8.98847e+307:-8.98847e+307] )
|
|
116
|
-
set autoscale rfixmin
|
|
117
|
-
set autoscale rfixmax
|
|
118
|
-
set trange [ * : * ] noreverse nowriteback # (currently [-5.00000:5.00000] )
|
|
119
|
-
set autoscale tfixmin
|
|
120
|
-
set autoscale tfixmax
|
|
121
|
-
set urange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] )
|
|
122
|
-
set autoscale ufixmin
|
|
123
|
-
set autoscale ufixmax
|
|
124
|
-
set vrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] )
|
|
125
|
-
set autoscale vfixmin
|
|
126
|
-
set autoscale vfixmax
|
|
127
|
-
set xlabel ""
|
|
128
|
-
set xlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate
|
|
129
|
-
set x2label ""
|
|
130
|
-
set x2label offset character 0, 0, 0 font "" textcolor lt -1 norotate
|
|
131
|
-
set xrange [ * : * ] noreverse nowriteback # (currently [-0.150000:3.15000] )
|
|
132
|
-
set autoscale xfixmin
|
|
133
|
-
set autoscale xfixmax
|
|
134
|
-
set x2range [ * : * ] noreverse nowriteback # (currently [0.00000:3.00000] )
|
|
135
|
-
set autoscale x2fixmin
|
|
136
|
-
set autoscale x2fixmax
|
|
137
|
-
set ylabel ""
|
|
138
|
-
set ylabel offset character 0, 0, 0 font "" textcolor lt -1 rotate by -270
|
|
139
|
-
set y2label ""
|
|
140
|
-
set y2label offset character 0, 0, 0 font "" textcolor lt -1 rotate by -270
|
|
141
|
-
set yrange [ 0.00000 : 1.90000e+06 ] noreverse nowriteback # (currently [:] )
|
|
142
|
-
set autoscale yfixmin
|
|
143
|
-
set autoscale yfixmax
|
|
144
|
-
set y2range [ * : * ] noreverse nowriteback # (currently [0.00000:1.90000e+06] )
|
|
145
|
-
set autoscale y2fixmin
|
|
146
|
-
set autoscale y2fixmax
|
|
147
|
-
set zlabel ""
|
|
148
|
-
set zlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate
|
|
149
|
-
set zrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] )
|
|
150
|
-
set autoscale zfixmin
|
|
151
|
-
set autoscale zfixmax
|
|
152
|
-
set cblabel ""
|
|
153
|
-
set cblabel offset character 0, 0, 0 font "" textcolor lt -1 rotate by -270
|
|
154
|
-
set cbrange [ * : * ] noreverse nowriteback # (currently [8.98847e+307:-8.98847e+307] )
|
|
155
|
-
set autoscale cbfixmin
|
|
156
|
-
set autoscale cbfixmax
|
|
157
|
-
set zero 1e-08
|
|
158
|
-
set lmargin -1
|
|
159
|
-
set bmargin -1
|
|
160
|
-
set rmargin -1
|
|
161
|
-
set tmargin -1
|
|
162
|
-
set pm3d explicit at s
|
|
163
|
-
set pm3d scansautomatic
|
|
164
|
-
set pm3d interpolate 1,1 flush begin noftriangles nohidden3d corners2color mean
|
|
165
|
-
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB
|
|
166
|
-
set palette rgbformulae 7, 5, 15
|
|
167
|
-
set colorbox default
|
|
168
|
-
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
|
|
169
|
-
set loadpath
|
|
170
|
-
set fontpath
|
|
171
|
-
set fit noerrorvariables
|
|
172
|
-
GNUTERM = "aqua"
|
|
173
|
-
plot 'bench_results.txt' using 2:xticlabel(1) w lp lw 2, '' using 3:xticlabel(1) w lp lw 2, '' using 4:xticlabel(1) w lp lw 2, '' using 5:xticlabel(1) w lp lw 2, '' using 6:xticlabel(1) w lp lw 2, '' using 7:xticlabel(1) w lp lw 2, '' using 8:xticlabel(1) w lp lw 2, '' using 9:xticlabel(1) w lp lw 2
|
|
174
|
-
# EOF
|
package/benchmark/bench.sh
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# for a given node version run:
|
|
4
|
-
# for i in {0..9}; do node benchmark.js >> bench_0.6.2.log; done;
|
|
5
|
-
|
|
6
|
-
PATTERNS=('nodeuuid.v1()' "nodeuuid.v1('binary'," 'nodeuuid.v4()' "nodeuuid.v4('binary'," "uuid()" "uuid('binary')" 'uuidjs.create(1)' 'uuidjs.create(4)' '140byte')
|
|
7
|
-
FILES=(node_uuid_v1_string node_uuid_v1_buf node_uuid_v4_string node_uuid_v4_buf libuuid_v4_string libuuid_v4_binary uuidjs_v1_string uuidjs_v4_string 140byte_es)
|
|
8
|
-
INDICES=(2 3 2 3 2 2 2 2 2)
|
|
9
|
-
VERSIONS=$( ls bench_*.log | sed -e 's/^bench_\([0-9\.]*\)\.log/\1/' | tr "\\n" " " )
|
|
10
|
-
TMPJOIN="tmp_join"
|
|
11
|
-
OUTPUT="bench_results.txt"
|
|
12
|
-
|
|
13
|
-
for I in ${!FILES[*]}; do
|
|
14
|
-
F=${FILES[$I]}
|
|
15
|
-
P=${PATTERNS[$I]}
|
|
16
|
-
INDEX=${INDICES[$I]}
|
|
17
|
-
echo "version $F" > $F
|
|
18
|
-
for V in $VERSIONS; do
|
|
19
|
-
(VAL=$( grep "$P" bench_$V.log | LC_ALL=en_US awk '{ sum += $'$INDEX' } END { print sum/NR }' ); echo $V $VAL) >> $F
|
|
20
|
-
done
|
|
21
|
-
if [ $I == 0 ]; then
|
|
22
|
-
cat $F > $TMPJOIN
|
|
23
|
-
else
|
|
24
|
-
join $TMPJOIN $F > $OUTPUT
|
|
25
|
-
cp $OUTPUT $TMPJOIN
|
|
26
|
-
fi
|
|
27
|
-
rm $F
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
rm $TMPJOIN
|
|
31
|
-
|
|
32
|
-
gnuplot bench.gnu
|
|
33
|
-
convert -density 200 -resize 800x560 -flatten bench.eps bench.png
|
|
34
|
-
rm bench.eps
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Test performance of native C UUID generation
|
|
3
|
-
|
|
4
|
-
To Compile: cc -luuid benchmark-native.c -o benchmark-native
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
#include <stdio.h>
|
|
8
|
-
#include <unistd.h>
|
|
9
|
-
#include <sys/time.h>
|
|
10
|
-
#include <uuid/uuid.h>
|
|
11
|
-
|
|
12
|
-
int main() {
|
|
13
|
-
uuid_t myid;
|
|
14
|
-
char buf[36+1];
|
|
15
|
-
int i;
|
|
16
|
-
struct timeval t;
|
|
17
|
-
double start, finish;
|
|
18
|
-
|
|
19
|
-
gettimeofday(&t, NULL);
|
|
20
|
-
start = t.tv_sec + t.tv_usec/1e6;
|
|
21
|
-
|
|
22
|
-
int n = 2e5;
|
|
23
|
-
for (i = 0; i < n; i++) {
|
|
24
|
-
uuid_generate(myid);
|
|
25
|
-
uuid_unparse(myid, buf);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
gettimeofday(&t, NULL);
|
|
29
|
-
finish = t.tv_sec + t.tv_usec/1e6;
|
|
30
|
-
double dur = finish - start;
|
|
31
|
-
|
|
32
|
-
printf("%d uuids/sec", (int)(n/dur));
|
|
33
|
-
return 0;
|
|
34
|
-
}
|