Last active
December 4, 2019 02:40
-
-
Save leotada/1977b775ef705db76389939184ea5637 to your computer and use it in GitHub Desktop.
D Programming Language (Dlang) - Example Garbage Collection ProfileStats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import core.memory; | |
import std.algorithm.mutation; | |
void main() | |
{ | |
int[] list; | |
int[] list2; | |
int[] result; | |
writeln("start"); | |
foreach (_; 0 .. 10) | |
{ | |
foreach (i; 0 .. 2000) | |
{ | |
list ~= i; | |
list2 ~= i + 1; | |
} | |
result = list ~ list2; | |
writeln(result.length); | |
// remove | |
foreach (i; list) | |
{ | |
list.remove(i); | |
} | |
// force more collections, you can remove this to compare | |
GC.collect(); | |
// add more | |
foreach (i; 0 .. 2000) | |
{ | |
list ~= i; | |
list2 ~= i + 1; | |
} | |
list = null; | |
list2 = null; | |
} | |
writeln("\nGC Stats"); | |
auto ps = GC.profileStats(); | |
writeln("numCollections: ", ps.numCollections); | |
writeln("totalCollectionTime: ", ps.totalCollectionTime); | |
writeln("totalPauseTime: ", ps.totalPauseTime); | |
writeln("maxPauseTime: ", ps.maxPauseTime); | |
writeln("maxCollectionTime: ", ps.maxCollectionTime); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment