@@ -9,8 +9,23 @@ void print_stats(const Stats * stats) {
99 clock_t total = clock() - stats->start_time;
1010 clock_t mut = total - stats->init_time - stats->gc_time - stats->exit_time;
1111 double mut_sec = (double)mut / CLOCKS_PER_SEC;
12− int avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
13− int alloc_rate = (int)((double)(stats->allocations) / mut_sec);
12+
13+ int avg_chunk = 0;
14+ if (stats->alloc_count > 0) {
15+ avg_chunk = (int)((double)stats->allocations / (double)stats->alloc_count);
16+ }
17+
18+ int alloc_rate = 0;
19+ if (mut > 0) {
20+ alloc_rate = (int)((double)(stats->allocations) / mut_sec);
21+ }
22+
23+ double gc_percent = 0.0d;
24+ double productivity = 0.0d;
25+ if (total > 0) {
26+ gc_percent = 100 * (double)stats->gc_time / (double)total;
27+ productivity = 100 * ((double)mut / (double)total);
28+ }
1429
1530 setlocale(LC_NUMERIC, "");
1631 printf("\n");
@@ -28,11 +43,11 @@ void print_stats(const Stats * stats) {
2843 printf("EXIT time: %8.3fs\n", (double)stats->exit_time / CLOCKS_PER_SEC);
2944 printf("TOTAL time: %8.3fs\n\n", (double)total / CLOCKS_PER_SEC);
3045
31− printf("%%GC time: %.2f%%\n\n", 100 * (double)stats->gc_time / (double)total);
46+ printf("%%GC time: %.2f%%\n\n", gc_percent);
3247
3348 printf("Alloc rate %'d bytes per MUT sec\n\n", alloc_rate);
3449
35− printf("Productivity %.2f%%\n", 100 * ((double)mut / (double)total));
50+ printf("Productivity %.2f%%\n", productivity);
3651}
3752
3853void aggregate_stats(Stats * stats1, const Stats * stats2) {