|
| 1 | +// Copyright 2015-2017 Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Parity. |
| 3 | + |
| 4 | +// Parity is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Parity is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Parity. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +#![feature(test)] |
| 18 | + |
| 19 | +extern crate test; |
| 20 | +extern crate ethcore_util as util; |
| 21 | +extern crate rand; |
| 22 | +extern crate bn; |
| 23 | + |
| 24 | +use self::test::{Bencher}; |
| 25 | +use rand::{StdRng}; |
| 26 | + |
| 27 | + |
| 28 | +#[bench] |
| 29 | +fn bn_128_pairing(b: &mut Bencher) { |
| 30 | + use bn::{pairing, G1, G2, Fr, Group}; |
| 31 | + |
| 32 | + let rng = &mut ::rand::thread_rng(); |
| 33 | + |
| 34 | + let sk0 = Fr::random(rng); |
| 35 | + let sk1 = Fr::random(rng); |
| 36 | + |
| 37 | + let pk0 = G1::one() * sk0; |
| 38 | + let pk1 = G2::one() * sk1; |
| 39 | + |
| 40 | + b.iter(|| { |
| 41 | + let _ = pairing(pk0, pk1); |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +#[bench] |
| 46 | +fn bn_128_mul(b: &mut Bencher) { |
| 47 | + use bn::{AffineG1, G1, Fr, Group}; |
| 48 | + |
| 49 | + let mut rng = StdRng::new().unwrap(); |
| 50 | + let p: G1 = G1::random(&mut rng); |
| 51 | + let fr = Fr::random(&mut rng); |
| 52 | + |
| 53 | + b.iter(|| { |
| 54 | + let _ = AffineG1::from_jacobian(p * fr); |
| 55 | + }); |
| 56 | +} |
| 57 | + |
0 commit comments