Skip to content

Conversation

jawj
Copy link

@jawj jawj commented Dec 12, 2024

Following up on #364 and #366, this patch switches the hexSlice implementation to use TypedArrays and TextDecoder. It also adds a performance benchmark for toString('hex').

In Node on an M3 Pro MacBook, the benchmark shows a 5x speed-up on a 4096-byte buffer, achieving 75% of the speed of the native method. The speed-up is generally larger as the buffer size increases.

Before:

BrowserBuffer#toString("hex") x 72,483 ops/sec ±0.19% (99 runs sampled)
NodeBuffer#toString("hex") x 527,266 ops/sec ±0.33% (97 runs sampled)
Fastest is NodeBuffer#toString("hex")

After:

BrowserBuffer#toString("hex") x 403,058 ops/sec ±0.30% (98 runs sampled)
NodeBuffer#toString("hex") x 533,325 ops/sec ±0.21% (98 runs sampled)
Fastest is NodeBuffer#toString("hex")

@jawj
Copy link
Author

jawj commented Dec 19, 2024

@dcousens Any chance of merging this in the near future? Thanks.

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.

1 participant