@@ -6,20 +6,20 @@ fn bench_alloc_speed(c: &mut Criterion) {
66
77 for num_objects in [ 100 , 500 , 1000 ] . iter ( ) {
88 group. bench_with_input (
9- BenchmarkId :: new ( "arena3 " , num_objects) ,
9+ BenchmarkId :: new ( "mempool3 " , num_objects) ,
1010 num_objects,
1111 |b, & num_objects| {
1212 b. iter ( || {
1313 let mut allocator =
14- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 65536 ) ;
14+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 65536 ) ;
1515
1616 let mut ptrs = Vec :: new ( ) ;
1717 for i in 0 ..num_objects {
1818 let ptr = allocator. try_alloc ( i) . expect ( "allocation failed" ) ;
1919 ptrs. push ( ptr) ;
2020 }
2121
22- black_box ( ( ptrs. len ( ) , allocator. arenas_len ( ) ) )
22+ black_box ( ( ptrs. len ( ) , allocator. pools_len ( ) ) )
2323 } ) ;
2424 } ,
2525 ) ;
@@ -34,6 +34,7 @@ fn bench_alloc_speed(c: &mut Criterion) {
3434
3535 let mut ptrs = Vec :: new ( ) ;
3636 for i in 0 ..num_objects {
37+ let i: usize = i;
3738 let ptr = allocator. try_alloc ( i) . expect ( "allocation failed" ) ;
3839 ptrs. push ( ptr) ;
3940 }
@@ -59,12 +60,12 @@ fn bench_small_objects(c: &mut Criterion) {
5960
6061 for num_objects in [ 100 , 500 , 1000 ] . iter ( ) {
6162 group. bench_with_input (
62- BenchmarkId :: new ( "arena3 " , num_objects) ,
63+ BenchmarkId :: new ( "mempool3 " , num_objects) ,
6364 num_objects,
6465 |b, & num_objects| {
6566 b. iter ( || {
6667 let mut allocator =
67- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 32768 ) ;
68+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 32768 ) ;
6869
6970 for i in 0 ..num_objects {
7071 let obj = SmallObject {
@@ -74,7 +75,7 @@ fn bench_small_objects(c: &mut Criterion) {
7475 let _ = allocator. try_alloc ( obj) . expect ( "allocation failed" ) ;
7576 }
7677
77- black_box ( allocator. arenas_len ( ) )
78+ black_box ( allocator. pools_len ( ) )
7879 } ) ;
7980 } ,
8081 ) ;
@@ -88,6 +89,7 @@ fn bench_small_objects(c: &mut Criterion) {
8889 oscars:: alloc:: arena2:: ArenaAllocator :: default ( ) . with_arena_size ( 32768 ) ;
8990
9091 for i in 0 ..num_objects {
92+ let i: usize = i;
9193 let obj = SmallObject {
9294 _a : i as u64 ,
9395 _b : i as u64 * 2 ,
@@ -107,10 +109,10 @@ fn bench_small_objects(c: &mut Criterion) {
107109fn bench_mixed ( c : & mut Criterion ) {
108110 let mut group = c. benchmark_group ( "3_mixed_sizes" ) ;
109111
110- group. bench_function ( "arena3 " , |b| {
112+ group. bench_function ( "mempool3 " , |b| {
111113 b. iter ( || {
112114 let mut allocator =
113- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 65536 ) ;
115+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 65536 ) ;
114116
115117 for _ in 0 ..50 {
116118 let _ = allocator. try_alloc ( [ 0u8 ; 16 ] ) ;
@@ -119,7 +121,7 @@ fn bench_mixed(c: &mut Criterion) {
119121 let _ = allocator. try_alloc ( [ 0u8 ; 128 ] ) ;
120122 }
121123
122- black_box ( allocator. arenas_len ( ) )
124+ black_box ( allocator. pools_len ( ) )
123125 } ) ;
124126 } ) ;
125127
@@ -148,20 +150,20 @@ fn bench_density(c: &mut Criterion) {
148150
149151 const PAGE_SIZE : usize = 4096 ;
150152
151- group. bench_function ( "arena3 " , |b| {
153+ group. bench_function ( "mempool3 " , |b| {
152154 b. iter ( || {
153155 let mut allocator =
154- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( PAGE_SIZE ) ;
156+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( PAGE_SIZE ) ;
155157
156158 let mut count = 0 ;
157159 while allocator. try_alloc ( [ 0u64 ; 2 ] ) . is_ok ( ) {
158160 count += 1 ;
159- if allocator. arenas_len ( ) > 1 {
161+ if allocator. pools_len ( ) > 1 {
160162 break ;
161163 }
162164 }
163165
164- black_box ( ( count, allocator. arenas_len ( ) ) )
166+ black_box ( ( count, allocator. pools_len ( ) ) )
165167 } ) ;
166168 } ) ;
167169
@@ -189,10 +191,10 @@ fn bench_density(c: &mut Criterion) {
189191fn bench_vec_growth ( c : & mut Criterion ) {
190192 let mut group = c. benchmark_group ( "5_vec_growth" ) ;
191193
192- group. bench_function ( "arena3 " , |b| {
194+ group. bench_function ( "mempool3 " , |b| {
193195 b. iter ( || {
194196 let mut allocator =
195- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 32768 ) ;
197+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 32768 ) ;
196198
197199 let mut cap = 1 ;
198200 while cap <= 1024 {
@@ -235,7 +237,7 @@ fn bench_vec_growth(c: &mut Criterion) {
235237 cap *= 2 ;
236238 }
237239
238- black_box ( allocator. arenas_len ( ) )
240+ black_box ( allocator. pools_len ( ) )
239241 } ) ;
240242 } ) ;
241243
@@ -296,16 +298,16 @@ fn bench_throughput(c: &mut Criterion) {
296298 let mut group = c. benchmark_group ( "6_sustained_throughput" ) ;
297299 group. throughput ( criterion:: Throughput :: Elements ( 10000 ) ) ;
298300
299- group. bench_function ( "arena3 " , |b| {
301+ group. bench_function ( "mempool3 " , |b| {
300302 b. iter ( || {
301303 let mut allocator =
302- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 131072 ) ;
304+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 131072 ) ;
303305
304306 for i in 0 ..10000 {
305307 let _ = allocator. try_alloc ( i) ;
306308 }
307309
308- black_box ( allocator. arenas_len ( ) )
310+ black_box ( allocator. pools_len ( ) )
309311 } ) ;
310312 } ) ;
311313
@@ -332,13 +334,13 @@ fn bench_dealloc_speed(c: &mut Criterion) {
332334 // using `iter_batched` ensures we only measure the deallocation phase
333335 for num_objects in [ 100 , 500 , 1000 ] . iter ( ) {
334336 group. bench_with_input (
335- BenchmarkId :: new ( "arena3 " , num_objects) ,
337+ BenchmarkId :: new ( "mempool3 " , num_objects) ,
336338 num_objects,
337339 |b, & num_objects| {
338340 b. iter_batched (
339341 || {
340342 let mut allocator =
341- oscars:: alloc:: arena3 :: ArenaAllocator :: default ( ) . with_arena_size ( 65536 ) ;
343+ oscars:: alloc:: mempool3 :: PoolAllocator :: default ( ) . with_page_size ( 65536 ) ;
342344
343345 let mut ptrs = Vec :: new ( ) ;
344346 for i in 0 ..num_objects {
@@ -347,12 +349,14 @@ fn bench_dealloc_speed(c: &mut Criterion) {
347349 }
348350 ( allocator, ptrs)
349351 } ,
350- |( mut allocator, ptrs) | {
352+ |( mut allocator, ptrs) : ( _ , _ ) | {
351353 for ptr in ptrs {
352- allocator. free_slot ( ptr. as_ptr ( ) . cast :: < u8 > ( ) ) ;
354+ unsafe {
355+ allocator. free_slot_typed ( ptr. as_ptr ( ) ) ;
356+ }
353357 }
354- allocator. drop_dead_arenas ( ) ;
355- black_box ( allocator. arenas_len ( ) )
358+ allocator. drop_empty_pools ( ) ;
359+ black_box ( allocator. pools_len ( ) )
356360 } ,
357361 criterion:: BatchSize :: SmallInput ,
358362 ) ;
@@ -370,12 +374,13 @@ fn bench_dealloc_speed(c: &mut Criterion) {
370374
371375 let mut ptrs = Vec :: new ( ) ;
372376 for i in 0 ..num_objects {
377+ let i: usize = i;
373378 let ptr = allocator. try_alloc ( i) . expect ( "allocation failed" ) ;
374379 ptrs. push ( ptr) ;
375380 }
376381 ( allocator, ptrs)
377382 } ,
378- |( mut allocator, ptrs) | {
383+ |( mut allocator, ptrs) : ( _ , _ ) | {
379384 for ptr in ptrs {
380385 let mut heap_item_ptr = ptr. as_ptr ( ) ;
381386 unsafe {
0 commit comments