aboutsummaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-23 23:03:40 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-23 23:03:40 -0800
commit6bfb65b31278dbc470d73036af1bb10f1051f509 (patch)
tree1f8e89d44419914cd34d4586d473543717bee83b /bench
parentdc330701d2e6e68922953616a7c0c6de41d98233 (diff)
downloadbun-6bfb65b31278dbc470d73036af1bb10f1051f509.tar.gz
bun-6bfb65b31278dbc470d73036af1bb10f1051f509.tar.zst
bun-6bfb65b31278dbc470d73036af1bb10f1051f509.zip
Add `expect().toEqual()` bench
Diffstat (limited to 'bench')
-rw-r--r--bench/expect-to-equal/.gitignore169
-rw-r--r--bench/expect-to-equal/README.md43
-rwxr-xr-xbench/expect-to-equal/bun.lockbbin0 -> 120819 bytes
-rw-r--r--bench/expect-to-equal/expect-to-equal.test.js42
-rw-r--r--bench/expect-to-equal/expect-to-equal.vitest.test.js41
-rw-r--r--bench/expect-to-equal/index.ts1
-rw-r--r--bench/expect-to-equal/package.json9
-rw-r--r--bench/expect-to-equal/tsconfig.json20
8 files changed, 325 insertions, 0 deletions
diff --git a/bench/expect-to-equal/.gitignore b/bench/expect-to-equal/.gitignore
new file mode 100644
index 000000000..f81d56eaa
--- /dev/null
+++ b/bench/expect-to-equal/.gitignore
@@ -0,0 +1,169 @@
+# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
+
+# Logs
+
+logs
+_.log
+npm-debug.log_
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+.pnpm-debug.log*
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+
+report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
+
+# Runtime data
+
+pids
+_.pid
+_.seed
+\*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+
+lib-cov
+
+# Coverage directory used by tools like istanbul
+
+coverage
+\*.lcov
+
+# nyc test coverage
+
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+
+bower_components
+
+# node-waf configuration
+
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+
+build/Release
+
+# Dependency directories
+
+node_modules/
+jspm_packages/
+
+# Snowpack dependency directory (https://snowpack.dev/)
+
+web_modules/
+
+# TypeScript cache
+
+\*.tsbuildinfo
+
+# Optional npm cache directory
+
+.npm
+
+# Optional eslint cache
+
+.eslintcache
+
+# Optional stylelint cache
+
+.stylelintcache
+
+# Microbundle cache
+
+.rpt2_cache/
+.rts2_cache_cjs/
+.rts2_cache_es/
+.rts2_cache_umd/
+
+# Optional REPL history
+
+.node_repl_history
+
+# Output of 'npm pack'
+
+\*.tgz
+
+# Yarn Integrity file
+
+.yarn-integrity
+
+# dotenv environment variable files
+
+.env
+.env.development.local
+.env.test.local
+.env.production.local
+.env.local
+
+# parcel-bundler cache (https://parceljs.org/)
+
+.cache
+.parcel-cache
+
+# Next.js build output
+
+.next
+out
+
+# Nuxt.js build / generate output
+
+.nuxt
+dist
+
+# Gatsby files
+
+.cache/
+
+# Comment in the public line in if your project uses Gatsby and not Next.js
+
+# https://nextjs.org/blog/next-9-1#public-directory-support
+
+# public
+
+# vuepress build output
+
+.vuepress/dist
+
+# vuepress v2.x temp and cache directory
+
+.temp
+.cache
+
+# Docusaurus cache and generated files
+
+.docusaurus
+
+# Serverless directories
+
+.serverless/
+
+# FuseBox cache
+
+.fusebox/
+
+# DynamoDB Local files
+
+.dynamodb/
+
+# TernJS port file
+
+.tern-port
+
+# Stores VSCode versions used for testing VSCode extensions
+
+.vscode-test
+
+# yarn v2
+
+.yarn/cache
+.yarn/unplugged
+.yarn/build-state.yml
+.yarn/install-state.gz
+.pnp.\*
diff --git a/bench/expect-to-equal/README.md b/bench/expect-to-equal/README.md
new file mode 100644
index 000000000..d9023f4a7
--- /dev/null
+++ b/bench/expect-to-equal/README.md
@@ -0,0 +1,43 @@
+# expect-to-equal
+
+To install dependencies:
+
+```bash
+bun install
+```
+
+To run in Bun:
+
+```bash
+# so it doesn't run the vitest one
+bun wiptest expect-to-equal.test.js
+```
+
+To run in Jest:
+
+```bash
+# If you remove the import the performance doesn't change much
+NODE_OPTIONS="--experimental-vm-modules" ./node_modules/.bin/jest expect-to-equal.test.js
+```
+
+To run in Vitest:
+
+```bash
+./node_modules/.bin/vitest --run expect-to-equal.vitest.test.js
+```
+
+Output on my machine (M1):
+
+bun:test (bun v0.3.0):
+
+> [36.40ms] expect().toEqual() x 10000
+
+jest (node v18.11.0)
+
+> expect().toEqual() x 10000: 5053 ms
+
+vitest (node v18.11.0)
+
+> expect().toEqual() x 10000: 401.08ms
+
+This project was created using `bun init` in bun v0.3.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
diff --git a/bench/expect-to-equal/bun.lockb b/bench/expect-to-equal/bun.lockb
new file mode 100755
index 000000000..74db7077d
--- /dev/null
+++ b/bench/expect-to-equal/bun.lockb
Binary files differ
diff --git a/bench/expect-to-equal/expect-to-equal.test.js b/bench/expect-to-equal/expect-to-equal.test.js
new file mode 100644
index 000000000..e8361596f
--- /dev/null
+++ b/bench/expect-to-equal/expect-to-equal.test.js
@@ -0,0 +1,42 @@
+// bun:test automatically rewrites this import to bun:test when run in bun
+import { test, expect } from "@jest/globals";
+
+const N = parseInt(process.env.RUN_COUNT || "10000", 10);
+if (!Number.isSafeInteger(N)) {
+ throw new Error("Invalid RUN_COUNT");
+}
+
+const label = "expect().toEqual() x " + N;
+
+test(label, () => {
+ console.time(label);
+ for (let runsLeft = N; runsLeft > 0; runsLeft--) {
+ expect("hello").toEqual("hello");
+ expect(123).toEqual(123);
+
+ expect({ a: 1, b: 2 }).toEqual({ b: 2, a: 1 });
+ expect([1, 2, 3]).toEqual([1, 2, 3]);
+ expect({ a: 1, b: 2 }).not.toEqual({ b: 2, a: 1, c: 3 });
+ expect([1, 2, 3]).not.toEqual([1, 2, 3, 4]);
+ expect({ a: 1, b: 2, c: 3 }).not.toEqual({ a: 1, b: 2 });
+ expect([1, 2, 3, 4]).not.toEqual([1, 2, 3]);
+
+ let a = [{ a: 1 }, { b: 2, c: 3, d: 4 }, { e: 5, f: 6 }];
+ let b = [{ a: 1 }, { b: 2, c: 3, d: 4 }, { e: 5, f: 6 }];
+ expect(a).toEqual(b);
+ expect(b).toEqual(a);
+ a[0].a = 2;
+ expect(a).not.toEqual(b);
+ expect(b).not.toEqual(a);
+
+ let c = { [Symbol("test")]: 1 };
+ let d = { [Symbol("test")]: 1 };
+ expect(c).not.toEqual(d);
+ expect(d).not.toEqual(c);
+
+ a = { a: 1, b: 2, c: 3 };
+ b = { a: 1, b: 2 };
+ expect(a).not.toEqual(b);
+ }
+ console.timeEnd(label);
+});
diff --git a/bench/expect-to-equal/expect-to-equal.vitest.test.js b/bench/expect-to-equal/expect-to-equal.vitest.test.js
new file mode 100644
index 000000000..aea945180
--- /dev/null
+++ b/bench/expect-to-equal/expect-to-equal.vitest.test.js
@@ -0,0 +1,41 @@
+import { test, expect } from "vitest";
+
+const N = parseInt(process.env.RUN_COUNT || "10000", 10);
+if (!Number.isSafeInteger(N)) {
+ throw new Error("Invalid RUN_COUNT");
+}
+
+const label = "expect().toEqual() x " + N;
+
+test(label, () => {
+ console.time(label);
+ for (let runsLeft = N; runsLeft > 0; runsLeft--) {
+ expect("hello").toEqual("hello");
+ expect(123).toEqual(123);
+
+ expect({ a: 1, b: 2 }).toEqual({ b: 2, a: 1 });
+ expect([1, 2, 3]).toEqual([1, 2, 3]);
+ expect({ a: 1, b: 2 }).not.toEqual({ b: 2, a: 1, c: 3 });
+ expect([1, 2, 3]).not.toEqual([1, 2, 3, 4]);
+ expect({ a: 1, b: 2, c: 3 }).not.toEqual({ a: 1, b: 2 });
+ expect([1, 2, 3, 4]).not.toEqual([1, 2, 3]);
+
+ let a = [{ a: 1 }, { b: 2, c: 3, d: 4 }, { e: 5, f: 6 }];
+ let b = [{ a: 1 }, { b: 2, c: 3, d: 4 }, { e: 5, f: 6 }];
+ expect(a).toEqual(b);
+ expect(b).toEqual(a);
+ a[0].a = 2;
+ expect(a).not.toEqual(b);
+ expect(b).not.toEqual(a);
+
+ let c = { [Symbol("test")]: 1 };
+ let d = { [Symbol("test")]: 1 };
+ expect(c).not.toEqual(d);
+ expect(d).not.toEqual(c);
+
+ a = { a: 1, b: 2, c: 3 };
+ b = { a: 1, b: 2 };
+ expect(a).not.toEqual(b);
+ }
+ console.timeEnd(label);
+});
diff --git a/bench/expect-to-equal/index.ts b/bench/expect-to-equal/index.ts
new file mode 100644
index 000000000..f67b2c645
--- /dev/null
+++ b/bench/expect-to-equal/index.ts
@@ -0,0 +1 @@
+console.log("Hello via Bun!"); \ No newline at end of file
diff --git a/bench/expect-to-equal/package.json b/bench/expect-to-equal/package.json
new file mode 100644
index 000000000..f775cecd2
--- /dev/null
+++ b/bench/expect-to-equal/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "expect-to-equal",
+ "module": "index.ts",
+ "type": "module",
+ "devDependencies": {
+ "jest": "^29.3.1",
+ "vitest": "^0.25.3"
+ }
+}
diff --git a/bench/expect-to-equal/tsconfig.json b/bench/expect-to-equal/tsconfig.json
new file mode 100644
index 000000000..30522c12f
--- /dev/null
+++ b/bench/expect-to-equal/tsconfig.json
@@ -0,0 +1,20 @@
+{
+ "compilerOptions": {
+ "lib": [
+ "ESNext"
+ ],
+ "module": "esnext",
+ "target": "esnext",
+ "moduleResolution": "nodenext",
+ "strict": true,
+ "downlevelIteration": true,
+ "skipLibCheck": true,
+ "jsx": "preserve",
+ "allowSyntheticDefaultImports": true,
+ "forceConsistentCasingInFileNames": true,
+ "allowJs": true,
+ "types": [
+ "bun-types" // add Bun global
+ ]
+ }
+} \ No newline at end of file