mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
43 lines
820 B
JavaScript
43 lines
820 B
JavaScript
// @runtime node, bun
|
|
import * as vm from "node:vm";
|
|
import { bench, run } from "../runner.mjs";
|
|
|
|
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();
|