Skip to content

Commit

Permalink
test(perf): add per test file overhead benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal committed Feb 10, 2021
1 parent 49a5ac9 commit 4c6a4c7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
/website/translated_docs
/website/i18n/*

/benchmarks/*/node_modules/

/reports/*

coverage
Expand Down
1 change: 1 addition & 0 deletions benchmarks/test-file-overhead/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1-9]*.test.js
1 change: 1 addition & 0 deletions benchmarks/test-file-overhead/0.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it('is fast', () => {});
6 changes: 6 additions & 0 deletions benchmarks/test-file-overhead/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
First, run `./prepare.sh` to generate the benchmark files. On Windows, use a Bash (WSL, Git, Cygwinm ...) to do this, but you can use CMD for the actual benchmark run if the CMD environment is what you want to benchmark for.

To run the benchmark, use a benchmarking tool such as [hyperfine](https://github.com/sharkdp/hyperfine):
```sh
hyperfine -w 3 -m 10 ../../jest /tmp/other-jest-clone-to-compare-against/jest
```
5 changes: 5 additions & 0 deletions benchmarks/test-file-overhead/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
4 changes: 4 additions & 0 deletions benchmarks/test-file-overhead/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
for i in {1..499}; do
cp 0.test.js $i.test.js
done
11 changes: 11 additions & 0 deletions benchmarks/test-file-overhead/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4

"root-workspace-0b6124@workspace:.":
version: 0.0.0-use.local
resolution: "root-workspace-0b6124@workspace:."
languageName: unknown
linkType: soft
1 change: 1 addition & 0 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type ModuleRegistry = Map<string, InitialModule | Module>;
// * take sufficiently long to require to warrant an optimization.
// When required from the outside, they use the worker's require cache and are thus
// only loaded once per worker, not once per test file.
// Use /benchmarks/test-file-overhead to measure the impact.
// Note that this only applies when they are required in an internal context;
// users who require one of these modules in their tests will still get the module from inside the VM.
// Prefer listing a module here only if it is impractical to use the jest-resolve-outside-vm-option where it is required,
Expand Down

0 comments on commit 4c6a4c7

Please sign in to comment.