Skip to content

Commit e948374

Browse files
Merge pull request askama-rs#342 from Kijewski/pr-no-derive
Make `derive` optional
2 parents da18bc0 + 98cb423 commit e948374

File tree

22 files changed

+212
-24
lines changed

22 files changed

+212
-24
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- run: |
2727
set -eu
2828
for PKG in \
29-
examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
29+
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
3030
rinja rinja_derive rinja_derive_standalone rinja_parser \
3131
testing testing-alloc testing-no-std testing-renamed
3232
do
@@ -116,7 +116,7 @@ jobs:
116116
cargo sort --check --check-format --grouped
117117
set -eu
118118
for PKG in \
119-
examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
119+
bench-build examples/actix-web-app examples/axum-app examples/poem-app examples/rocket-app examples/salvo-app examples/warp-app fuzzing \
120120
rinja rinja_derive rinja_derive_standalone rinja_parser \
121121
testing testing-alloc testing-no-std testing-renamed
122122
do
@@ -159,7 +159,7 @@ jobs:
159159
strategy:
160160
matrix:
161161
package: [
162-
examples/actix-web-app, examples/axum-app, examples/poem-app, examples/rocket-app, examples/salvo-app, examples/warp-app, fuzzing,
162+
bench-build, examples/actix-web-app, examples/axum-app, examples/poem-app, examples/rocket-app, examples/salvo-app, examples/warp-app, fuzzing,
163163
rinja, rinja_derive, rinja_derive_standalone, rinja_parser,
164164
testing, testing-alloc, testing-no-std, testing-renamed,
165165
]

bench-build/.rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.rustfmt.toml

bench-build/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "bench-build"
3+
version = "0.3.5"
4+
authors = ["rinja-rs developers"]
5+
edition = "2021"
6+
rust-version = "1.81"
7+
publish = false
8+
9+
[dependencies]
10+
rinja = { path = "../rinja", version = "0.3.5", default-features = false, features = ["std"] }
11+
rinja_derive = { path = "../rinja_derive", version = "0.3.5", features = ["std"] }
12+
13+
[features]
14+
default = []
15+
derive = ["rinja/derive"]
16+
17+
[workspace]
18+
members = ["."]

bench-build/LICENSE-APACHE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-APACHE

bench-build/LICENSE-MIT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-MIT

bench-build/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Run the script `./run.sh` in this directory to compare the compile compile of `rinja`
2+
3+
* uses feature `derive` vs
4+
* it does not use that feature.
5+
6+
The output might look like:
7+
8+
```text
9+
Benchmark 1: cargo run --features=derive
10+
Time (mean ± σ): 3.378 s ± 0.041 s [User: 7.944 s, System: 1.018 s]
11+
Range (min … max): 3.345 s … 3.424 s 3 runs
12+
13+
Benchmark 2: cargo run
14+
Time (mean ± σ): 3.283 s ± 0.130 s [User: 8.400 s, System: 1.091 s]
15+
Range (min … max): 3.141 s … 3.398 s 3 runs
16+
17+
Summary
18+
cargo run ran
19+
1.03 ± 0.04 times faster than cargo run --features=derive
20+
21+
----------
22+
23+
Benchmark 1: cargo run --release --features=derive
24+
Time (mean ± σ): 4.733 s ± 0.050 s [User: 9.026 s, System: 0.749 s]
25+
Range (min … max): 4.689 s … 4.788 s 3 runs
26+
27+
Benchmark 2: cargo run --release
28+
Time (mean ± σ): 4.504 s ± 0.032 s [User: 9.010 s, System: 0.733 s]
29+
Range (min … max): 4.481 s … 4.541 s 3 runs
30+
31+
Summary
32+
cargo run --release ran
33+
1.05 ± 0.01 times faster than cargo run --release --features=derive
34+
```
35+
36+
This shows that – while it is less convenient – for small projects it might be better
37+
to use the following setup.
38+
This might be especially true if you are using `rinja` in a library.
39+
Without the feature, `cargo` will be able to compile more dependencies in parallel.
40+
41+
```toml
42+
# Cargo.toml
43+
[dependencies]
44+
rinja = { version = "0.3.5", default-features = false, features = ["std"] }
45+
rinja_derive = { version = "0.3.5", features = ["std"] }
46+
```
47+
48+
```rust
49+
// lib.rs
50+
use rinja::Template as _;
51+
use rinja_derive::Template;
52+
```
53+
54+
The script uses [hyperfine](https://crates.io/crates/hyperfine).
55+
Install it with `cargo install hyperfine`.

bench-build/_typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../_typos.toml

bench-build/clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../clippy.toml

bench-build/deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../deny.toml

bench-build/run.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
cd "$(dirname "${BASH_SOURCE[0]}")"
4+
5+
mkdir -p target
6+
hyperfine \
7+
--runs=3 \
8+
--warmup=1 \
9+
--prepare='rm -r target' \
10+
'cargo run --features=derive' \
11+
'cargo run'
12+
echo
13+
echo ----------
14+
echo
15+
hyperfine \
16+
--runs=3 \
17+
--warmup=1 \
18+
--prepare='rm -r target' \
19+
'cargo run --release --features=derive' \
20+
'cargo run --release'

0 commit comments

Comments
 (0)