mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-14 09:40:20 +02:00
Refactor gcbench.c
This commit is contained in:
parent
bdf4b27733
commit
869a490ba6
2 changed files with 18 additions and 92 deletions
108
GCBench.c
108
GCBench.c
|
@ -42,27 +42,16 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#ifdef GC
|
#ifdef GC_BDW
|
||||||
# include "gc.h"
|
#include "bdw.h"
|
||||||
|
#else
|
||||||
|
#error unknown gc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PROFIL
|
|
||||||
extern void init_profiling();
|
|
||||||
extern dump_profile();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// These macros were a quick hack for the Macintosh.
|
|
||||||
//
|
|
||||||
// #define currentTime() clock()
|
|
||||||
// #define elapsedTime(x) ((1000*(x))/CLOCKS_PER_SEC)
|
|
||||||
|
|
||||||
#define currentTime() stats_rtclock()
|
|
||||||
#define elapsedTime(x) (x)
|
#define elapsedTime(x) (x)
|
||||||
|
|
||||||
/* Get the current time in milliseconds */
|
/* Get the current time in milliseconds */
|
||||||
|
static unsigned currentTime(void)
|
||||||
unsigned
|
|
||||||
stats_rtclock( void )
|
|
||||||
{
|
{
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
|
@ -84,12 +73,6 @@ typedef struct Node0_struct {
|
||||||
int i, j;
|
int i, j;
|
||||||
} Node0;
|
} Node0;
|
||||||
|
|
||||||
#ifdef HOLES
|
|
||||||
# define HOLE() GC_NEW(Node0);
|
|
||||||
#else
|
|
||||||
# define HOLE()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef Node0 *Node;
|
typedef Node0 *Node;
|
||||||
|
|
||||||
void init_Node(Node me, Node l, Node r) {
|
void init_Node(Node me, Node l, Node r) {
|
||||||
|
@ -97,18 +80,6 @@ void init_Node(Node me, Node l, Node r) {
|
||||||
me -> right = r;
|
me -> right = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef GC
|
|
||||||
void destroy_Node(Node me) {
|
|
||||||
if (me -> left) {
|
|
||||||
destroy_Node(me -> left);
|
|
||||||
}
|
|
||||||
if (me -> right) {
|
|
||||||
destroy_Node(me -> right);
|
|
||||||
}
|
|
||||||
free(me);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Nodes used by a tree of a given size
|
// Nodes used by a tree of a given size
|
||||||
static int TreeSize(int i) {
|
static int TreeSize(int i) {
|
||||||
return ((1 << (i + 1)) - 1);
|
return ((1 << (i + 1)) - 1);
|
||||||
|
@ -125,13 +96,8 @@ static void Populate(int iDepth, Node thisNode) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
iDepth--;
|
iDepth--;
|
||||||
# ifdef GC
|
thisNode->left = GC_NEW(Node0);
|
||||||
thisNode->left = GC_NEW(Node0); HOLE();
|
thisNode->right = GC_NEW(Node0);
|
||||||
thisNode->right = GC_NEW(Node0); HOLE();
|
|
||||||
# else
|
|
||||||
thisNode->left = calloc(1, sizeof(Node0));
|
|
||||||
thisNode->right = calloc(1, sizeof(Node0));
|
|
||||||
# endif
|
|
||||||
Populate (iDepth, thisNode->left);
|
Populate (iDepth, thisNode->left);
|
||||||
Populate (iDepth, thisNode->right);
|
Populate (iDepth, thisNode->right);
|
||||||
}
|
}
|
||||||
|
@ -141,21 +107,13 @@ static void Populate(int iDepth, Node thisNode) {
|
||||||
static Node MakeTree(int iDepth) {
|
static Node MakeTree(int iDepth) {
|
||||||
Node result;
|
Node result;
|
||||||
if (iDepth<=0) {
|
if (iDepth<=0) {
|
||||||
# ifndef GC
|
result = GC_NEW(Node0);
|
||||||
result = calloc(1, sizeof(Node0));
|
/* result is implicitly initialized in both cases. */
|
||||||
# else
|
return result;
|
||||||
result = GC_NEW(Node0); HOLE();
|
|
||||||
# endif
|
|
||||||
/* result is implicitly initialized in both cases. */
|
|
||||||
return result;
|
|
||||||
} else {
|
} else {
|
||||||
Node left = MakeTree(iDepth-1);
|
Node left = MakeTree(iDepth-1);
|
||||||
Node right = MakeTree(iDepth-1);
|
Node right = MakeTree(iDepth-1);
|
||||||
# ifndef GC
|
result = GC_NEW(Node0);
|
||||||
result = malloc(sizeof(Node0));
|
|
||||||
# else
|
|
||||||
result = GC_NEW(Node0); HOLE();
|
|
||||||
# endif
|
|
||||||
init_Node(result, left, right);
|
init_Node(result, left, right);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -182,32 +140,22 @@ static void TimeConstruction(int depth) {
|
||||||
|
|
||||||
tStart = currentTime();
|
tStart = currentTime();
|
||||||
for (i = 0; i < iNumIters; ++i) {
|
for (i = 0; i < iNumIters; ++i) {
|
||||||
# ifndef GC
|
tempTree = GC_NEW(Node0);
|
||||||
tempTree = calloc(1, sizeof(Node0));
|
|
||||||
# else
|
|
||||||
tempTree = GC_NEW(Node0);
|
|
||||||
# endif
|
|
||||||
Populate(depth, tempTree);
|
Populate(depth, tempTree);
|
||||||
# ifndef GC
|
|
||||||
destroy_Node(tempTree);
|
|
||||||
# endif
|
|
||||||
tempTree = 0;
|
tempTree = 0;
|
||||||
}
|
}
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
printf("\tTop down construction took %d msec\n",
|
printf("\tTop down construction took %d msec\n",
|
||||||
elapsedTime(tFinish - tStart));
|
tFinish - tStart);
|
||||||
|
|
||||||
tStart = currentTime();
|
tStart = currentTime();
|
||||||
for (i = 0; i < iNumIters; ++i) {
|
for (i = 0; i < iNumIters; ++i) {
|
||||||
tempTree = MakeTree(depth);
|
tempTree = MakeTree(depth);
|
||||||
# ifndef GC
|
|
||||||
destroy_Node(tempTree);
|
|
||||||
# endif
|
|
||||||
tempTree = 0;
|
tempTree = 0;
|
||||||
}
|
}
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
printf("\tBottom up construction took %d msec\n",
|
printf("\tBottom up construction took %d msec\n",
|
||||||
elapsedTime(tFinish - tStart));
|
tFinish - tStart);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,11 +168,9 @@ int main() {
|
||||||
int i, d;
|
int i, d;
|
||||||
double *array;
|
double *array;
|
||||||
|
|
||||||
#ifdef GC
|
|
||||||
// GC_full_freq = 30;
|
// GC_full_freq = 30;
|
||||||
// GC_free_space_divisor = 16;
|
// GC_free_space_divisor = 16;
|
||||||
// GC_enable_incremental();
|
// GC_enable_incremental();
|
||||||
#endif
|
|
||||||
printf("Garbage Collector Test\n");
|
printf("Garbage Collector Test\n");
|
||||||
printf(" Live storage will peak at %d bytes.\n\n",
|
printf(" Live storage will peak at %d bytes.\n\n",
|
||||||
2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
|
2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
|
||||||
|
@ -240,32 +186,17 @@ int main() {
|
||||||
|
|
||||||
// Stretch the memory space quickly
|
// Stretch the memory space quickly
|
||||||
tempTree = MakeTree(kStretchTreeDepth);
|
tempTree = MakeTree(kStretchTreeDepth);
|
||||||
# ifndef GC
|
|
||||||
destroy_Node(tempTree);
|
|
||||||
# endif
|
|
||||||
tempTree = 0;
|
tempTree = 0;
|
||||||
|
|
||||||
// Create a long lived object
|
// Create a long lived object
|
||||||
printf(" Creating a long-lived binary tree of depth %d\n",
|
printf(" Creating a long-lived binary tree of depth %d\n",
|
||||||
kLongLivedTreeDepth);
|
kLongLivedTreeDepth);
|
||||||
# ifndef GC
|
longLivedTree = GC_NEW(Node0);
|
||||||
longLivedTree = calloc(1, sizeof(Node0));
|
|
||||||
# else
|
|
||||||
longLivedTree = GC_NEW(Node0);
|
|
||||||
# endif
|
|
||||||
Populate(kLongLivedTreeDepth, longLivedTree);
|
Populate(kLongLivedTreeDepth, longLivedTree);
|
||||||
|
|
||||||
// Create long-lived array, filling half of it
|
// Create long-lived array, filling half of it
|
||||||
printf(" Creating a long-lived array of %d doubles\n", kArraySize);
|
printf(" Creating a long-lived array of %d doubles\n", kArraySize);
|
||||||
# ifndef GC
|
array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
|
||||||
array = malloc(kArraySize * sizeof(double));
|
|
||||||
# else
|
|
||||||
# ifndef NO_PTRFREE
|
|
||||||
array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
|
|
||||||
# else
|
|
||||||
array = GC_MALLOC(sizeof(double) * kArraySize);
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
for (i = 0; i < kArraySize/2; ++i) {
|
for (i = 0; i < kArraySize/2; ++i) {
|
||||||
array[i] = 1.0/i;
|
array[i] = 1.0/i;
|
||||||
}
|
}
|
||||||
|
@ -282,15 +213,10 @@ int main() {
|
||||||
// to keep them from being optimized away
|
// to keep them from being optimized away
|
||||||
|
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
tElapsed = elapsedTime(tFinish-tStart);
|
tElapsed = tFinish - tStart;
|
||||||
PrintDiagnostics();
|
PrintDiagnostics();
|
||||||
printf("Completed in %d msec\n", tElapsed);
|
printf("Completed in %d msec\n", tElapsed);
|
||||||
# ifdef GC
|
|
||||||
printf("Completed %d collections\n", GC_gc_no);
|
printf("Completed %d collections\n", GC_gc_no);
|
||||||
printf("Heap size is %d\n", GC_get_heap_size());
|
printf("Heap size is %d\n", GC_get_heap_size());
|
||||||
# endif
|
|
||||||
# ifdef PROFIL
|
|
||||||
dump_profile();
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ ALL_TESTS=$(foreach COLLECTOR,$(COLLECTORS),$(addprefix $(COLLECTOR)-,$(TESTS)))
|
||||||
all: $(ALL_TESTS)
|
all: $(ALL_TESTS)
|
||||||
|
|
||||||
bdw-%: bdw.h %.c
|
bdw-%: bdw.h %.c
|
||||||
$(CC) $(CFLAGS) -lpthread `pkg-config --libs --cflags bdw-gc` -I. -o $@ $*.c bdw.h
|
$(CC) $(CFLAGS) -lpthread `pkg-config --libs --cflags bdw-gc` -I. -DGC_BDW -o $@ $*.c
|
||||||
|
|
||||||
check: $(addprefix test-$(TARGET),$(TARGETS))
|
check: $(addprefix test-$(TARGET),$(TARGETS))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue