We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 57480d7 commit 7da30c1Copy full SHA for 7da30c1
bench/snippets/byteLength.mjs
@@ -0,0 +1,27 @@
1
+import { Buffer } from "node:buffer";
2
+import { bench, run } from "../runner.mjs";
3
+
4
+const variations = [
5
+ ["latin1", "hello world"],
6
+ ["utf16", "hello emoji 🤔"],
7
+];
8
9
+for (const [label, string] of variations) {
10
+ const big = Buffer.alloc(1000000, string).toString();
11
+ const small = Buffer.from(string).toString();
12
+ const substring = big.slice(0, big.length - 2);
13
14
+ bench(`${substring.length}`, () => {
15
+ return Buffer.byteLength(substring, "utf8");
16
+ });
17
18
+ bench(`${small.length}`, () => {
19
+ return Buffer.byteLength(small);
20
21
22
+ bench(`${big.length}`, () => {
23
+ return Buffer.byteLength(big);
24
25
+}
26
27
+await run();
0 commit comments