Skip to content

Instantly share code, notes, and snippets.

@rluvaton
Created November 16, 2022 19:23
Show Gist options
  • Save rluvaton/62a1b4411e027163a9ab96e5b777c537 to your computer and use it in GitHub Desktop.
Save rluvaton/62a1b4411e027163a9ab96e5b777c537 to your computer and use it in GitHub Desktop.
Vitests vs Jest with workers

Jest vs Vitest

Results:

Max Workers Jest (time) Jest (max heap) Vitest (time) Vitest (max heap)
1 29.329 s 1244 MB 13.29s 149 MB
2 18.383 s 944 MB 7.58s 190 MB
4 12.914 s 832 MB 7.40s 203 MB
9 (max) 15.830 s 545 MB 8.80s 119 MB

1 Worker

Jest:

❯ npm test -- --runInBand --logHeapUsage

 PASS  src/search/test/result-matching.test.ts (8.497 s, 463 MB heap size)
 PASS  src/search/test/authorization-filtering.test.ts (546 MB heap size)
 PASS  src/authorization/service.test.ts (588 MB heap size)
 PASS  src/search/test/elastic-search.test.ts (655 MB heap size)
 PASS  src/http/test/server-auth.test.ts (809 MB heap size)
 PASS  src/http/test/request-id.test.ts (961 MB heap size)
 PASS  src/search/test/response-format.test.ts (1111 MB heap size)
 PASS  src/http/server.test.ts (1244 MB heap size)
 PASS  src/lib/monitoring/fastify.test.ts (935 MB heap size)
 PASS  src/http/test/assertion.test.ts (1077 MB heap size)
 PASS  src/http/test/etag.test.ts (1218 MB heap size)
 PASS  src/search/search.test.ts (1079 MB heap size)

Test Suites: 12 passed, 12 total
Tests:       2 skipped, 197 passed, 199 total
Snapshots:   0 total
Time:        29.329 s

Vitest:

❯ vitest run --threads=false

 ✓ src/search/test/result-matching.test.ts (41) 6156ms 93 MB heap used
 ✓ src/search/test/authorization-filtering.test.ts (13) 2379ms 97 MB heap used
 ✓ src/authorization/service.test.ts (21) 1008ms 99 MB heap used
 ✓ src/search/test/elastic-search.test.ts (9) 937ms 86 MB heap used
 ✓ src/http/test/server-auth.test.ts (37) 435ms 118 MB heap used
 ✓ src/http/test/request-id.test.ts (36) 128 MB heap used
 ✓ src/search/test/response-format.test.ts (5) 382ms 133 MB heap used
 ✓ src/http/server.test.ts (23) 133 MB heap used
 ✓ src/lib/monitoring/fastify.test.ts (4) 142 MB heap used
 ✓ src/http/test/assertion.test.ts (2) 138 MB heap used
 ✓ src/http/test/etag.test.ts (7) 149 MB heap used
 ✓ src/search/search.test.ts (1) 141 MB heap used

 Test Files  12 passed (12)
      Tests  197 passed | 2 skipped (199)
   Start at  20:51:06
   Duration  13.29s (transform 458ms, setup 901ms, collect 264ms, tests 11.71s)

2 Workers

Jest:

❯ npm test -- --maxWorkers=2 --logHeapUsage --silent=true

 PASS  src/search/test/authorization-filtering.test.ts (8.082 s, 404 MB heap size)
 PASS  src/search/test/result-matching.test.ts (9.391 s, 425 MB heap size)
 PASS  src/authorization/service.test.ts (540 MB heap size)
 PASS  src/search/test/elastic-search.test.ts (439 MB heap size)
 PASS  src/http/test/server-auth.test.ts (514 MB heap size)
 PASS  src/http/test/request-id.test.ts (528 MB heap size)
 PASS  src/http/server.test.ts (667 MB heap size)
 PASS  src/search/test/response-format.test.ts (584 MB heap size)
 PASS  src/lib/monitoring/fastify.test.ts (813 MB heap size)
 PASS  src/http/test/assertion.test.ts (729 MB heap size)
 PASS  src/http/test/etag.test.ts (944 MB heap size)
 PASS  src/search/search.test.ts (859 MB heap size)

Test Suites: 12 passed, 12 total
Tests:       2 skipped, 197 passed, 199 total
Snapshots:   0 total
Time:        18.383 s

Vitest

❯ VITEST_MIN_THREADS=2 VITEST_MAX_THREADS=2 vitest run

 ✓ src/search/test/authorization-filtering.test.ts (13) 3901ms 105 MB heap used
 ✓ src/search/test/result-matching.test.ts (41) 5397ms 109 MB heap used
 ✓ src/authorization/service.test.ts (21) 1017ms 100 MB heap used
 ✓ src/search/test/elastic-search.test.ts (9) 927ms 112 MB heap used
 ✓ src/http/test/server-auth.test.ts (37) 402ms 140 MB heap used
 ✓ src/http/test/request-id.test.ts (36) 174 MB heap used
 ✓ src/search/test/response-format.test.ts (5) 347ms 113 MB heap used
 ✓ src/http/server.test.ts (23) 174 MB heap used
 ✓ src/lib/monitoring/fastify.test.ts (4) 187 MB heap used
 ✓ src/http/test/assertion.test.ts (2) 188 MB heap used
 ✓ src/http/test/etag.test.ts (7) 115 MB heap used
 ✓ src/search/search.test.ts (1) 190 MB heap used

 Test Files  12 passed (12)
      Tests  197 passed | 2 skipped (199)
   Start at  21:01:47
   Duration  7.58s (transform 382ms, setup 1.58s, collect 303ms, tests 12.46s)

