use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use blstrs::*; use ff::Field; #[bench] fn bench_fp_add_assign(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec<(Fp, Fp)> = (0..SAMPLES) .map(|_| (Fp::random(&mut rng), Fp::random(&mut rng))) .collect(); let mut count = 0; b.iter(|| { let mut tmp = v[count].0; tmp += &v[count].1; count = (count + 1) % SAMPLES; tmp }); } #[bench] fn bench_fp_sub_assign(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec<(Fp, Fp)> = (0..SAMPLES) .map(|_| (Fp::random(&mut rng), Fp::random(&mut rng))) .collect(); let mut count = 0; b.iter(|| { let mut tmp = v[count].0; tmp -= &v[count].1; count = (count + 1) % SAMPLES; tmp }); } #[bench] fn bench_fp_mul_assign(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec<(Fp, Fp)> = (0..SAMPLES) .map(|_| (Fp::random(&mut rng), Fp::random(&mut rng))) .collect(); let mut count = 0; b.iter(|| { let mut tmp = v[count].0; tmp *= &v[count].1; count = (count + 1) % SAMPLES; tmp }); } #[bench] fn bench_fp_square(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec = (0..SAMPLES).map(|_| Fp::random(&mut rng)).collect(); let mut count = 0; b.iter(|| { let tmp = v[count].square(); count = (count + 1) % SAMPLES; tmp }); } #[bench] fn bench_fp_inverse(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec = (0..SAMPLES).map(|_| Fp::random(&mut rng)).collect(); let mut count = 0; b.iter(|| { count = (count + 1) % SAMPLES; v[count].invert() }); } #[bench] fn bench_fp_negate(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec = (0..SAMPLES).map(|_| Fp::random(&mut rng)).collect(); let mut count = 0; b.iter(|| { let tmp = -v[count]; count = (count + 1) % SAMPLES; tmp }); } #[bench] fn bench_fp_sqrt(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec = (0..SAMPLES) .map(|_| Fp::random(&mut rng).square()) .collect(); let mut count = 0; b.iter(|| { count = (count + 1) % SAMPLES; v[count].sqrt() }); } #[bench] fn bench_fp_to_bytes_le(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec = (0..SAMPLES).map(|_| Fp::random(&mut rng)).collect(); let mut count = 0; b.iter(|| { count = (count + 1) % SAMPLES; v[count].to_bytes_le() }); } #[bench] fn bench_fp_from_bytes_le(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; let mut rng = XorShiftRng::from_seed([ 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc, 0xe5, ]); let v: Vec<[u8; 48]> = (0..SAMPLES) .map(|_| Fp::random(&mut rng).to_bytes_le()) .collect(); let mut count = 0; b.iter(|| { count = (count + 1) % SAMPLES; Fp::from_bytes_le(&v[count]) }); }