Skip to content
Snippets Groups Projects
Commit 22f7943d authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

migrate recoding benchmark to PLNK (dragoon/komodo!89)

this MR
- moves the last "recoding" benchmark to `examples/benches/`
- moves the README, which is now all alone, to `examples/benches/`
- adds a mention to `examples/benches/README.md` in `README.md`
- some minor improvements to the bench README

## TODO
- [x] find a way to plot the "recoding" results (thanks to !90)
parent b3449155
No related branches found
No related tags found
No related merge requests found
...@@ -51,10 +51,6 @@ ark-secq256k1 = "0.4.0" ...@@ -51,10 +51,6 @@ ark-secq256k1 = "0.4.0"
ark-vesta = "0.4.0" ark-vesta = "0.4.0"
criterion = "0.3" criterion = "0.3"
[[bench]]
name = "recoding"
harness = false
[[example]] [[example]]
name = "bench_commit" name = "bench_commit"
path = "examples/benches/commit.rs" path = "examples/benches/commit.rs"
...@@ -78,3 +74,7 @@ path = "examples/benches/setup.rs" ...@@ -78,3 +74,7 @@ path = "examples/benches/setup.rs"
[[example]] [[example]]
name = "bench_linalg" name = "bench_linalg"
path = "examples/benches/linalg.rs" path = "examples/benches/linalg.rs"
[[example]]
name = "bench_recoding"
path = "examples/benches/recoding.rs"
...@@ -19,3 +19,6 @@ tests for the binary application can also be run with ...@@ -19,3 +19,6 @@ tests for the binary application can also be run with
```bash ```bash
nu tests/cli.nu nu tests/cli.nu
``` ```
## the benchmarks
see [the `README`](examples/benches/README.md)
```nushell ```nushell
use scripts/math.nu * use scripts/math.nu *
use scripts/formats.nu *
``` ```
## atomic operations ## atomic operations
...@@ -62,9 +63,8 @@ for graph in [ ...@@ -62,9 +63,8 @@ for graph in [
( (
$linalg $linalg
| where op == $graph.op | where op == $graph.op
| rename --column { n: "x", name: "curve", mean: "measurement", stddev: "error" } | rename --column { n: "x", mean: "measurement", stddev: "error" }
| group-by curve --to-table | group-by name --to-table
| update items { reject curve }
| to json | to json
) )
] ]
...@@ -86,15 +86,14 @@ python scripts/plot/plot.py ...[ ...@@ -86,15 +86,14 @@ python scripts/plot/plot.py ...[
| ns-to-ms $.times | ns-to-ms $.times
| compute-stats $.times | compute-stats $.times
| insert degree { get label | parse "degree {d}" | into record | get d | into int} | insert degree { get label | parse "degree {d}" | into record | get d | into int}
| insert curve {|it| if ($it.name | str starts-with "ARK") { | update name {|it| if ($it.name | str starts-with "ARK") {
let c = $it.name | parse "ARK setup on {curve}" | into record | get curve let c = $it.name | parse "ARK setup on {curve}" | into record | get curve
$"($c)-ark" $"($c)-ark"
} else { } else {
$it.name | parse "setup on {curve}" | into record | get curve $it.name | parse "setup on {curve}" | into record | get curve
}} }}
| rename --column { degree: "x", mean: "measurement", stddev: "error" } | rename --column { degree: "x", mean: "measurement", stddev: "error" }
| group-by curve --to-table | group-by name --to-table
| update items { reject curve }
| to json | to json
) )
] ]
...@@ -114,11 +113,52 @@ python scripts/plot/plot.py ...[ ...@@ -114,11 +113,52 @@ python scripts/plot/plot.py ...[
open commit.ndjson open commit.ndjson
| ns-to-ms $.times | ns-to-ms $.times
| compute-stats $.times | compute-stats $.times
| update label { parse "degree {d}" | into record | get d | into int } | insert degree { get label | parse "degree {d}" | into record | get d | into int }
| rename --column { label: "x", name: "curve", mean: "measurement", stddev: "error" } | rename --column { degree: "x", mean: "measurement", stddev: "error" }
| group-by curve --to-table | group-by name --to-table
| update items { reject curve }
| to json | to json
) )
] ]
``` ```
## end-to-end benchmarks
### recoding
```nushell
cargo run --example bench_recoding -- ...[
--nb-measurements 10
...[1, 1_024, (1_024 * 1_024)]
--shards ...[2, 4, 8, 16]
--ks ...[2, 4, 8, 16]
] | from ndnuon | to ndjson out> recoding.ndjson
```
```nushell
python scripts/plot/plot.py --title "recoding with k = 4" (
open recoding.ndjson
| ns-to-ms $.times
| compute-stats $.times
| update label { from nuon }
| flatten --all label
| insert case { $"($in.name) / ($in.shards)" }
| where k == 4 # $k$ has a negligible influence on _recoding_
| rename --column { bytes: "x", mean: "measurement", stddev: "error" }
| group-by case --to-table
| insert style {|it|
let g = $it.group | parse "{c} / {s}" | into record | into int s
let c = match $g.c {
"BLS-12-381" => "blue"
"BN-254" => "orange"
"PALLAS" => "green"
_ => "gray"
}
let t = match $g.s {
2 => "dotted"
4 => "dashdot"
8 => "dashed"
16 => "solid"
_ => { color: "loosely dotted" }
}
{ color: $c, line: { type: $t } }
}
| to json
)
```
// see `benches/README.md` // see `benches/README.md`
use std::time::Duration;
use ark_ff::PrimeField; use ark_ff::PrimeField;
use ark_std::rand::Rng; use ark_std::rand::Rng;
use criterion::{criterion_group, criterion_main, Criterion}; use clap::{arg, command, Parser};
use komodo::{ use komodo::{
fec::{recode_with_coeffs, Shard}, fec::{recode_with_coeffs, Shard},
field, field,
}; };
use plnk::Bencher;
fn to_curve<F: PrimeField>(n: u128) -> F { fn to_curve<F: PrimeField>(n: u128) -> F {
F::from_le_bytes_mod_order(&n.to_le_bytes()) F::from_le_bytes_mod_order(&n.to_le_bytes())
...@@ -30,13 +28,7 @@ fn create_fake_shard<F: PrimeField>(nb_bytes: usize, k: usize) -> Shard<F> { ...@@ -30,13 +28,7 @@ fn create_fake_shard<F: PrimeField>(nb_bytes: usize, k: usize) -> Shard<F> {
} }
} }
fn bench_template<F: PrimeField>( fn bench_template<F: PrimeField>(b: &Bencher, nb_bytes: usize, k: usize, nb_shards: usize) {
c: &mut Criterion,
nb_bytes: usize,
k: usize,
nb_shards: usize,
curve: &str,
) {
let shards: Vec<Shard<F>> = (0..nb_shards) let shards: Vec<Shard<F>> = (0..nb_shards)
.map(|_| create_fake_shard(nb_bytes, k)) .map(|_| create_fake_shard(nb_bytes, k))
.collect(); .collect();
...@@ -46,32 +38,46 @@ fn bench_template<F: PrimeField>( ...@@ -46,32 +38,46 @@ fn bench_template<F: PrimeField>(
.map(|_| to_curve::<F>(rng.gen::<u128>())) .map(|_| to_curve::<F>(rng.gen::<u128>()))
.collect(); .collect();
c.bench_function( plnk::bench(
b,
&format!( &format!(
"recoding {} bytes and {} shards with k = {} on {}", r#"{{"bytes": {}, "shards": {}, "k": {}}}"#,
nb_bytes, nb_shards, k, curve nb_bytes, nb_shards, k
), ),
|b| b.iter(|| recode_with_coeffs(&shards, &coeffs)), || plnk::timeit(|| recode_with_coeffs(&shards, &coeffs)),
); );
} }
fn criterion_benchmark(c: &mut Criterion) { #[derive(Parser)]
for nb_bytes in [1, 1_024, 1_024 * 1_024] { #[command(version, about, long_about = None)]
for nb_shards in [2, 4, 8, 16] { struct Cli {
for k in [2, 4, 8, 16] { #[arg(num_args = 1.., value_delimiter = ' ')]
bench_template::<ark_bls12_381::Fr>(c, nb_bytes, k, nb_shards, "BLS-12-381"); bytes: Vec<usize>,
bench_template::<ark_bn254::Fr>(c, nb_bytes, k, nb_shards, "BN-254");
bench_template::<ark_pallas::Fr>(c, nb_bytes, k, nb_shards, "PALLAS"); #[arg(short, long, num_args = 1.., value_delimiter = ' ')]
shards: Vec<usize>,
#[arg(short, long, num_args = 1.., value_delimiter = ' ')]
ks: Vec<usize>,
/// the number of measurements to repeat each case, larger values will reduce the variance of
/// the measurements
#[arg(short, long)]
nb_measurements: usize,
}
fn main() {
let cli = Cli::parse();
let bencher = plnk::Bencher::new(cli.nb_measurements);
for b in cli.bytes {
for s in &cli.shards {
for k in &cli.ks {
bench_template::<ark_bls12_381::Fr>(&bencher.with_name("BLS-12-381"), b, *k, *s);
bench_template::<ark_bn254::Fr>(&bencher.with_name("BN-254"), b, *k, *s);
bench_template::<ark_pallas::Fr>(&bencher.with_name("PALLAS"), b, *k, *s);
} }
} }
} }
} }
criterion_group!(
name = benches;
config = Criterion::default()
.warm_up_time(Duration::from_secs_f32(0.5))
.sample_size(10);
targets = criterion_benchmark
);
criterion_main!(benches);
export def "from ndnuon" []: [string -> any] {
lines | each { from nuon }
}
export def "to ndnuon" []: [any -> string] {
each { to nuon --raw } | to text
}
export def "from nuonl" []: [string -> any] {
from ndnuon
}
export def "to nuonl" []: [any -> string] {
to ndnuon
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment