-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2788 from Conflux-Chain/v2.0-stable-merge
Release v2.3.4.
- Loading branch information
Showing
95 changed files
with
7,820 additions
and
2,233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
extern crate cfx_types; | ||
extern crate criterion; | ||
extern crate rand; | ||
extern crate rand_xorshift; | ||
|
||
use cfx_types::U256; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::{Rng, SeedableRng}; | ||
use rand_xorshift::XorShiftRng; | ||
|
||
fn bench_random_input(c: &mut Criterion) { | ||
c.bench_function("u64 input gen", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u64>()); | ||
}); | ||
|
||
c.bench_function("u128 input gen", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>()); | ||
}); | ||
|
||
c.bench_function("u256 input gen", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| U256(rng.gen())); | ||
}); | ||
} | ||
|
||
fn bench_u256_basic_op(c: &mut Criterion) { | ||
c.bench_function("u256 / u256", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| U256(rng.gen()) / (U256(rng.gen()) >> 64)); | ||
}); | ||
|
||
c.bench_function("u256 / u64", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| U256(rng.gen()) / rng.gen::<u64>()); | ||
}); | ||
|
||
c.bench_function("u256 small quo (4 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| U256(rng.gen()) / (U256(rng.gen()) >> 4)); | ||
}); | ||
|
||
c.bench_function("u256 small quo (2 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| U256(rng.gen()) / (U256(rng.gen()) >> 2)); | ||
}); | ||
|
||
c.bench_function("u256 small quo (0 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| { | ||
let a = U256(rng.gen()); | ||
(a >> 1) / a | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_u128_basic_op(c: &mut Criterion) { | ||
c.bench_function("u128 / u128", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>() / (rng.gen::<u128>() >> 32)); | ||
}); | ||
|
||
c.bench_function("u128 / u64", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>() / rng.gen::<u64>() as u128); | ||
}); | ||
|
||
c.bench_function("u128 small quo (4 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>() / (rng.gen::<u128>() >> 4)); | ||
}); | ||
|
||
c.bench_function("u128 small quo (2 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>() / (rng.gen::<u128>() >> 2)); | ||
}); | ||
|
||
c.bench_function("u128 small quo (0 bit)", move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| { | ||
let a = rng.gen::<u128>(); | ||
(a >> 1) / a | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_random_input, | ||
bench_u128_basic_op, | ||
bench_u256_basic_op | ||
); | ||
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,107 @@ | ||
extern crate cfx_math; | ||
extern crate cfx_types; | ||
extern crate criterion; | ||
extern crate num; | ||
extern crate rand; | ||
extern crate rand_xorshift; | ||
extern crate typenum; | ||
|
||
use cfx_math::{ | ||
nth_inv_root, | ||
nth_root::{nth_root, RootDegree, RootInvParams}, | ||
}; | ||
use cfx_types::U256; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use num::integer::Roots; | ||
use rand::{Rng, SeedableRng}; | ||
use rand_xorshift::XorShiftRng; | ||
|
||
fn bench_nth_root<N: RootDegree>(c: &mut Criterion) { | ||
c.bench_function(&format!("u64 {}-th root", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| nth_root::<N, u64>(rng.gen())); | ||
}); | ||
|
||
c.bench_function(&format!("u64 {}-th baseline", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u64>().nth_root(N::U32)); | ||
}); | ||
|
||
c.bench_function(&format!("u128 {}-th root", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| nth_root::<N, u128>(rng.gen())); | ||
}); | ||
c.bench_function(&format!("u128 {}-th baseline", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| rng.gen::<u128>().nth_root(N::U32)); | ||
}); | ||
|
||
c.bench_function(&format!("u192 {}-th root", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| nth_root::<N, U256>(U256(rng.gen()) >> 64)); | ||
}); | ||
|
||
c.bench_function(&format!("u256 {}-th root", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| nth_root::<N, U256>(U256(rng.gen()))); | ||
}); | ||
} | ||
|
||
fn bench_nth_inv_root<N: RootDegree>(c: &mut Criterion) | ||
where | ||
(N, typenum::U10): RootInvParams, | ||
(N, typenum::U15): RootInvParams, | ||
(N, typenum::U20): RootInvParams, | ||
{ | ||
c.bench_function(&format!("{}-th inv root (10 bit)", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| { | ||
nth_inv_root::<N, typenum::U10>(U256::from(rng.gen::<u64>())) | ||
}); | ||
}); | ||
|
||
c.bench_function(&format!("{}-th inv root (15 bit)", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| { | ||
nth_inv_root::<N, typenum::U15>(U256::from(rng.gen::<u64>())) | ||
}); | ||
}); | ||
|
||
c.bench_function(&format!("{}-th inv root (20 bit)", N::USIZE), move |b| { | ||
let mut rng = XorShiftRng::from_seed([0u8; 16]); | ||
b.iter(|| { | ||
nth_inv_root::<N, typenum::U20>(U256::from(rng.gen::<u64>())) | ||
}); | ||
}); | ||
} | ||
|
||
fn bench_multiple_nth_root(c: &mut Criterion) { | ||
bench_nth_root::<typenum::U2>(c); | ||
bench_nth_root::<typenum::U3>(c); | ||
bench_nth_root::<typenum::U4>(c); | ||
bench_nth_root::<typenum::U5>(c); | ||
bench_nth_root::<typenum::U8>(c); | ||
bench_nth_root::<typenum::U10>(c); | ||
bench_nth_root::<typenum::U12>(c); | ||
|
||
// c.bench_function(&format!("u256 another sqrt"), move |b| { | ||
// b.iter(|| cfx_math::sqrt_u256(U256(rand::random::<[u64; 4]>()))); | ||
// }); | ||
} | ||
|
||
fn bench_multiple_nth_inv_root(c: &mut Criterion) { | ||
bench_nth_inv_root::<typenum::U2>(c); | ||
bench_nth_inv_root::<typenum::U3>(c); | ||
bench_nth_inv_root::<typenum::U4>(c); | ||
bench_nth_inv_root::<typenum::U5>(c); | ||
bench_nth_inv_root::<typenum::U8>(c); | ||
bench_nth_inv_root::<typenum::U10>(c); | ||
bench_nth_inv_root::<typenum::U12>(c); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_multiple_nth_inv_root, | ||
bench_multiple_nth_root | ||
); | ||
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
Oops, something went wrong.