forked from nucypher/ferveo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
panicks at 'capacity overflow' during js-benches
- Loading branch information
1 parent
5573895
commit 2958e93
Showing
10 changed files
with
155 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
**/*.rs.bk | ||
Cargo.lock | ||
bin/ | ||
pkg/ | ||
pkg | ||
wasm-pack.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Benchmarks | ||
|
||
## Benchmarking WASM | ||
|
||
This time we may not use [`centurion.rs`](https://github.com/bheisler/criterion.rs/blob/version-0.4/book/src/user_guide/wasi.md#webasseblywasi-benchmarking) because `wasm32-wasi` is incompatible with `wasm_bindgen` ([1](https://github.com/rustwasm/wasm-bindgen/issues/2554), [2](https://github.com/bevyengine/bevy/discussions/5908?sort=new)). Instead, we're going to measure performance directly in the browser. | ||
|
||
### Setup | ||
|
||
```bash | ||
wasm-pack build --release --target web | ||
|
||
cd js-benches | ||
ln -s ../pkg . | ||
``` | ||
|
||
### Running | ||
|
||
```bash | ||
npx http-server | ||
# Visit localhost:8080/index.html | ||
``` | ||
|
||
## Benchmarking Rust | ||
|
||
```bash | ||
cargo bench | ||
``` | ||
|
||
## Results | ||
|
||
### WASM Results | ||
|
||
``` | ||
``` | ||
|
||
### Rust Results | ||
|
||
``` | ||
TPKE-WASM/tpke-wasm::encrypt - num_shares=8, num_entities=8, threshold=8 | ||
time: [4.8427 ms 4.9178 ms 5.0113 ms] | ||
Found 2 outliers among 10 measurements (20.00%) | ||
2 (20.00%) high mild | ||
TPKE-WASM/tpke-wasm::encrypt - num_shares=16, num_entities=16, threshold=16 | ||
time: [4.8967 ms 4.9732 ms 5.1114 ms] | ||
Found 1 outliers among 10 measurements (10.00%) | ||
1 (10.00%) high mild | ||
TPKE-WASM/tpke-wasm::encrypt - num_shares=32, num_entities=32, threshold=32 | ||
time: [4.8219 ms 5.0377 ms 5.3367 ms] | ||
Found 1 outliers among 10 measurements (10.00%) | ||
1 (10.00%) high severe | ||
TPKE-WASM/tpke-wasm::encrypt - num_shares=64, num_entities=64, threshold=64 | ||
time: [4.8865 ms 4.9192 ms 4.9529 ms] | ||
TPKE-WASM/tpke-wasm::encrypt - num_shares=128, num_entities=128, threshold=128 | ||
time: [4.8900 ms 4.9389 ms 4.9834 ms] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
pub fn bench_encrypt_combine(c: &mut Criterion) { | ||
fn encrypt_bench( | ||
num_shares: usize, | ||
num_entities: usize, | ||
threshold: usize, | ||
) -> impl Fn() { | ||
let message = "my-secret-message".as_bytes().to_vec(); | ||
let setup = tpke_wasm::Setup::new(threshold, num_shares, num_entities); | ||
move || { | ||
let message = message.clone(); | ||
black_box(tpke_wasm::encrypt(message, setup.public_key)); | ||
} | ||
} | ||
|
||
let mut group = c.benchmark_group("TPKE-WASM"); | ||
group.sample_size(10); | ||
|
||
for num_shares in [8, 16, 32, 64, 128].iter() { | ||
let a = encrypt_bench(*num_shares, *num_shares, *num_shares); | ||
group.measurement_time(core::time::Duration::new(30, 0)); | ||
group.bench_function(format!("tpke-wasm::encrypt - num_shares={}, num_entities={}, threshold={}", num_shares, num_shares, num_shares), |b| { | ||
b.iter(|| a()) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_encrypt_combine); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>TPKE benchmark</title> | ||
<script type="module" src="./index.js"></script> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import init from "./pkg/tpke_wasm.js"; | ||
import { Setup } from "./pkg/tpke_wasm.js"; | ||
|
||
const runBenchmarks = async () => { | ||
console.log("Initializing ..."); | ||
|
||
const setup = new Setup(); | ||
|
||
console.log("Setup: ", setup); | ||
|
||
console.log("Done!"); | ||
}; | ||
|
||
init() | ||
.then(runBenchmarks) | ||
.catch((err) => console.error(err)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters