Files
RustySecrets/benches/thss.rs
Noah Vesely c25f661645 Rustfmt updates + refactor Travis configuration (#60)
* Update rustfmt compliance

Looks like rustfmt has made some improvements recently, so wanted to bring the
code up to date.

* Add rustfmt to nightly item in Travis matrix

* Use Travis Cargo cache

* Allow fast_finish in Travis

Items that match the `allow_failures` predicate (right now, just Rust nightly),
will still finish, but Travis won't wait for them to report a result if the
other builds have already finished.

* Run kcov in a separate matrix build in Travis

* Rework allowed_failures logic

We don't want rustfmt to match `allow_failures` just because it needs to use
nightly, while we do want nightly to match `allow_failures`. Env vars provide a
solution.

* Add --all switch to rustfmt Travis

* Test building docs in Travis

* Use exact Ubuntu dependencies listed for kcov

Some of the dependencies we were installing were not listed on
https://github.com/SimonKagstrom/kcov/blob/master/INSTALL.md, and we were
missing one dependency that was listed there. When `sudo: true` Travis uses
Ubuntu Trusty.

* No need to build before running kcov

kcov builds its own test executables.

* Generate `Cargo.lock` w/ `cargo update` before running kcov

As noted in aeb3906cce8e3e26c7bc80d6aec417b365f3d2f1 it is not necessary to
build the project before running kcov, but kcov does require a `Cargo.lock`
file, which can be generated with `cargo update`.
2018-08-13 21:29:39 +02:00

53 lines
1.4 KiB
Rust

#![cfg(test)]
#![feature(test)]
#![cfg(feature = "dss")]
extern crate rusty_secrets;
extern crate test;
mod shared;
mod thss {
use rusty_secrets::dss::thss;
use shared;
use test::{black_box, Bencher};
macro_rules! bench_generate {
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
b.iter(move || {
let shares = thss::split_secret($k, $n, &secret, &None).unwrap();
black_box(shares);
});
}
};
}
macro_rules! bench_recover {
($name:ident, $k:expr, $n:expr, $secret:ident) => {
#[bench]
fn $name(b: &mut Bencher) {
let secret = shared::$secret();
let all_shares = thss::split_secret($k, $n, &secret, &None).unwrap();
let shares = &all_shares.into_iter().take($k).collect::<Vec<_>>().clone();
b.iter(|| {
let result = thss::recover_secret(&shares.to_vec()).unwrap();
black_box(result);
});
}
};
}
bench_generate!(generate_1kb_3_5, 3, 5, secret_1kb);
bench_recover!(recover_1kb_3_5, 3, 5, secret_1kb);
bench_generate!(generate_1kb_10_25, 10, 25, secret_1kb);
bench_recover!(recover_1kb_10_25, 10, 25, secret_1kb);
}