11use core:: num:: NonZeroU32 ;
22
33use criterion:: { criterion_group, criterion_main, BatchSize , Criterion } ;
4- use crypto_bigint:: { nlimbs, Integer , Odd , RandomBits , Uint , U1024 } ;
4+ use crypto_bigint:: { nlimbs, Integer , Odd , RandomBits , Uint , U1024 , U128 , U256 } ;
55use rand_chacha:: ChaCha8Rng ;
66use rand_core:: { CryptoRngCore , OsRng , SeedableRng } ;
77
@@ -45,12 +45,12 @@ fn bench_sieve(c: &mut Criterion) {
4545 let mut group = c. benchmark_group ( "Sieve" ) ;
4646
4747 group. bench_function ( "(U128) random start" , |b| {
48- b. iter ( || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) )
48+ b. iter ( || random_odd_uint :: < U128 > ( & mut OsRng , 128 ) )
4949 } ) ;
5050
5151 group. bench_function ( "(U128) creation" , |b| {
5252 b. iter_batched (
53- || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
53+ || random_odd_uint :: < U128 > ( & mut OsRng , 128 ) ,
5454 |start| Sieve :: new ( start. as_ref ( ) , NonZeroU32 :: new ( 128 ) . unwrap ( ) , false ) ,
5555 BatchSize :: SmallInput ,
5656 )
@@ -66,12 +66,12 @@ fn bench_sieve(c: &mut Criterion) {
6666 } ) ;
6767
6868 group. bench_function ( "(U1024) random start" , |b| {
69- b. iter ( || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) )
69+ b. iter ( || random_odd_uint :: < U1024 > ( & mut OsRng , 1024 ) )
7070 } ) ;
7171
7272 group. bench_function ( "(U1024) creation" , |b| {
7373 b. iter_batched (
74- || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) ,
74+ || random_odd_uint :: < U1024 > ( & mut OsRng , 1024 ) ,
7575 |start| Sieve :: new ( start. as_ref ( ) , NonZeroU32 :: new ( 1024 ) . unwrap ( ) , false ) ,
7676 BatchSize :: SmallInput ,
7777 )
@@ -93,7 +93,7 @@ fn bench_miller_rabin(c: &mut Criterion) {
9393
9494 group. bench_function ( "(U128) creation" , |b| {
9595 b. iter_batched (
96- || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
96+ || random_odd_uint :: < U128 > ( & mut OsRng , 128 ) ,
9797 MillerRabin :: new,
9898 BatchSize :: SmallInput ,
9999 )
@@ -109,7 +109,7 @@ fn bench_miller_rabin(c: &mut Criterion) {
109109
110110 group. bench_function ( "(U1024) creation" , |b| {
111111 b. iter_batched (
112- || random_odd_uint :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut OsRng , 1024 ) ,
112+ || random_odd_uint :: < U1024 > ( & mut OsRng , 1024 ) ,
113113 MillerRabin :: new,
114114 BatchSize :: SmallInput ,
115115 )
@@ -202,39 +202,39 @@ fn bench_presets(c: &mut Criterion) {
202202
203203 group. bench_function ( "(U128) Prime test" , |b| {
204204 b. iter_batched (
205- || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
205+ || random_odd_uint :: < U128 > ( & mut OsRng , 128 ) ,
206206 |num| is_prime_with_rng ( & mut OsRng , num. as_ref ( ) ) ,
207207 BatchSize :: SmallInput ,
208208 )
209209 } ) ;
210210
211211 group. bench_function ( "(U128) Safe prime test" , |b| {
212212 b. iter_batched (
213- || random_odd_uint :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut OsRng , 128 ) ,
213+ || random_odd_uint :: < U128 > ( & mut OsRng , 128 ) ,
214214 |num| is_safe_prime_with_rng ( & mut OsRng , num. as_ref ( ) ) ,
215215 BatchSize :: SmallInput ,
216216 )
217217 } ) ;
218218
219219 let mut rng = make_rng ( ) ;
220220 group. bench_function ( "(U128) Random prime" , |b| {
221- b. iter ( || generate_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
221+ b. iter ( || generate_prime_with_rng :: < U128 > ( & mut rng, 128 ) )
222222 } ) ;
223223
224224 let mut rng = make_rng ( ) ;
225225 group. bench_function ( "(U1024) Random prime" , |b| {
226- b. iter ( || generate_prime_with_rng :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut rng, 1024 ) )
226+ b. iter ( || generate_prime_with_rng :: < U1024 > ( & mut rng, 1024 ) )
227227 } ) ;
228228
229229 let mut rng = make_rng ( ) ;
230230 group. bench_function ( "(U128) Random safe prime" , |b| {
231- b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
231+ b. iter ( || generate_safe_prime_with_rng :: < U128 > ( & mut rng, 128 ) )
232232 } ) ;
233233
234234 group. sample_size ( 20 ) ;
235235 let mut rng = make_rng ( ) ;
236236 group. bench_function ( "(U1024) Random safe prime" , |b| {
237- b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 1024 ) } > > ( & mut rng, 1024 ) )
237+ b. iter ( || generate_safe_prime_with_rng :: < U1024 > ( & mut rng, 1024 ) )
238238 } ) ;
239239
240240 group. finish ( ) ;
@@ -244,19 +244,19 @@ fn bench_presets(c: &mut Criterion) {
244244
245245 let mut rng = make_rng ( ) ;
246246 group. bench_function ( "(U128) Random safe prime" , |b| {
247- b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 128 ) } > > ( & mut rng, 128 ) )
247+ b. iter ( || generate_safe_prime_with_rng :: < U128 > ( & mut rng, 128 ) )
248248 } ) ;
249249
250250 // The performance should scale with the prime size, not with the Uint size.
251251 // So we should strive for this test's result to be as close as possible
252252 // to that of the previous one and as far away as possible from the next one.
253253 group. bench_function ( "(U256) Random 128 bit safe prime" , |b| {
254- b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 256 ) } > > ( & mut rng, 128 ) )
254+ b. iter ( || generate_safe_prime_with_rng :: < U256 > ( & mut rng, 128 ) )
255255 } ) ;
256256
257257 // The upper bound for the previous test.
258258 group. bench_function ( "(U256) Random 256 bit safe prime" , |b| {
259- b. iter ( || generate_safe_prime_with_rng :: < Uint < { nlimbs ! ( 256 ) } > > ( & mut rng, 256 ) )
259+ b. iter ( || generate_safe_prime_with_rng :: < U256 > ( & mut rng, 256 ) )
260260 } ) ;
261261
262262 group. finish ( ) ;
0 commit comments