rosella/gc_test.c

70 lines
1.3 KiB
C

#include <sys/time.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "gc.h"
int gc_counter;
int gc_ticks;
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);
gc_counter = 0;
gc_ticks = 0;
srand((unsigned int)time(NULL));
register_gc_root(&list_root, NIL);
while (1)
{
int r = rand() & 0xffff;
if (r == 0)
list_root.value = to_fixnum(rand());
else if (r & 1)
list_root.value = cons(to_fixnum(rand()), list_root.value);
else if (r & 2)
list_root.value = cons(list_root.value, to_fixnum(rand()));
else if (r & 4)
{
list_root.value = cons(list_root.value, cons(to_fixnum(-1), NIL));
get_pair(get_pair(list_root.value)->cdr)->cdr = list_root.value;
}
if (gc_counter >= 1000)
{
fprintf(stderr, "%d collections in %0.3f seconds = %0.3f usec / GC\n",
gc_counter,
gc_ticks / (double)CLOCKS_PER_SEC,
(1000000 * (gc_ticks / (double)CLOCKS_PER_SEC)) / gc_counter);
gc_counter = gc_ticks = 0;
if (++count == 10)
break;
}
}
unregister_gc_root(&list_root);
return 0;
}
/* vim:set sw=2 expandtab: */