Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
// testing rust allocator vs onsen without doing any work on the data
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use std::time::Duration;

use onsen;
use onsen::PoolApi;

// The data we work on contains a primary value used for sorting and some payload which becomes mutated
pub struct Data<const N: usize> {
    primary: u32,
    payload: [u32; N],
}

type SmallData = Data<3>;
type MedData = Data<64>;
type BigData = Data<1000>;

impl<const N: usize> Data<N> {
    fn new(primary: u32) -> Self {
        Data {
            primary,
            payload: [primary; N],
        }
    }
}

trait DataHandle {
    fn primary(&self) -> &u32;
    fn primary_mut(&mut self) -> &mut u32;
    fn payload(&mut self) -> &mut [u32];
}

// Worker contains context and work we simulate
trait Worker<'a> {
    type Data: DataHandle;
    fn new() -> Self;
    fn new_element(&'a self, primary: u32) -> Option<Self::Data>;

    // a work simulator that does not free elements
    fn run_keep(&'a self, howmuch: usize) {
        let mut state = 0xbabeface_u32;
        let mut workspace: Vec<Option<Self::Data>> = Vec::with_capacity(howmuch);
        for _ in 0..howmuch {
            match fast_prng(&mut state) % 100 {
                _ if workspace.len() < 50 => {
                    // warmup for the first 50 entries
                    workspace.push(self.new_element(fast_prng(&mut state)));
                }
                0..=69 => {
                    //push new entry
                    workspace.push(self.new_element(fast_prng(&mut state)));
                }
                70..=74 => {
                    // mutate payload & primary within first 10%
                    let pos = fast_prng(&mut state) as usize % (workspace.len() / 10);
                    if let Some(value) = workspace[pos].as_mut() {
                        *value.primary_mut() = fast_prng(&mut state);
                        for n in 0..value.payload().len() {
                            value.payload()[n] = fast_prng(&mut state);
                        }
                    }
                }
                75..=79 => {
                    // sort the first 5% of the vec values increasing, none at the end
                    let pos = fast_prng(&mut state) as usize % (workspace.len() / 20);
                    workspace[0..pos].sort_unstable_by(|a, b| {
                        match (a, b) {
                            (Some(a), Some(b)) => a.primary().partial_cmp(&b.primary()).unwrap(),
                            _ => std::cmp::Ordering::Greater, // Contains a 'None'
                        }
                    });
                }
                80..=99 => {
                    // swap 2 entries, first from the first 10%, second from anywhere
                    let pos1 = fast_prng(&mut state) as usize % (workspace.len() / 10);
                    let pos2 = fast_prng(&mut state) as usize % (workspace.len());
                    workspace.swap(pos1, pos2);
                }
                _ => unreachable!(),
            }
        }
    }

    // a work simulator that sometimes frees elements
    fn run_drop(&'a self, howmuch: usize) {
        let mut state = 0xbabeface_u32;
        let mut workspace: Vec<Option<Self::Data>> = Vec::with_capacity(howmuch);
        for _ in 0..howmuch {
            match fast_prng(&mut state) % 100 {
                _ if workspace.len() < 50 => {
                    // warmup for the first 50 entries
                    workspace.push(self.new_element(fast_prng(&mut state)));
                }
                0..=39 => {
                    //push new entry
                    workspace.push(self.new_element(fast_prng(&mut state)));
                }
                40..=69 => {
                    // mutate payload & primary within first 10%
                    let pos = fast_prng(&mut state) as usize % (workspace.len() / 10);
                    if let Some(value) = workspace[pos].as_mut() {
                        *value.primary_mut() = fast_prng(&mut state);
                        for n in 0..value.payload().len() {
                            value.payload()[n] = fast_prng(&mut state);
                        }
                    }
                }
                70..=74 => {
                    // sort the first 5% of the vec values increasing, none at the end
                    let pos = fast_prng(&mut state) as usize % (workspace.len() / 20);
                    workspace[0..pos].sort_unstable_by(|a, b| {
                        match (a, b) {
                            (Some(a), Some(b)) => a.primary().partial_cmp(&b.primary()).unwrap(),
                            _ => std::cmp::Ordering::Greater, // Contains a 'None'
                        }
                    });
                }
                75..=89 => {
                    // swap 2 entries, first from the first 10%, second from anywhere
                    let pos1 = fast_prng(&mut state) as usize % (workspace.len() / 10);
                    let pos2 = fast_prng(&mut state) as usize % (workspace.len());
                    workspace.swap(pos1, pos2);
                }
                90..=99 => {
                    // drop random entry in first 20%
                    let pos = fast_prng(&mut state) as usize % (workspace.len() / 5);
                    workspace[pos] = None;
                }
                _ => unreachable!(),
            }
        }
    }
}

