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