Skip to content

Commit b559bb5

Browse files
Benchmark specializations and item lengths
`tuple_windows, circular_tuple_windows, tuples, tuple_combinations, combinations, combinations_with_replacement, permutations` all generate elements of various fixed lengths. Benchmark against those lengths (here 1 2 3 4) might provide more insight.
1 parent 9fc2af3 commit b559bb5

File tree

1 file changed

+143
-8
lines changed

1 file changed

+143
-8
lines changed

benches/specializations.rs

Lines changed: 143 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,84 @@ bench_specializations! {
155155
}
156156
v.iter().batching(Iterator::next)
157157
}
158-
tuple_windows {
158+
tuple_windows1 {
159+
ExactSizeIterator
160+
{
161+
let v = black_box(vec![0; 1024]);
162+
}
163+
v.iter().tuple_windows::<(_,)>()
164+
}
165+
tuple_windows2 {
166+
ExactSizeIterator
167+
{
168+
let v = black_box(vec![0; 1024]);
169+
}
170+
v.iter().tuple_windows::<(_, _)>()
171+
}
172+
tuple_windows3 {
173+
ExactSizeIterator
174+
{
175+
let v = black_box(vec![0; 1024]);
176+
}
177+
v.iter().tuple_windows::<(_, _, _)>()
178+
}
179+
tuple_windows4 {
159180
ExactSizeIterator
160181
{
161182
let v = black_box(vec![0; 1024]);
162183
}
163184
v.iter().tuple_windows::<(_, _, _, _)>()
164185
}
165-
circular_tuple_windows {
186+
circular_tuple_windows1 {
187+
ExactSizeIterator
188+
{
189+
let v = black_box(vec![0; 1024]);
190+
}
191+
v.iter().circular_tuple_windows::<(_,)>()
192+
}
193+
circular_tuple_windows2 {
194+
ExactSizeIterator
195+
{
196+
let v = black_box(vec![0; 1024]);
197+
}
198+
v.iter().circular_tuple_windows::<(_, _)>()
199+
}
200+
circular_tuple_windows3 {
201+
ExactSizeIterator
202+
{
203+
let v = black_box(vec![0; 1024]);
204+
}
205+
v.iter().circular_tuple_windows::<(_, _, _)>()
206+
}
207+
circular_tuple_windows4 {
166208
ExactSizeIterator
167209
{
168210
let v = black_box(vec![0; 1024]);
169211
}
170212
v.iter().circular_tuple_windows::<(_, _, _, _)>()
171213
}
172-
tuples {
214+
tuples1 {
215+
ExactSizeIterator
216+
{
217+
let v = black_box(vec![0; 1024]);
218+
}
219+
v.iter().tuples::<(_,)>()
220+
}
221+
tuples2 {
222+
ExactSizeIterator
223+
{
224+
let v = black_box(vec![0; 1024]);
225+
}
226+
v.iter().tuples::<(_, _)>()
227+
}
228+
tuples3 {
229+
ExactSizeIterator
230+
{
231+
let v = black_box(vec![0; 1024]);
232+
}
233+
v.iter().tuples::<(_, _, _)>()
234+
}
235+
tuples4 {
173236
ExactSizeIterator
174237
{
175238
let v = black_box(vec![0; 1024]);
@@ -287,9 +350,27 @@ bench_specializations! {
287350
}
288351
v.iter().copied().update(|x| *x *= 7)
289352
}
290-
tuple_combinations {
353+
tuple_combinations1 {
291354
{
292-
let v = black_box((0..64).collect_vec());
355+
let v = black_box(vec![0; 1024]);
356+
}
357+
v.iter().tuple_combinations::<(_,)>()
358+
}
359+
tuple_combinations2 {
360+
{
361+
let v = black_box(vec![0; 64]);
362+
}
363+
v.iter().tuple_combinations::<(_, _)>()
364+
}
365+
tuple_combinations3 {
366+
{
367+
let v = black_box(vec![0; 64]);
368+
}
369+
v.iter().tuple_combinations::<(_, _, _)>()
370+
}
371+
tuple_combinations4 {
372+
{
373+
let v = black_box(vec![0; 64]);
293374
}
294375
v.iter().tuple_combinations::<(_, _, _, _)>()
295376
}
@@ -307,19 +388,73 @@ bench_specializations! {
307388
}
308389
v.iter().intersperse_with(|| &n)
309390
}
310-
combinations {
391+
combinations1 {
392+
{
393+
let v = black_box(vec![0; 1792]);
394+
}
395+
v.iter().combinations(1)
396+
}
397+
combinations2 {
398+
{
399+
let v = black_box(vec![0; 60]);
400+
}
401+
v.iter().combinations(2)
402+
}
403+
combinations3 {
404+
{
405+
let v = black_box(vec![0; 23]);
406+
}
407+
v.iter().combinations(3)
408+
}
409+
combinations4 {
311410
{
312411
let v = black_box(vec![0; 16]);
313412
}
314413
v.iter().combinations(4)
315414
}
316-
combinations_with_replacement {
415+
combinations_with_replacement1 {
416+
{
417+
let v = black_box(vec![0; 4096]);
418+
}
419+
v.iter().combinations_with_replacement(1)
420+
}
421+
combinations_with_replacement2 {
422+
{
423+
let v = black_box(vec![0; 90]);
424+
}
425+
v.iter().combinations_with_replacement(2)
426+
}
427+
combinations_with_replacement3 {
428+
{
429+
let v = black_box(vec![0; 28]);
430+
}
431+
v.iter().combinations_with_replacement(3)
432+
}
433+
combinations_with_replacement4 {
317434
{
318435
let v = black_box(vec![0; 16]);
319436
}
320437
v.iter().combinations_with_replacement(4)
321438
}
322-
permutations {
439+
permutations1 {
440+
{
441+
let v = black_box(vec![0; 1024]);
442+
}
443+
v.iter().permutations(1)
444+
}
445+
permutations2 {
446+
{
447+
let v = black_box(vec![0; 36]);
448+
}
449+
v.iter().permutations(2)
450+
}
451+
permutations3 {
452+
{
453+
let v = black_box(vec![0; 12]);
454+
}
455+
v.iter().permutations(3)
456+
}
457+
permutations4 {
323458
{
324459
let v = black_box(vec![0; 8]);
325460
}

0 commit comments

Comments
 (0)