/// Owned data (copypaste, workaround the lack of GAT's, eventually needs macro or wait for GAT's)
pub struct SmallOwnedData(SmallData, usize);
pub struct MedOwnedData(MedData, usize);
pub struct BigOwnedData(BigData, usize);

impl DataHandle for SmallOwnedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

impl DataHandle for MedOwnedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

impl DataHandle for BigOwnedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

// data in a rust box
pub struct SmallBoxedData(Box<SmallData>);
pub struct MedBoxedData(Box<MedData>);
pub struct BigBoxedData(Box<BigData>);

impl DataHandle for SmallBoxedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

impl DataHandle for MedBoxedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

impl DataHandle for BigBoxedData {
    fn primary(&self) -> &u32 {
        &self.0.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.0.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.0.payload
    }
}

// data in a onsen box
impl DataHandle for onsen::Box<SmallData> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

impl DataHandle for onsen::Box<MedData> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

impl DataHandle for onsen::Box<BigData> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

// data in a onsen tbox
#[cfg(feature = "tbox")]
struct Bench;
#[cfg(feature = "tbox")]
onsen::define_tbox_pool!(Bench: SmallData);
#[cfg(feature = "tbox")]
onsen::define_tbox_pool!(Bench: MedData);
#[cfg(feature = "tbox")]
onsen::define_tbox_pool!(Bench: BigData);

#[cfg(feature = "tbox")]
impl DataHandle for onsen::TBox<SmallData, Bench> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

#[cfg(feature = "tbox")]
impl DataHandle for onsen::TBox<MedData, Bench> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

#[cfg(feature = "tbox")]
impl DataHandle for onsen::TBox<BigData, Bench> {
    fn primary(&self) -> &u32 {
        &self.primary
    }

    fn primary_mut(&mut self) -> &mut u32 {
        &mut self.primary
    }

    fn payload(&mut self) -> &mut [u32] {
        &mut self.payload
    }
}

// Now implement the workers for owned
#[repr(C)]
pub struct SmallOwnedWorker;
#[repr(C)]
pub struct MedOwnedWorker;
#[repr(C)]
pub struct BigOwnedWorker;

impl Worker<'_> for SmallOwnedWorker {
    type Data = SmallOwnedData;
    fn new() -> Self {
        SmallOwnedWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(SmallOwnedData(Data::new(primary), primary as usize))
    }
}

impl Worker<'_> for MedOwnedWorker {
    type Data = MedOwnedData;
    fn new() -> Self {
        MedOwnedWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(MedOwnedData(Data::new(primary), primary as usize))
    }
}

impl Worker<'_> for BigOwnedWorker {
    type Data = BigOwnedData;
    fn new() -> Self {
        BigOwnedWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(BigOwnedData(Data::new(primary), primary as usize))
    }
}

// Now implement the workers for rust boxes
#[repr(C)]
pub struct SmallBoxWorker;
#[repr(C)]
pub struct MedBoxWorker;
#[repr(C)]
pub struct BigBoxWorker;

impl Worker<'_> for SmallBoxWorker {
    type Data = SmallBoxedData;
    fn new() -> Self {
        SmallBoxWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(SmallBoxedData(Box::new(Data::new(primary))))
    }
}

impl Worker<'_> for MedBoxWorker {
    type Data = MedBoxedData;
    fn new() -> Self {
        MedBoxWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(MedBoxedData(Box::new(Data::new(primary))))
    }
}

impl Worker<'_> for BigBoxWorker {
    type Data = BigBoxedData;
    fn new() -> Self {
        BigBoxWorker
    }

    fn new_element(&self, primary: u32) -> Option<Self::Data> {
        Some(BigBoxedData(Box::new(Data::new(primary))))
    }
}

// // Now implement the workers for onsen boxes
pub struct SmallOnsenWorker {
    pool: onsen::RcPool<SmallData>,
}

pub struct MedOnsenWorker {
    pool: onsen::RcPool<MedData>,
}

pub struct BigOnsenWorker {
    pool: onsen::RcPool<BigData>,
}

impl<'a> Worker<'a> for SmallOnsenWorker {
    type Data = onsen::Box<SmallData>;
    fn new() -> Self {
        let pool = onsen::RcPool::new();
        pool.with_min_entries(1000);
        SmallOnsenWorker { pool }
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::Box::new(Data::new(primary), &self.pool))
    }
}

impl<'a> Worker<'a> for MedOnsenWorker {
    type Data = onsen::Box<MedData>;
    fn new() -> Self {
        let pool = onsen::RcPool::new();
        pool.with_min_entries(1000);
        MedOnsenWorker { pool }
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::Box::new(Data::new(primary), &self.pool))
    }
}

