@@ -2,9 +2,12 @@ use base62::{
22 decode, decode_alternative, encode, encode_alternative, encode_alternative_buf,
33 encode_alternative_bytes, encode_buf, encode_bytes,
44} ;
5- use criterion:: { black_box, criterion_group, criterion_main, BatchSize , Criterion } ;
6- use rand:: distributions:: Standard ;
7- use rand:: { thread_rng, Rng } ;
5+
6+ use std:: hint:: black_box;
7+
8+ use criterion:: { criterion_group, criterion_main, BatchSize , Criterion } ;
9+ use rand:: distr:: StandardUniform ;
10+ use rand:: { rng, Rng } ;
811
912pub fn criterion_benchmark ( c : & mut Criterion ) {
1013 let mut group = c. benchmark_group ( "decode" ) ;
@@ -19,7 +22,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
1922 b. iter_batched (
2023 || {
2124 // Setup (runs outside measured time)
22- let random_num: u128 = thread_rng ( ) . sample ( Standard ) ;
25+ let random_num: u128 = rng ( ) . sample ( StandardUniform ) ;
2326 encode ( random_num)
2427 } ,
2528 decode, // Measured function
@@ -35,7 +38,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
3538 b. iter_batched (
3639 || {
3740 // Setup (runs outside measured time)
38- let random_num: u128 = thread_rng ( ) . sample ( Standard ) ;
41+ let random_num: u128 = rng ( ) . sample ( StandardUniform ) ;
3942 encode_alternative ( random_num)
4043 } ,
4144 decode_alternative,
@@ -52,15 +55,15 @@ pub fn criterion_benchmark(c: &mut Criterion) {
5255
5356 group. bench_function ( "standard_new_random" , |b| {
5457 b. iter_batched (
55- || thread_rng ( ) . sample ( Standard ) ,
58+ || rng ( ) . sample ( StandardUniform ) ,
5659 |num : u128 | encode ( black_box ( num) ) ,
5760 BatchSize :: SmallInput ,
5861 )
5962 } ) ;
6063
6164 group. bench_function ( "standard_new_random_u64" , |b| {
6265 b. iter_batched (
63- || thread_rng ( ) . sample ( Standard ) ,
66+ || rng ( ) . sample ( StandardUniform ) ,
6467 |num : u64 | encode ( black_box ( num) ) ,
6568 BatchSize :: SmallInput ,
6669 )
@@ -73,7 +76,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
7376
7477 group. bench_function ( "standard_bytes_random" , |b| {
7578 b. iter_batched (
76- || thread_rng ( ) . sample ( Standard ) ,
79+ || rng ( ) . sample ( StandardUniform ) ,
7780 |num : u128 | {
7881 let mut buf = [ 0 ; 22 ] ;
7982 encode_bytes ( black_box ( num) , black_box ( & mut buf) )
@@ -84,7 +87,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
8487
8588 group. bench_function ( "standard_bytes_random_u64" , |b| {
8689 b. iter_batched (
87- || thread_rng ( ) . sample ( Standard ) ,
90+ || rng ( ) . sample ( StandardUniform ) ,
8891 |num : u64 | {
8992 let mut buf = [ 0 ; 22 ] ;
9093 encode_bytes ( black_box ( num) , black_box ( & mut buf) )
@@ -100,7 +103,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
100103 group. bench_function ( "standard_buf_random" , |b| {
101104 b. iter_batched_ref (
102105 || {
103- let num: u128 = thread_rng ( ) . sample ( Standard ) ;
106+ let num: u128 = rng ( ) . sample ( StandardUniform ) ;
104107 ( num, String :: with_capacity ( 22 ) )
105108 } ,
106109 |( num, buf) | {
@@ -114,7 +117,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
114117 group. bench_function ( "standard_buf_random_u64" , |b| {
115118 b. iter_batched_ref (
116119 || {
117- let num: u64 = thread_rng ( ) . sample ( Standard ) ;
120+ let num: u64 = rng ( ) . sample ( StandardUniform ) ;
118121 ( num, String :: with_capacity ( 11 ) )
119122 } ,
120123 |( num, buf) | {
@@ -131,15 +134,15 @@ pub fn criterion_benchmark(c: &mut Criterion) {
131134
132135 group. bench_function ( "alternative_new_random" , |b| {
133136 b. iter_batched (
134- || thread_rng ( ) . sample ( Standard ) ,
137+ || rng ( ) . sample ( StandardUniform ) ,
135138 |num : u128 | encode_alternative ( black_box ( num) ) ,
136139 BatchSize :: SmallInput ,
137140 )
138141 } ) ;
139142
140143 group. bench_function ( "alternative_new_random_u64" , |b| {
141144 b. iter_batched (
142- || thread_rng ( ) . sample ( Standard ) ,
145+ || rng ( ) . sample ( StandardUniform ) ,
143146 |num : u64 | encode_alternative ( black_box ( num) ) ,
144147 BatchSize :: SmallInput ,
145148 )
@@ -152,7 +155,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
152155
153156 group. bench_function ( "alternative_bytes_random" , |b| {
154157 b. iter_batched (
155- || thread_rng ( ) . sample ( Standard ) ,
158+ || rng ( ) . sample ( StandardUniform ) ,
156159 |num : u128 | {
157160 let mut buf = [ 0 ; 22 ] ;
158161 encode_alternative_bytes ( black_box ( num) , black_box ( & mut buf) )
@@ -163,7 +166,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
163166
164167 group. bench_function ( "alternative_bytes_random_u64" , |b| {
165168 b. iter_batched (
166- || thread_rng ( ) . sample ( Standard ) ,
169+ || rng ( ) . sample ( StandardUniform ) ,
167170 |num : u64 | {
168171 let mut buf = [ 0 ; 11 ] ;
169172 encode_alternative_bytes ( black_box ( num) , black_box ( & mut buf) )
@@ -179,7 +182,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
179182 group. bench_function ( "alternative_buf_random" , |b| {
180183 b. iter_batched_ref (
181184 || {
182- let num: u128 = thread_rng ( ) . sample ( Standard ) ;
185+ let num: u128 = rng ( ) . sample ( StandardUniform ) ;
183186 ( num, String :: with_capacity ( 22 ) )
184187 } ,
185188 |( num, buf) | {
@@ -193,7 +196,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
193196 group. bench_function ( "alternative_buf_random_u64" , |b| {
194197 b. iter_batched_ref (
195198 || {
196- let num: u64 = thread_rng ( ) . sample ( Standard ) ;
199+ let num: u64 = rng ( ) . sample ( StandardUniform ) ;
197200 ( num, String :: with_capacity ( 11 ) )
198201 } ,
199202 |( num, buf) | {
0 commit comments