-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint no-undef: "off" */ | ||
|
||
import {Buffer} from 'node:buffer'; | ||
import {randomBytes} from 'node:crypto'; | ||
import benchmark from 'benchmark'; | ||
import { | ||
base64ToString, | ||
concatUint8Arrays, | ||
hexToUint8Array, | ||
isUint8Array, | ||
stringToBase64, | ||
stringToUint8Array, | ||
uint8ArrayToBase64, | ||
uint8ArrayToHex, | ||
uint8ArrayToString, | ||
} from './index.js'; | ||
|
||
const oneMb = 1024 * 1024; | ||
const largeUint8Array = new Uint8Array(randomBytes(oneMb).buffer); | ||
const textFromUint8Array = uint8ArrayToString(largeUint8Array); | ||
const base64FromUint8Array = Buffer.from(textFromUint8Array).toString('base64'); | ||
const hexFromUint8Array = uint8ArrayToHex(largeUint8Array); | ||
|
||
const suite = new benchmark.Suite(); | ||
|
||
suite.add('isUint8Array', () => isUint8Array(largeUint8Array)); | ||
|
||
suite.add('concatUint8Arrays with 2 arrays', () => concatUint8Arrays([largeUint8Array, largeUint8Array])); | ||
|
||
suite.add('concatUint8Arrays with 3 arrays', () => concatUint8Arrays([largeUint8Array, largeUint8Array])); | ||
|
||
suite.add('concatUint8Arrays with 4 arrays', () => concatUint8Arrays([largeUint8Array, largeUint8Array, largeUint8Array, largeUint8Array])); | ||
|
||
suite.add('uint8ArrayToString', () => uint8ArrayToString(largeUint8Array)); | ||
|
||
suite.add('stringToUint8Array', () => stringToUint8Array(textFromUint8Array)); | ||
|
||
suite.add('uint8ArrayToBase64', () => uint8ArrayToBase64(largeUint8Array)); | ||
|
||
suite.add('stringToBase64', () => stringToBase64(textFromUint8Array)); | ||
|
||
suite.add('base64ToString', () => base64ToString(base64FromUint8Array)); | ||
|
||
suite.add('uint8ArrayToHex', () => uint8ArrayToHex(largeUint8Array)); | ||
|
||
suite.add('hexToUint8Array', () => hexToUint8Array(hexFromUint8Array)); | ||
|
||
suite.on('cycle', event => console.log(event.target.toString())); | ||
suite.run({async: false}); |
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