4 Workers

Jest

❯ npm test -- --maxWorkers=4 --logHeapUsage --silent=true

 PASS  src/search/test/elastic-search.test.ts (7.555 s, 412 MB heap size)
 PASS  src/authorization/service.test.ts (7.646 s, 398 MB heap size)
 PASS  src/search/test/authorization-filtering.test.ts (8.996 s, 412 MB heap size)
 PASS  src/http/test/request-id.test.ts (554 MB heap size)
 PASS  src/http/test/server-auth.test.ts (566 MB heap size)
 PASS  src/http/server.test.ts (688 MB heap size)
 PASS  src/lib/monitoring/fastify.test.ts (711 MB heap size)
 PASS  src/search/test/result-matching.test.ts (10.914 s, 426 MB heap size)
 PASS  src/http/test/assertion.test.ts (832 MB heap size)
 PASS  src/http/test/etag.test.ts (566 MB heap size)
 PASS  src/search/test/response-format.test.ts (554 MB heap size)
 PASS  src/search/search.test.ts (556 MB heap size)

Test Suites: 12 passed, 12 total
Tests:       2 skipped, 197 passed, 199 total
Snapshots:   0 total
Time:        12.914 s

Vitest

❯ VITEST_MIN_THREADS=4 VITEST_MAX_THREADS=4 vitest run

 ✓ src/authorization/service.test.ts (21) 2979ms 91 MB heap used
 ✓ src/search/test/authorization-filtering.test.ts (13) 4683ms 108 MB heap used
 ✓ src/search/test/elastic-search.test.ts (9) 2929ms 96 MB heap used
 ✓ src/search/test/result-matching.test.ts (41) 5901ms 114 MB heap used
 ✓ src/http/test/request-id.test.ts (36) 338ms 96 MB heap used
 ✓ src/http/test/server-auth.test.ts (37) 610ms 163 MB heap used
 ✓ src/search/test/response-format.test.ts (5) 604ms 103 MB heap used
 ✓ src/http/server.test.ts (23) 178 MB heap used
 ✓ src/lib/monitoring/fastify.test.ts (4) 188 MB heap used
 ✓ src/http/test/assertion.test.ts (2) 197 MB heap used
 ✓ src/http/test/etag.test.ts (7) 203 MB heap used
 ✓ src/search/search.test.ts (1) 198 MB heap used

 Test Files  12 passed (12)
      Tests  197 passed | 2 skipped (199)
   Start at  21:06:06
   Duration  7.40s (transform 431ms, setup 3.65s, collect 687ms, tests 18.36s)

Max workers (9)

Jest

❯ npm test -- --maxWorkers=9 --logHeapUsage --silent=true

 PASS  src/lib/monitoring/fastify.test.ts (8.648 s, 398 MB heap size)
 PASS  src/http/server.test.ts (8.702 s, 389 MB heap size)
 PASS  src/http/test/request-id.test.ts (8.974 s, 406 MB heap size)
 PASS  src/http/test/server-auth.test.ts (9.141 s, 422 MB heap size)
 PASS  src/http/test/assertion.test.ts (531 MB heap size)
 PASS  src/http/test/etag.test.ts (535 MB heap size)
 PASS  src/search/search.test.ts (545 MB heap size)
 PASS  src/search/test/response-format.test.ts (11.263 s, 398 MB heap size)
 PASS  src/search/test/elastic-search.test.ts (12.083 s, 395 MB heap size)
 PASS  src/authorization/service.test.ts (12.161 s, 393 MB heap size)
 PASS  src/search/test/authorization-filtering.test.ts (13.728 s, 409 MB heap size)
 PASS  src/search/test/result-matching.test.ts (15.058 s, 414 MB heap size)

Test Suites: 12 passed, 12 total
Tests:       2 skipped, 197 passed, 199 total
Snapshots:   0 total
Time:        15.83 s

Vitest

❯ VITEST_MIN_THREADS=9 VITEST_MAX_THREADS=9 vitest run

 ✓ src/lib/monitoring/fastify.test.ts (4) 704ms 106 MB heap used
 ✓ src/http/server.test.ts (23) 754ms 104 MB heap used
 ✓ src/authorization/service.test.ts (21) 3486ms 104 MB heap used
 ✓ src/http/test/server-auth.test.ts (37) 1070ms 97 MB heap used
 ✓ src/http/test/request-id.test.ts (36) 825ms 96 MB heap used
 ✓ src/search/test/response-format.test.ts (5) 2691ms 106 MB heap used
 ✓ src/search/test/result-matching.test.ts (41) 6566ms 107 MB heap used
 ✓ src/search/test/elastic-search.test.ts (9) 3352ms 108 MB heap used
 ✓ src/search/test/authorization-filtering.test.ts (13) 4632ms 116 MB heap used
 ✓ src/http/test/assertion.test.ts (2) 113 MB heap used
 ✓ src/http/test/etag.test.ts (7) 119 MB heap used
 ✓ src/search/search.test.ts (1) 351ms 107 MB heap used

 Test Files  12 passed (12)
      Tests  197 passed | 2 skipped (199)
   Start at  21:10:58
   Duration  8.80s (transform 452ms, setup 11.31s, collect 3.10s, tests 24.57s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment