Skip to content

Commit 06a19ad

Browse files
committed
add benchmarks
1 parent 4c722d3 commit 06a19ad

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

benchmarks/base64.bench.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as exodus from '@exodus/bytes/base'
22
import { base64 as scureBase64 } from '@scure/base'
33
import base64js from 'base64-js'
4+
import buffer from 'buffer/index.js'
45

56
import { bufs } from './random.js'
67

@@ -23,4 +24,8 @@ for (let i = 0; i < 5; i++) {
2324
console.time('Buffer.from')
2425
for (const buf of bufs) Buffer.from(buf).toString('base64')
2526
console.timeEnd('Buffer.from')
27+
28+
console.time('buffer/Buffer.from')
29+
for (const buf of bufs) buffer.Buffer.from(buf).toString('base64')
30+
console.timeEnd('buffer/Buffer.from')
2631
}

benchmarks/base64from.bench.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as exodus from '@exodus/bytes/base'
2+
import { base64 as scureBase64 } from '@scure/base'
3+
import base64js from 'base64-js'
4+
import buffer from 'buffer/index.js'
5+
6+
import { bufs } from './random.js'
7+
8+
const strings = bufs.map(x => exodus.toBase64(x))
9+
10+
if (Buffer.compare(exodus.fromBase64(strings[0]), bufs[0]) !== 0) throw new Error('exodus')
11+
if (Buffer.compare(scureBase64.decode(strings[0]), bufs[0]) !== 0) throw new Error('scure.base64')
12+
13+
for (let i = 0; i < 5; i++) {
14+
console.time('base64-js')
15+
for (const str of strings) base64js.toByteArray(str)
16+
console.timeEnd('base64-js')
17+
18+
console.time('@exodus/bytes/base')
19+
for (const str of strings) exodus.fromBase64(str)
20+
console.timeEnd('@exodus/bytes/base')
21+
22+
console.time('@scure/base')
23+
for (const str of strings) scureBase64.decode(str)
24+
console.timeEnd('@scure/base')
25+
26+
console.time('Buffer.from')
27+
for (const str of strings) Buffer.from(str, 'base64')
28+
console.timeEnd('Buffer.from')
29+
30+
console.time('buffer/Buffer.from')
31+
for (const str of strings) buffer.Buffer.from(str, 'base64')
32+
console.timeEnd('buffer/Buffer.from')
33+
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@
4949
"dependencies": {},
5050
"devDependencies": {
5151
"@exodus/test": "^1.0.0-rc.100",
52+
"@scure/base": "^1.2.6",
5253
"@types/node": "^24.0.10",
54+
"base-x": "^5.0.1",
55+
"base32.js": "^0.1.0",
56+
"base64-js": "^1.5.1",
57+
"buffer": "^6.0.3",
5358
"electron": "36.5.0",
5459
"jsvu": "^3.0.0"
5560
},

pnpm-lock.yaml

Lines changed: 33 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)