impl<'a> Worker<'a> for BigOnsenWorker {
    type Data = onsen::Box<BigData>;
    fn new() -> Self {
        let pool = onsen::RcPool::new();
        pool.with_min_entries(1000);
        BigOnsenWorker { pool }
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::Box::new(Data::new(primary), &self.pool))
    }
}

// Now implement the workers for onsen tbox
pub struct SmallOnsenTBoxWorker;

pub struct MedOnsenTBoxWorker;

pub struct BigOnsenTBoxWorker;

#[cfg(feature = "tbox")]
impl<'a> Worker<'a> for SmallOnsenTBoxWorker {
    type Data = onsen::TBox<SmallData, Bench>;
    fn new() -> Self {
        SmallOnsenTBoxWorker
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::TBox::new(Data::new(primary), Bench))
    }
}

#[cfg(feature = "tbox")]
impl<'a> Worker<'a> for MedOnsenTBoxWorker {
    type Data = onsen::TBox<MedData, Bench>;
    fn new() -> Self {
        MedOnsenTBoxWorker
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::TBox::new(Data::new(primary), Bench))
    }
}

#[cfg(feature = "tbox")]
impl<'a> Worker<'a> for BigOnsenTBoxWorker {
    type Data = onsen::TBox<BigData, Bench>;
    fn new() -> Self {
        BigOnsenTBoxWorker
    }

    fn new_element(&'a self, primary: u32) -> Option<Self::Data> {
        Some(onsen::TBox::new(Data::new(primary), Bench))
    }
}

//

#[inline(always)]
fn fast_prng(state: &mut u32) -> u32 {
    let rand = *state;
    *state = rand << 1 ^ ((rand >> 30) & 1) ^ ((rand >> 2) & 1);
    rand
}

fn criterion_benchmark(c: &mut Criterion) {
    // Keep benchmarks
    let mut simulated_work = c.benchmark_group("simulated keep, small data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(30));

        simulated_work.bench_with_input(BenchmarkId::new("owned", size), &size, {
            |b, &s| {
                let worker = SmallOwnedWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = SmallBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = SmallOnsenWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<SmallData, Bench>::pool().acquire().unwrap();
                let worker = SmallOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                });
                onsen::TBox::<SmallData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);
    let mut simulated_work = c.benchmark_group("simulated keep, medium data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(60));

        simulated_work.bench_with_input(BenchmarkId::new("owned", size), &size, {
            |b, &s| {
                let worker = MedOwnedWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = MedBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = MedOnsenWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<MedData, Bench>::pool().acquire().unwrap();
                let worker = MedOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                });
                onsen::TBox::<MedData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);
    let mut simulated_work = c.benchmark_group("simulated keep, big data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(90));

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = BigBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = BigOnsenWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<BigData, Bench>::pool().acquire().unwrap();
                let worker = BigOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_keep(*s);
                });
                onsen::TBox::<BigData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);

    // Drop benchmarks
    let mut simulated_work = c.benchmark_group("simulated drop, small data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(30));

        simulated_work.bench_with_input(BenchmarkId::new("owned", size), &size, {
            |b, &s| {
                let worker = SmallOwnedWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = SmallBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = SmallOnsenWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<SmallData, Bench>::pool().acquire().unwrap();
                let worker = SmallOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                });
                onsen::TBox::<SmallData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);
    let mut simulated_work = c.benchmark_group("simulated drop, medium data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(60));

        simulated_work.bench_with_input(BenchmarkId::new("owned", size), &size, {
            |b, &s| {
                let worker = MedOwnedWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = MedBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = MedOnsenWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<MedData, Bench>::pool().acquire().unwrap();
                let worker = MedOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                });
                onsen::TBox::<MedData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);
    let mut simulated_work = c.benchmark_group("simulated drop, big data");

    for size in [100, 500, 1000, 3000, 5000, 7500, 10000].iter() {
        simulated_work.throughput(Throughput::Elements(*size as u64));
        simulated_work.measurement_time(Duration::from_secs(90));

        simulated_work.bench_with_input(BenchmarkId::new("rust box", size), &size, {
            |b, &s| {
                let worker = BigBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        simulated_work.bench_with_input(BenchmarkId::new("onsen box", size), &size, {
            |b, &s| {
                let worker = BigOnsenWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                })
            }
        });

        #[cfg(feature = "tbox")]
        simulated_work.bench_with_input(BenchmarkId::new("onsen tbox", size), &size, {
            |b, &s| {
                onsen::TBox::<BigData, Bench>::pool().acquire().unwrap();
                let worker = BigOnsenTBoxWorker::new();
                b.iter(|| {
                    worker.run_drop(*s);
                });
                onsen::TBox::<BigData, Bench>::pool().release().unwrap();
            }
        });
    }

    drop(simulated_work);
}

criterion_group!(benches2, criterion_benchmark);
criterion_main!(benches2);