- From: Jimmy Wärting <notifications@github.com>
- Date: Sat, 04 Feb 2023 06:04:16 -0800
- To: whatwg/encoding <encoding@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/encoding/issues/69/1416760938@github.com>
cbor-x raised similar concerns and prefered to stick to using `node:buffer` `write` method instead of using something more cross env. friendlier such as TextEncoder and drags in the hole node:buffer with it.
```js
let { Buffer } = await import('https://esm.sh/buffer')
let u = new Uint8Array(2048)
let b = Buffer.alloc(2048)
let te = new TextEncoder()
console.time('write')
for (let i = 0; i < 10000000; i++) b.write('hello world', 10)
console.timeEnd('write')
console.time('encodeInto subview')
for (let i = 0; i < 10000000; i++) te.encodeInto('hello world', u.subarray(10))
console.timeEnd('encodeInto subview')
// note that this is on par with buffer.write, but is useless since you can't
// specify a starting index, subarray time needs to be included in a fair comparison
console.time('encodeInto')
for (let i = 0; i < 10000000; i++) te.encodeInto('hello world', u)
console.timeEnd('encodeInto')
```
The browserified buffer module even out perf native TextEncoder
```
Chrome 109
write: 657.280029296875 ms
encodeInto subview: 4531.56005859375 ms
encodeInto: 2966.76904296875 ms
Firefox 109
write: 1463ms
encodeInto subview: 2846ms
encodeInto: 1869ms
Safari 16.2
write: 1750.032ms
encodeInto subview: 1392.487ms
encodeInto: 1011.426ms
```
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/encoding/issues/69#issuecomment-1416760938
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/encoding/issues/69/1416760938@github.com>
Received on Saturday, 4 February 2023 14:04:28 UTC