aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/node-vm.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'bench/snippets/node-vm.mjs')
-rw-r--r--bench/snippets/node-vm.mjs42
1 files changed, 42 insertions, 0 deletions
diff --git a/bench/snippets/node-vm.mjs b/bench/snippets/node-vm.mjs
new file mode 100644
index 000000000..6f9d60773
--- /dev/null
+++ b/bench/snippets/node-vm.mjs
@@ -0,0 +1,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();