Skip to content

Instantly share code, notes, and snippets.

@grogancolin
Created August 26, 2016 22:53
Show Gist options
  • Save grogancolin/a96a33f3b6d36c820e63982ced116eca to your computer and use it in GitHub Desktop.
Save grogancolin/a96a33f3b6d36c820e63982ced116eca to your computer and use it in GitHub Desktop.
import std.stdio;
import core.runtime;
void main(string[] args){
int x;
int[] xs;
for(int i = 0; i< 50; i++){
x = x+i;
xs ~= x;
}
writefln("X is %s", x);
printLatestStats();
writefln("Fib: %s", factorial(5));
printLatestStats();
}
void printLatestStats(){
writeln("type - bytes total allocations");
foreach(entry; getLatestAndClear()){
writefln(" %s - %s %s", entry.name, entry.count, entry.line);
}
}
@nogc int factorial(int n){
if(n==0 || n==1) return 1;
return n*factorial(n-1);
}
/+
Produces
./profile X is 1225
type - bytes total allocations
int[] D main profile.d:10 - 50 200
Fib: 120
type - bytes total allocations
+/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment