Add benchmark comparing performance of this package with node:zlib.crc32 #36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mentioned in #34 (comment)
Here's my manually formatted table of data:
Here's what the terminal colors look like:
So it looks like the JS<->C++ switching cost is most noticeable with many small inputs (many iterations, small buffer), once the JIT has had time to optimize the code. I'm not totally sure the JIT didn't notice that the input data was the same every time and decided to return a constant; pretty difficult to tell. But i think the more important result is that the native code outperforms the JS code in most cases. In the many iterations, large buffer case, the situation I would argue that performance is the most critical, the improvement is about an order of magnitude.
This uses https://github.com/paulmillr/micro-bmark , which seemed suitable for this use case. I'm using node
v20.15.1
.