-
Notifications
You must be signed in to change notification settings - Fork 68
Description
During my work on the Nim version of this code (which it it's most optimised version beats the C++ versions on speed), I did some runs of the C++ code as well. One thing I noticed is that I regularly got 504KiB memory usage, and not the 0.3MiB (so somewhere around the 300KiB mark). I did sometimes see it dip to 376KiB however, so I went to see how often this would happen.
To get lot's of measurements I went with:
for i in {0..10000}; do; ~/div/cgmemtime/cgmemtime --force-empty -t ./main-gcc 2>>memtest2; done
However I did abort the run after 5826 samples as it was starting to drag on a bit. The average memory consumption of all the runs were 524KiB and the breakdown of samples was as follows:
| Memory usage | Occurences |
|---|---|
| 376 | 29 |
| 380 | 42 |
| 500 | 1 |
| 504 | 4512 |
| 508 | 295 |
| 632 | 891 |
| 636 | 37 |
| 760 | 16 |
| 764 | 2 |
| Total Result | 5825 |
As we can see only 71 of the 5825 runs used less than 500KiB, a mere 1.22%.
Running with the Nim version with manual memory allocation we actually get a better average at 513KiB with a breakdown of:
| Memory usage | Occurences |
|---|---|
| 500 | 1 |
| 504 | 880 |
| 508 | 53 |
| 632 | 60 |
| 636 | 4 |
| 760 | 2 |
| Total Result | 1000 |
And just for comparison the Nim version using the GC get's an average of 899KiB with a breakdown of:
| Memory usage | Occurences |
|---|---|
| 888 | 868 |
| 892 | 48 |
| 1016 | 77 |
| 1020 | 4 |
| 1144 | 3 |
| Total Result | 1000 |
The speed seems to be affected as well, although not as much:
| C++ raw pointers | Nim manual memory | Nim GC |
|---|---|---|
| 0.314 | 0.280 | 0.282 |
| 0.241 | 0.190 | 0.193 |
First row is average speed, second is minimum speed (C++ version run 5825 times, the Nim versions only 1000 times).