Skip to content

Commit

Permalink
Refactor benchmarks (#161)
Browse files Browse the repository at this point in the history
Revamped benchmarks:

- Benchmarks no longer run any code outside of bench_function block
- Using latticefold/benches/config.toml to run benchmarks
- No macros used in benchmarks
- Using build.rs to generate benchmarks code from
latticefold/benches/config.toml
  • Loading branch information
cupicmarko authored Dec 23, 2024
1 parent 25df352 commit 71debaf
Show file tree
Hide file tree
Showing 14 changed files with 2,527 additions and 2,627 deletions.
67 changes: 67 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions latticefold/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ thiserror = { workspace = true }
num-bigint = { workspace = true }
rayon = { version = "1.10.0", optional = true }


[build-dependencies]
serde = { version = "1.0.216", features = ["derive"] }
toml = "0.8.19"
quote = "1.0.37"
proc-macro2 = "1.0.92"

[features]
default = [ "std" ]
std = [ "ark-std/std", "cyclotomic-rings/std", "rand/std" ]
Expand All @@ -40,6 +47,12 @@ dhat-heap = []
[profile.release]
debug = 1

[profile.bench]
lto = false
codegen-units = 16
opt-level = 3
rpath = true

[lints.clippy]
single_match = "warn"
single_match_else = "warn"
Expand All @@ -60,6 +73,7 @@ implicit_clone = "warn"
criterion = "0.5.1"
dhat = "0.3.2"
humansize = "2.1.3"
lazy_static = "1.5.0"

[[bench]]
name = "ajtai"
Expand All @@ -69,10 +83,12 @@ harness = false
name = "linearization"
harness = false


[[bench]]
name = "decomposition"
harness = false


[[bench]]
name = "folding"
harness = false
Expand Down
96 changes: 96 additions & 0 deletions latticefold/benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Benchmarking with Environment Variables

This benchmark suite allows users to selectively enable or disable certain benchmarks using environment variables. By leveraging environment variables, users can tailor the benchmark runs to specific configurations.

---

## Environment Variables

The following environment variables can be set to **enable or filter benchmarks**:

### Boolean Flags (Enable/Disable Filtering)
- `GOLDILOCKS`
- `STARK`
- `BABYBEAR`
- `FROG`

- `PROVER`
- `VERIFIER`
- `AJTAI`

- `LINEARIZATION`
- `DECOMPOSITION`
- `FOLDING`
- `E2E`

> **Default Behavior**:
If none of the flags for a group are set, all flags are enabled by default.

### Optional Variables (Numeric Values)
The following variables control specific parameters for benchmarks. If not set, they will be ignored:
- `DURATION` (default: `50.0` seconds as floating point number) – Duration for benchmarks
- `WARMUP` (default: `1.0` seconds as floating point number) – Warmup time

---

## How It Works
- If none of `LINEARIZATION`, `DECOMPOSITION`, `FOLDING`, and `E2E` is set, all benchmarks would be run.
- If some of them is set, only set benchmarks would be run.
- Similarly, if none of `PROVER`, `VERIFIER` and `AJTAI` is set, all benchmarks would be run, otherwise,
only set benchmarks would be run.
- `GOLDILOCKS`, `STARK`, `BABYBEAR` and `FROG` are used similarly.

---

## Examples

### **Bash**

1. **Run only `LINEARIZATION` benchmarks:**
```bash
LINEARIZATION=1 cargo bench
```

2. **Run only `PROVER` `DECOMPOSITION` benchmarks:**
```bash
PROVER=1 DECOMPOSITION=1 cargo bench
```

3. **Run benchmarks matching specific parameters for GOLDILOCKS ring:**
```bash
KAPPA=10 GOLDILOCKS=1 L=8 GOLDILOCKS=1 cargo bench
```

---

### **PowerShell**
1. **Run only `LINEARIZATION` benchmarks:**
```powershell
$env:LINEARIZATION=1; cargo bench
```

2. **Run only `PROVER` `DECOMPOSITION` benchmarks:**
```powershell
$env:PROVER=1; $env:DECOMPOSITION=1; cargo bench
```

3. **Run benchmarks matching specific parameters for GOLDILOCKS ring:**
```powershell
$env:KAPPA=10; $env:GOLDILOCKS=1; $env:L=8; $env:GOLDILOCKS=1; cargo bench
```

---

## Numeric Parameters

Numeric parameters can be used to filter benchmarks, if they are set they only benchmarks with matching parameter would be run

- X_LEN
- KAPPA
- W
- WIT_LEN
- B
- L
- B_SMALL
- K

Loading

0 comments on commit 71debaf

Please sign in to comment.