Skip to content

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Nov 8, 2023

Before:

isUint8Array x 30,520,055 ops/sec ±1.32% (93 runs sampled)
uint8ArrayToString x 102 ops/sec ±0.41% (76 runs sampled)
stringToUint8Array x 165 ops/sec ±0.16% (85 runs sampled)
uint8ArrayToBase64: 
stringToBase64: 

The values are empty because it only throws errors.

Now:

isUint8Array x 160,822,491 ops/sec ±1.10% (100 runs sampled)
uint8ArrayToString x 103 ops/sec ±0.19% (76 runs sampled)
stringToUint8Array x 164 ops/sec ±0.21% (84 runs sampled)
uint8ArrayToBase64 x 16.44 ops/sec ±6.55% (37 runs sampled)
stringToBase64 x 8.37 ops/sec ±5.35% (25 runs sampled)

Full Execution:

isUint8Array x 160,822,491 ops/sec ±1.10% (100 runs sampled)
concatUint8Arrays with 2 arrays x 3,125 ops/sec ±7.13% (71 runs sampled)
concatUint8Arrays with 3 arrays x 3,699 ops/sec ±3.41% (82 runs sampled)
concatUint8Arrays with 4 arrays x 1,974 ops/sec ±2.87% (84 runs sampled)
uint8ArrayToString x 103 ops/sec ±0.19% (76 runs sampled)
stringToUint8Array x 164 ops/sec ±0.21% (84 runs sampled)
uint8ArrayToBase64 x 16.44 ops/sec ±6.55% (37 runs sampled)
stringToBase64 x 8.37 ops/sec ±5.35% (25 runs sampled)
base64ToString x 4.30 ops/sec ±0.60% (15 runs sampled)
uint8ArrayToHex x 20.14 ops/sec ±5.41% (38 runs sampled)
hexToUint8Array x 38.27 ops/sec ±0.52% (67 runs sampled)

I added benchmark for all the functions but I didn't necessarily optimize all of them.

The changes were mostly to address the issue with larger arrays and some of the optimizations will only be noticeable on tiny arrays (uint8ArrayToString and stringToUint8Array).

@H4ad H4ad changed the title Perf/making op faster perf: optimizing functions Nov 8, 2023
@sindresorhus
Copy link
Owner

I think you switched the benchmark results, as otherwise, everything got slower.

@H4ad H4ad requested a review from sindresorhus November 8, 2023 13:57
@sindresorhus sindresorhus merged commit 473fe2f into sindresorhus:main Nov 8, 2023
@sindresorhus
Copy link
Owner

Thank you :)

@H4ad H4ad deleted the perf/making-op-faster branch November 8, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants