@@ -104,6 +104,17 @@ fn read_hash_sync(c: &mut Criterion) {
104
104
} ) ;
105
105
}
106
106
107
+ fn read_hash_sync_xxh3 ( c : & mut Criterion ) {
108
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
109
+ let cache = tmp. path ( ) . to_owned ( ) ;
110
+ let data = b"hello world" . to_vec ( ) ;
111
+ let sri =
112
+ cacache:: write_sync_with_algo ( cacache:: Algorithm :: Xxh3 , & cache, "hello" , data) . unwrap ( ) ;
113
+ c. bench_function ( "get::data_hash_sync::xxh3" , move |b| {
114
+ b. iter ( || cacache:: read_hash_sync ( black_box ( & cache) , black_box ( & sri) ) . unwrap ( ) )
115
+ } ) ;
116
+ }
117
+
107
118
fn read_hash_many_sync ( c : & mut Criterion ) {
108
119
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
109
120
let cache = tmp. path ( ) . to_owned ( ) ;
@@ -124,6 +135,28 @@ fn read_hash_many_sync(c: &mut Criterion) {
124
135
} ) ;
125
136
}
126
137
138
+ fn read_hash_many_sync_xxh3 ( c : & mut Criterion ) {
139
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
140
+ let cache = tmp. path ( ) . to_owned ( ) ;
141
+ let data: Vec < _ > = ( 0 ..)
142
+ . take ( NUM_REPEATS )
143
+ . map ( |i| format ! ( "test_file_{i}" ) )
144
+ . collect ( ) ;
145
+ let sris: Vec < _ > = data
146
+ . iter ( )
147
+ . map ( |datum| {
148
+ cacache:: write_sync_with_algo ( cacache:: Algorithm :: Xxh3 , & cache, "hello" , datum) . unwrap ( )
149
+ } )
150
+ . collect ( ) ;
151
+ c. bench_function ( "get::data_hash_many_sync::xxh3" , move |b| {
152
+ b. iter ( || {
153
+ for sri in sris. iter ( ) {
154
+ cacache:: read_hash_sync ( black_box ( & cache) , black_box ( sri) ) . unwrap ( ) ;
155
+ }
156
+ } )
157
+ } ) ;
158
+ }
159
+
127
160
fn read_sync ( c : & mut Criterion ) {
128
161
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
129
162
let cache = tmp. path ( ) . to_owned ( ) ;
@@ -144,6 +177,17 @@ fn read_hash_sync_big_data(c: &mut Criterion) {
144
177
} ) ;
145
178
}
146
179
180
+ fn read_hash_sync_big_data_xxh3 ( c : & mut Criterion ) {
181
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
182
+ let cache = tmp. path ( ) . to_owned ( ) ;
183
+ let data = vec ! [ 1 ; 1024 * 1024 * 5 ] ;
184
+ let sri =
185
+ cacache:: write_sync_with_algo ( cacache:: Algorithm :: Xxh3 , & cache, "hello" , data) . unwrap ( ) ;
186
+ c. bench_function ( "get_hash_big_data::xxh3" , move |b| {
187
+ b. iter ( || cacache:: read_hash_sync ( black_box ( & cache) , black_box ( & sri) ) . unwrap ( ) )
188
+ } ) ;
189
+ }
190
+
147
191
fn read_hash_many_async ( c : & mut Criterion ) {
148
192
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
149
193
let cache = tmp. path ( ) . to_owned ( ) ;
@@ -195,6 +239,38 @@ fn read_hash_async_big_data(c: &mut Criterion) {
195
239
} ) ;
196
240
}
197
241
242
+ fn write_hash ( c : & mut Criterion ) {
243
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
244
+ let cache = tmp. path ( ) . to_owned ( ) ;
245
+ c. bench_function ( "put::data::sync" , move |b| {
246
+ b. iter_custom ( |iters| {
247
+ let start = std:: time:: Instant :: now ( ) ;
248
+ for i in 0 ..iters {
249
+ cacache:: write_hash_sync ( & cache, format ! ( "hello world{i}" ) ) . unwrap ( ) ;
250
+ }
251
+ start. elapsed ( )
252
+ } )
253
+ } ) ;
254
+ }
255
+
256
+ fn write_hash_xxh3 ( c : & mut Criterion ) {
257
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
258
+ let cache = tmp. path ( ) . to_owned ( ) ;
259
+ c. bench_function ( "put::data::sync::xxh3" , move |b| {
260
+ b. iter_custom ( |iters| {
261
+ let start = std:: time:: Instant :: now ( ) ;
262
+ for i in 0 ..iters {
263
+ cacache:: write_hash_sync_with_algo (
264
+ cacache:: Algorithm :: Xxh3 ,
265
+ & cache,
266
+ format ! ( "hello world{i}" ) ,
267
+ )
268
+ . unwrap ( ) ;
269
+ }
270
+ start. elapsed ( )
271
+ } )
272
+ } ) ;
273
+ }
198
274
fn write_hash_async ( c : & mut Criterion ) {
199
275
let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
200
276
let cache = tmp. path ( ) . to_owned ( ) ;
@@ -209,6 +285,25 @@ fn write_hash_async(c: &mut Criterion) {
209
285
} ) ;
210
286
}
211
287
288
+ fn write_hash_async_xxh3 ( c : & mut Criterion ) {
289
+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
290
+ let cache = tmp. path ( ) . to_owned ( ) ;
291
+ c. bench_function ( "put::data::xxh3" , move |b| {
292
+ b. iter_custom ( |iters| {
293
+ let start = std:: time:: Instant :: now ( ) ;
294
+ for i in 0 ..iters {
295
+ block_on ( cacache:: write_hash_with_algo (
296
+ cacache:: Algorithm :: Xxh3 ,
297
+ & cache,
298
+ format ! ( "hello world{i}" ) ,
299
+ ) )
300
+ . unwrap ( ) ;
301
+ }
302
+ start. elapsed ( )
303
+ } )
304
+ } ) ;
305
+ }
306
+
212
307
#[ cfg( feature = "link_to" ) ]
213
308
fn create_tmpfile ( tmp : & tempfile:: TempDir , buf : & [ u8 ] ) -> PathBuf {
214
309
let dir = tmp. path ( ) . to_owned ( ) ;
@@ -294,12 +389,18 @@ criterion_group!(
294
389
read_hash_async,
295
390
read_hash_many_async,
296
391
read_async,
392
+ write_hash,
393
+ write_hash_xxh3,
297
394
write_hash_async,
395
+ write_hash_async_xxh3,
298
396
read_hash_sync,
397
+ read_hash_sync_xxh3,
299
398
read_hash_many_sync,
399
+ read_hash_many_sync_xxh3,
300
400
read_sync,
301
401
read_hash_async_big_data,
302
- read_hash_sync_big_data
402
+ read_hash_sync_big_data,
403
+ read_hash_sync_big_data_xxh3,
303
404
) ;
304
405
305
406
#[ cfg( feature = "link_to" ) ]
0 commit comments