-
-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize uuid.v1 by 1.3x uuid.v4 by 4.3x (430%)
- Loading branch information
Showing
6 changed files
with
46 additions
and
35 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 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
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 |
---|---|---|
@@ -1,40 +1,48 @@ | ||
import assert from 'assert'; | ||
import stringify from '../../src/stringify.js'; | ||
import { unsafeStringify, stringify } from '../../src/unsafeStringify.js'; | ||
|
||
const BYTES = [ | ||
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b, | ||
]; | ||
|
||
describe('stringify', () => { | ||
test('Stringify Array', () => { | ||
assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
describe('unsafeStringify', () => { | ||
describe('default', () => { | ||
test('Stringify Array', () => { | ||
assert.equal(unsafeStringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
|
||
test('Stringify TypedArray', () => { | ||
assert.equal(stringify(Uint8Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
assert.equal(stringify(Int32Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
test('Stringify TypedArray', () => { | ||
assert.equal(unsafeStringify(Uint8Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
assert.equal(unsafeStringify(Int32Array.from(BYTES)), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
|
||
test('Stringify w/ offset', () => { | ||
assert.equal(stringify([0, 0, 0, ...BYTES], 3), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
test('Stringify w/ offset', () => { | ||
assert.equal(unsafeStringify([0, 0, 0, ...BYTES], 3), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
}); | ||
|
||
test('Throws on not enough values', () => { | ||
const bytes = [...BYTES]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
describe('safe', () => { | ||
test('Stringify Array', () => { | ||
assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b'); | ||
}); | ||
|
||
test('Throws on undefined value', () => { | ||
const bytes = [...BYTES]; | ||
delete bytes[3]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
test('Throws on not enough values', () => { | ||
const bytes = [...BYTES]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
|
||
test('Throws on undefined value', () => { | ||
const bytes = [...BYTES]; | ||
delete bytes[3]; | ||
bytes.length = 15; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
|
||
test('Throws on invalid value', () => { | ||
const bytes = [...BYTES]; | ||
bytes[3] = 256; | ||
assert.throws(() => stringify(bytes)); | ||
test('Throws on invalid value', () => { | ||
const bytes = [...BYTES]; | ||
bytes[3] = 256; | ||
assert.throws(() => stringify(bytes)); | ||
}); | ||
}); | ||
}); |