File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ path = "main.rs"
9
9
10
10
[dependencies ]
11
11
draw = " 0.3"
12
+ memory-stats = " 1.0.0"
12
13
rand = " 0.8"
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ Memory usage:
32
32
Tree size (16 bytes) * 100000
33
33
+ TreeKind size (~30 bytes) * 2
34
34
-------------------------------
35
- Total: 1MB (instead of 4MB)
35
+ Total: 1688KB (estimated 1562KB),
36
+ instead of 4492KB
36
37
```
37
38
38
39
## Overview
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const TREE_TYPES: u32 = 2;
12
12
fn main ( ) {
13
13
let forest = & mut Forest :: default ( ) ;
14
14
15
+ let phys_mem_before = memory_stats:: memory_stats ( ) . unwrap ( ) . physical_mem ;
16
+
15
17
for _ in 0 ..TREES_TO_DRAW / TREE_TYPES {
16
18
let mut rng = rand:: thread_rng ( ) ;
17
19
@@ -32,6 +34,8 @@ fn main() {
32
34
) ;
33
35
}
34
36
37
+ let phys_mem_after = memory_stats:: memory_stats ( ) . unwrap ( ) . physical_mem ;
38
+
35
39
let mut canvas = Canvas :: new ( CANVAS_SIZE , CANVAS_SIZE ) ;
36
40
forest. draw ( & mut canvas) ;
37
41
@@ -45,8 +49,9 @@ fn main() {
45
49
println ! ( "+ TreeKind size (~30 bytes) * {}" , TREE_TYPES ) ;
46
50
println ! ( "-------------------------------" ) ;
47
51
println ! (
48
- "Total: {}MB (instead of {}MB)" ,
49
- ( ( TREES_TO_DRAW * 16 + TREE_TYPES * 30 ) / 1024 / 1024 ) ,
50
- ( ( TREES_TO_DRAW * 46 ) / 1024 / 1024 )
52
+ "Total: {}KB (estimated {}KB),\n instead of {}KB" ,
53
+ ( phys_mem_after - phys_mem_before) / 1024 ,
54
+ ( TREES_TO_DRAW * 16 + TREE_TYPES * 30 ) / 1024 ,
55
+ ( ( TREES_TO_DRAW * 46 ) / 1024 )
51
56
) ;
52
57
}
You can’t perform that action at this time.
0 commit comments