File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
crates/divan_compat/examples Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -44,3 +44,7 @@ harness = false
4444[[bench ]]
4545name = " counters"
4646harness = false
47+
48+ [[bench ]]
49+ name = " alloc"
50+ harness = false
Original file line number Diff line number Diff line change 1+ use std:: {
2+ alloc:: Layout ,
3+ collections:: { HashMap , HashSet } ,
4+ } ;
5+
6+ #[ divan:: bench]
7+ fn allocate ( ) {
8+ println ! ( "Hello, world!" ) ;
9+
10+ let vec = vec ! [ 1 , 2 , 3 ] ;
11+ println ! ( "{vec:?}" ) ;
12+
13+ let mut map = HashMap :: new ( ) ;
14+ map. insert ( "key" , "value" ) ;
15+ println ! ( "{map:?}" ) ;
16+
17+ let mut set = HashSet :: new ( ) ;
18+ set. insert ( "apple" ) ;
19+ set. insert ( "banana" ) ;
20+ println ! ( "{set:?}" ) ;
21+
22+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
23+
24+ let mut bytes_vec = vec ! [ 0u8 ; 0x100 ] ;
25+ println ! ( "{:?}" , bytes_vec. len( ) ) ;
26+
27+ bytes_vec. extend ( & vec ! [ 0u8 ; 0x1000 ] ) ;
28+
29+ // Alloc 256 bytes of memory
30+ for _ in 0 ..100 {
31+ let memory = unsafe { std:: alloc:: alloc ( Layout :: new :: < [ u8 ; 42 ] > ( ) ) } ;
32+ core:: hint:: black_box ( memory) ;
33+ }
34+ }
35+
36+ fn main ( ) {
37+ divan:: main ( ) ;
38+ }
You can’t perform that action at this time.
0 commit comments