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"
99
1010[dependencies ]
1111draw = " 0.3"
12+ memory-stats = " 1.0.0"
1213rand = " 0.8"
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ Memory usage:
3232Tree size (16 bytes) * 100000
3333+ TreeKind size (~30 bytes) * 2
3434-------------------------------
35- Total: 1MB (instead of 4MB)
35+ Total: 1688KB (estimated 1562KB),
36+ instead of 4492KB
3637```
3738
3839## Overview
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const TREE_TYPES: u32 = 2;
1212fn main ( ) {
1313 let forest = & mut Forest :: default ( ) ;
1414
15+ let phys_mem_before = memory_stats:: memory_stats ( ) . unwrap ( ) . physical_mem ;
16+
1517 for _ in 0 ..TREES_TO_DRAW / TREE_TYPES {
1618 let mut rng = rand:: thread_rng ( ) ;
1719
@@ -32,6 +34,8 @@ fn main() {
3234 ) ;
3335 }
3436
37+ let phys_mem_after = memory_stats:: memory_stats ( ) . unwrap ( ) . physical_mem ;
38+
3539 let mut canvas = Canvas :: new ( CANVAS_SIZE , CANVAS_SIZE ) ;
3640 forest. draw ( & mut canvas) ;
3741
@@ -45,8 +49,9 @@ fn main() {
4549 println ! ( "+ TreeKind size (~30 bytes) * {}" , TREE_TYPES ) ;
4650 println ! ( "-------------------------------" ) ;
4751 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 )
5156 ) ;
5257}
You can’t perform that action at this time.
0 commit comments