aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/headers.mjs
blob: ace0d9f00894121d2e11e4bdab106445be39c6b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { bench, run } from "../node_modules/mitata/src/cli.mjs";

// pure JS implementation will optimze this out
bench("new Headers", function () {
  return new Headers();
});

var big = new Headers({
  "Content-Type": "text/plain",
  "Content-Length": "123",
  "X-Custom-Header": "Hello World",
  "X-Another-Custom-Header": "Hello World",
  "X-Yet-Another-Custom-ader": "Hello World",
  "X-Yet-Another-Custom-Heder": "Hello World",
  "X-Yet-Another-Custom-Heade": "Hello World",
  "X-Yet-Another-Custom-Headz": "Hello Worlda",
});

bench("Header.get", function () {
  return big.get("Content-Type");
});

bench("Header.set (standard)", function () {
  return big.set("Content-Type", "text/html");
});

bench("Header.set (non-standard)", function () {
  return big.set("X-My-Custom", "text/html123");
});

if (big.toJSON)
  bench("Header.toJSON", function () {
    return big.toJSON();
  });

bench("Header fromEntries", function () {
  return Object.fromEntries(big.entries());
});

run();