Replies: 2 comments
-
Depends on what you're doing. Uint8Array is fine for simple byte manipulations but you probably can't beat buffer.includes() with your lovingly open-coded version except for trivial searches. |
Beta Was this translation helpful? Give feedback.
-
In Node.js, the choice between Buffer and TypedArrays depends on your needs. Buffer has a bigger API and was re-implemented for compatibility and performance. Performance may vary, so benchmark your specific use case. If you want a larger API and are comfortable with potential quirks, go with Buffer. If you prefer a standardized and predictable API, use TypedArrays like Uint8Array, following Node.js documentation recommendations. |
Beta Was this translation helpful? Give feedback.
-
However, after typed arrays were introduced with ES6 (in 2015) standard, the Node.js
Buffer
was re-implemented to extend fromUint8Array
for better compatibility and performance. This madeBuffer
a kind of typed array.Several online sources, including StackOverflow answers, mention that
Buffer
has a bigger API and better performance, compared to ES6TypedArrays
.It's obvious that
Buffer
has a larger API, whereBuffer
seems to have approximately 62 methods , whileTypedArray
have only approximately 34 .However, I'm unable to find anything trustworthy regarding performance? Previous documentation version mentioned that
Buffer.slices
is more efficient thanTypedArray.slices
, but that statement has since been removed in recent versions.Furthermore, the Node.JS docs recommend using
TypedArray
's likeUint8Array
with.slices()
since theBuffer
's implementation can have unexpected behaviour.So, is
Buffer
mainly a good choice because of it's larger API, or, are there still some performance related features around it?Beta Was this translation helpful? Give feedback.
All reactions