#include #include #include #include #include #include #include #include "gc.h" void out_of_memory(void) { fprintf(stderr, "Out of memory!\n"); abort(); } int main(int argc, char **argv) { gc_root_t list_root; int count = 0; gc_init(1024, 256*1024*1024); srand((unsigned int)time(NULL)); register_gc_root(&list_root, NIL); while (1) { int r = rand() & 0x3fff; if (r == 0) list_root.value = make_fixnum(rand()); else { switch (r & 7) { case 0: list_root.value = cons(make_fixnum(rand()), list_root.value); break; case 1: list_root.value = cons(list_root.value, make_byte_string(256, '\0')); break; case 2: list_root.value = make_box(list_root.value); break; case 3: list_root.value = cons(list_root.value, cons(make_fixnum(-1), NIL)); get_pair(get_pair(list_root.value)->cdr)->cdr = list_root.value; break; case 4: case 5: case 6: case 7: { value_t s = make_struct(NIL, 5); _get_struct(s)->slots[1+(r & 3)] = list_root.value; list_root.value = s; } break; } } if (++count >= 10000000) { const double total_time = gc_stats.total_ticks / (double)CLOCKS_PER_SEC; fprintf(stderr, "%0.3f sec / %d GCs => %0.3f usec/GC; peak was %u bytes.\n", total_time, gc_stats.collections, (1000000 * total_time) / gc_stats.collections, gc_stats.high_water); gc_stats.collections = 0; gc_stats.total_ticks = 0; gc_stats.high_water = 0; count = 0; break; } } unregister_gc_root(&list_root); return 0; } /* vim:set sw=2 expandtab: */