File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -999,18 +999,37 @@ mod tests {
999
999
1000
1000
#[ cfg( all( test, feature = "unstable" ) ) ]
1001
1001
mod benches {
1002
- use rand:: { Rng , thread_rng } ;
1002
+ use rand:: { thread_rng , RngCore } ;
1003
1003
use test:: { Bencher , black_box} ;
1004
1004
1005
1005
use super :: { Secp256k1 , Message } ;
1006
1006
1007
1007
#[ bench]
1008
1008
pub fn generate ( bh : & mut Bencher ) {
1009
- struct CounterRng ( u32 ) ;
1010
- impl Rng for CounterRng {
1011
- fn next_u32 ( & mut self ) -> u32 { self . 0 += 1 ; self . 0 }
1009
+ struct CounterRng ( u64 ) ;
1010
+ impl RngCore for CounterRng {
1011
+ fn next_u32 ( & mut self ) -> u32 {
1012
+ self . next_u64 ( ) as u32
1013
+ }
1014
+
1015
+ fn next_u64 ( & mut self ) -> u64 {
1016
+ self . 0 += 1 ;
1017
+ self . 0
1018
+ }
1019
+
1020
+ fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
1021
+ for chunk in dest. chunks_mut ( 64 /8 ) {
1022
+ let rand: [ u8 ; 64 /8 ] = unsafe { std:: mem:: transmute ( self . next_u64 ( ) ) } ;
1023
+ chunk. copy_from_slice ( & rand[ ..chunk. len ( ) ] ) ;
1024
+ }
1025
+ }
1026
+
1027
+ fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , rand:: Error > {
1028
+ Ok ( self . fill_bytes ( dest) )
1029
+ }
1012
1030
}
1013
1031
1032
+
1014
1033
let s = Secp256k1 :: new ( ) ;
1015
1034
let mut r = CounterRng ( 0 ) ;
1016
1035
bh. iter ( || {
You can’t perform that action at this time.
0 commit comments