Editing node-uuid performance This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) For more information, see https://github.com/broofa/node-uuid Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script> /* * Generate a RFC4122(v4) UUID * * Documentation at https://github.com/broofa/node-uuid */ // Use node.js Buffer class if available, otherwise use the Array class var BufferClass = typeof(Buffer) == 'function' ? Buffer : Array; // Buffer used for generating string uuids var _buf = new BufferClass(16); // Cache number <-> hex string for octet values var toString = []; var toNumber = {}; for (var i = 0; i < 256; i++) { toString[i] = (i + 0x100).toString(16).substr(1).toUpperCase(); toNumber[toString[i]] = i; } function parse(s) { var buf = new BufferClass(16); var i = 0, ton = toNumber; s.toUpperCase().replace(/[0-9A-F][0-9A-F]/g, function(octet) { buf[i++] = toNumber[octet]; }); return buf; } function unparse(buf) { var tos = toString, b = buf; return tos[b[0]] + tos[b[1]] + tos[b[2]] + tos[b[3]] + '-' + tos[b[4]] + tos[b[5]] + '-' + tos[b[6]] + tos[b[7]] + '-' + tos[b[8]] + tos[b[9]] + '-' + tos[b[10]] + tos[b[11]] + tos[b[12]] + tos[b[13]] + tos[b[14]] + tos[b[15]]; } function uuid(fmt, buf, offset) { var b32 = 0x100000000, ff = 0xff; var b = fmt != 'binary' ? _buf : (buf ? buf : new BufferClass(16)); var i = buf && offset || 0; r = Math.random() * b32; b[i++] = r & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; r = Math.random() * b32; b[i++] = r & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & 0x0f | 0x40; // See RFC4122 sect. 4.1.3 b[i++] = (r = r >>> 8) & ff; r = Math.random() * b32; b[i++] = r & 0x3f | 0x80; // See RFC4122 sect. 4.4 b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; r = Math.random() * b32; b[i++] = r & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; b[i++] = (r = r >>> 8) & ff; return fmt === undefined ? unparse(b) : b; }; uuid.parse = parse; uuid.unparse = unparse; uuid.BufferClass = BufferClass; var buf = new uuid.BufferClass(16); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code uuid(); Test 2 Title Async (check if this is an asynchronous test) Code uuid('binary'); Test 3 Title Async (check if this is an asynchronous test) Code uuid('binary', buf);