aboutsummaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-19 12:12:13 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-19 12:12:13 -0700
commit9b28d2009db0bc5502acd6eab074e6f44014ab0f (patch)
tree6f6d57107c1b3abb256a1836db8df8c2648eaca9 /bench
parentf910d791f9ba3f573b4480853dc6b65b57055807 (diff)
downloadbun-9b28d2009db0bc5502acd6eab074e6f44014ab0f.tar.gz
bun-9b28d2009db0bc5502acd6eab074e6f44014ab0f.tar.zst
bun-9b28d2009db0bc5502acd6eab074e6f44014ab0f.zip
Add snippet for node:vm
Diffstat (limited to 'bench')
-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();