Buffer.(read|write)(U)Int(LE|BE)(8|16|32)
Open
@ronag is already working on this.
Since Jan 9, 2023.
- Dominant language
- Shell
- Stars
- 399
- Forks
- 11
- Avg merge
- 29m
- Merged PRs (30d)
- 1
Description
Just adding something that I've been looking at which could maybe be improved.
Using Node Buffer vs Int32Array to read/write 32 bit values to buffers.
NAME REPS
-----------------------------------
Buffer 64,553,382
Int32Array 174,148,855
const arrayBuffer = new ArrayBuffer(NUM_CASES * 4)
const buffer = Buffer.from(arrayBuffer)
const buffer32 = new Int32Array(arrayBuffer)
{
Buffer: (index, value) => {
buffer.writeInt32LE(value, index * 4)
assert(buffer.readInt32LE(index * 4) === value)
},
Int32Array: (index, value) => {
buffer32[index] = value
assert(buffer32[index] === value)
},
DataView: () => {
const c = cases[caseIndex]
view.setInt32(caseIndex * 4, c, true)
assert(view.getInt32(caseIndex * 4, true) === c)
if (++caseIndex === NUM_CASES) {
caseIndex = 0
}
},
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.