Skip to content

Commit 6811d64

Browse files
authored
docs(swc-angular): 📝 add benchmark data (#308)
1 parent 47b2913 commit 6811d64

File tree

2 files changed

+141
-14
lines changed

2 files changed

+141
-14
lines changed

packages/swc-angular/README.md

+114-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
# ⚡️ Speed Up Angular Testing with SWC 🦀
22

3+
<!-- TOC -->
4+
5+
* [⚡️ Speed Up Angular Testing with SWC 🦀](#-speed-up-angular-testing-with-swc-)
6+
* [👀 What is this?](#-what-is-this)
7+
* [🤔 Context](#-context)
8+
* [🥇 Benchmark Summary](#-benchmark-summary)
9+
* [🎭 Setup with Jest](#-setup-with-jest)
10+
* [1. Install](#1-install)
11+
* [2. Configure](#2-configure)
12+
* [3. Add `reflect-metadata`](#3-add-reflect-metadata)
13+
* [⚡️Setup with Vitest](#setup-with-vitest)
14+
* [1. Install](#1-install-1)
15+
* [2. Configure](#2-configure-1)
16+
* [3. Add `reflect-metadata`](#3-add-reflect-metadata-1)
17+
* [🥇 Benchmark Data](#-benchmark-data)
18+
* [🔥 No Cache](#-no-cache)
19+
* [⚡️ With Cache](#-with-cache)
20+
* [🥱 Cold Start](#-cold-start)
21+
* [Configurations](#configurations)
22+
* [Source](#source)
23+
24+
<!-- TOC -->
25+
326
## 👀 What is this?
427

528
This is a set of Angular presets that enable you to use [SWC (Speedy Web Compiler)](https://swc.rs/) with Jest or
629
Vitest.
730

8-
**Switching to SWC can speed up your tests by 2x to 5x.**
31+
**Switching to SWC can speed up your tests by 2x to 12x.**
932

1033
## 🤔 Context
1134

@@ -18,13 +41,16 @@ fast.
1841
This package enables you to use SWC with Angular projects by setting the right configuration for SWC and using
1942
our Angular plugin for SWC [`@jscutlery/swc-angular-plugin`](../swc-angular-plugin)
2043

21-
## 🥇 Benchmark
44+
## 🥇 Benchmark Summary
2245

23-
| ts-jest | @swc/jest |
24-
|---------|---------------------|
25-
| 85s | 35s _(2.4x faster)_ |
46+
![Benchmark](benchmark.svg)
2647

27-
💻 try it yourself: https://github.com/yjaaidi/experiments/tree/angular-jest-swc-benchmark
48+
_This chart is based on the [benchmark where all caches were disabled](#-no-cache) as in most cases we will still have
49+
to transform the code that we changed and which is affecting our tests._
50+
_In addition to that, incremental build tools like [Nx](https://nx.dev) (or jest/vitest `changedSince`/`changed`
51+
options) will reduce the amount of transforms._
52+
53+
_Cf. [Detailed Benchmark Data](#-no-cache)_
2854

2955
## 🎭 Setup with Jest
3056

@@ -49,14 +75,13 @@ export default {
4975
// ...
5076
transform: {
5177
'^.+\\.(ts|mjs|js)$': swcAngularJestTransformer(),
52-
'^.+\\.(html)$':
53-
[
54-
'jest-preset-angular',
55-
{
56-
tsconfig: '<rootDir>/tsconfig.spec.json',
57-
stringifyContentPathRegex: '\\.(html|svg)$',
58-
},
59-
],
78+
'^.+\\.(html)$': [
79+
'jest-preset-angular',
80+
{
81+
tsconfig: '<rootDir>/tsconfig.spec.json',
82+
stringifyContentPathRegex: '\\.(html|svg)$',
83+
},
84+
],
6085
},
6186
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
6287
// ...
@@ -108,3 +133,78 @@ located at `src/test-setup.ts`.
108133
```ts
109134
import 'reflect-metadata';
110135
```
136+
137+
## 🥇 Benchmark Data
138+
139+
### 🔥 No Cache
140+
141+
All caches are cleared before each benchmark run.
142+
143+
| Configuration | Relative | Mean [s] | Min [s] | Max [s] |
144+
|:------------------------------|-------------:|---------------:|--------:|--------:|
145+
| 🥇`vitest-swc-no-isolate` | 1.00 | 3.137 ± 0.061 | 3.042 | 3.227 |
146+
| 🥈`jest-swc` | 3.31 ± 0.15 | 10.393 ± 0.429 | 9.745 | 10.994 |
147+
| 🥉`angular-cli-karma` | 3.52 ± 0.53 | 11.041 ± 1.642 | 10.218 | 15.690 |
148+
| `angular-cli-web-test-runner` | 5.46 ± 0.45 | 17.118 ± 1.362 | 16.473 | 20.911 |
149+
| `jest` | 5.78 ± 0.25 | 18.132 ± 0.716 | 17.553 | 19.998 |
150+
| `angular-cli-jest` | 8.61 ± 0.63 | 27.009 ± 1.902 | 24.938 | 30.450 |
151+
| `vitest-swc` | 8.94 ± 0.21 | 28.038 ± 0.402 | 27.539 | 28.617 |
152+
| `vitest` | 11.43 ± 0.32 | 35.872 ± 0.727 | 34.452 | 37.340 |
153+
| `vitest-no-isolate` | 11.49 ± 0.25 | 36.061 ± 0.369 | 35.414 | 36.502 |
154+
155+
### ⚡️ With Cache
156+
157+
All tests are ran once to warm up the cache before running the benchmark.
158+
159+
| Configuration | Relative | Mean [s] | Min [s] | Max [s] |
160+
|:------------------------------|-------------:|---------------:|--------:|--------:|
161+
| 🥇`vitest-swc-no-isolate` | 1.00 | 3.092 ± 0.090 | 3.030 | 3.301 |
162+
| 🥈`angular-cli-karma` | 1.91 ± 0.07 | 5.901 ± 0.139 | 5.718 | 6.131 |
163+
| 🥉`jest-swc` | 2.93 ± 0.18 | 9.045 ± 0.494 | 8.513 | 10.065 |
164+
| `jest` | 4.07 ± 0.25 | 12.581 ± 0.663 | 11.572 | 13.915 |
165+
| `angular-cli-web-test-runner` | 5.96 ± 0.29 | 18.428 ± 0.711 | 17.497 | 19.262 |
166+
| `angular-cli-jest` | 8.46 ± 1.04 | 26.170 ± 3.117 | 23.350 | 31.983 |
167+
| `vitest-swc` | 9.28 ± 0.36 | 28.691 ± 0.728 | 27.977 | 30.488 |
168+
| `vitest-no-isolate` | 11.74 ± 0.45 | 36.286 ± 0.880 | 35.107 | 38.018 |
169+
| `vitest` | 12.18 ± 0.63 | 37.666 ± 1.625 | 35.563 | 41.503 |
170+
171+
- _Note that, as of
172+
today, [vitest doesn't cache transformed files](https://vitest.dev/config/#cache:~:text=At%20the%20moment%20Vitest%20stores%20cache%20for%20test%20results%20to%20run%20the%20longer%20and%20failed%20tests%20first)._
173+
174+
### 🥱 Cold Start
175+
176+
Run a single test module just and try to measure the bootstrap time.
177+
178+
| Configuration | Relative | Mean [s] | Min [s] | Max [s] |
179+
|:------------------------------|------------:|--------------:|--------:|--------:|
180+
| 🥇`vitest-swc-no-isolate` | 1.00 | 1.260 ± 0.024 | 1.241 | 1.314 |
181+
| 🥈`vitest-swc` | 1.00 ± 0.03 | 1.262 ± 0.026 | 1.225 | 1.305 |
182+
| 🥉`jest-swc` | 1.44 ± 0.15 | 1.812 ± 0.186 | 1.714 | 2.310 |
183+
| `vitest-no-isolate` | 1.47 ± 0.05 | 1.846 ± 0.056 | 1.797 | 1.949 |
184+
| `vitest` | 1.61 ± 0.16 | 2.030 ± 0.198 | 1.814 | 2.423 |
185+
| `jest` | 1.69 ± 0.08 | 2.136 ± 0.094 | 2.017 | 2.356 |
186+
| `angular-cli-jest` | 1.73 ± 0.39 | 2.186 ± 0.495 | 1.869 | 3.119 |
187+
| `angular-cli-web-test-runner` | 2.06 ± 1.15 | 2.602 ± 1.451 | 2.080 | 6.730 |
188+
| `angular-cli-karma` | 5.08 ± 1.30 | 6.400 ± 1.636 | 5.377 | 10.177 |
189+
190+
### Configurations
191+
192+
| | Configuration | Test Isolation\* |
193+
|-------------------------------|:-------------------------------|-----------------:|
194+
| `angular-cli-karma` | Angular CLI's Karma | false |
195+
| `angular-cli-jest` | Angular CLI's Jest | true |
196+
| `angular-cli-web-test-runner` | Angular CLI's @web/test-runner | true |
197+
| `jest` | Jest | true |
198+
| `jest-swc` | Jest + SWC | true |
199+
| `vitest` | Vitest | true |
200+
| `vitest-no-isolate` | Vitest + No Isolation | false |
201+
| `vitest-swc` | Vitest + SWC | true |
202+
| `vitest-swc-no-isolate` | Vitest + SWC + No Isolation | false |
203+
204+
- _Test Isolation: this tells whether each test module has its own testing environment or if each one is isolated. (i.e.
205+
globals like the DOM are shared, asynchronous code might bleed between tests, etc...)_
206+
207+
### Source
208+
209+
💻 try it yourself: https://github.com/yjaaidi/experiments/tree/angular-jest-swc-benchmark
210+
or checkout the last benchmark results: https://github.com/yjaaidi/experiments/actions/workflows/benchmark.yml

packages/swc-angular/benchmark.svg

+27
Loading

0 commit comments

Comments
 (0)