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
41
42
|
// @runtime node, bun
import { bench, run } from "./runner.mjs";
import * as vm from "node:vm";
const context = {
animal: "cat",
count: 2,
};
const script = new vm.Script("animal = 'hey'");
vm.createContext(context);
bench("vm.Script.runInContext", () => {
script.runInContext(context);
});
bench("vm.Script.runInThisContext", () => {
script.runInThisContext(context);
});
bench("vm.Script.runInNewContext", () => {
script.runInNewContext(context);
});
bench("vm.runInContext", () => {
vm.runInContext("animal = 'hey'", context);
});
bench("vm.runInNewContext", () => {
vm.runInNewContext("animal = 'hey'", context);
});
bench("vm.runInThisContext", () => {
vm.runInThisContext("animal = 'hey'", context);
});
bench("vm.createContext", () => {
vm.createContext({ yo: 1 });
});
await run();
|