mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-13 17:20:21 +02:00
Reindent gcbench
This commit is contained in:
parent
869a490ba6
commit
25213ccdeb
1 changed files with 103 additions and 105 deletions
208
GCBench.c
208
GCBench.c
|
@ -48,8 +48,6 @@
|
||||||
#error unknown gc
|
#error unknown gc
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define elapsedTime(x) (x)
|
|
||||||
|
|
||||||
/* Get the current time in milliseconds */
|
/* Get the current time in milliseconds */
|
||||||
static unsigned currentTime(void)
|
static unsigned currentTime(void)
|
||||||
{
|
{
|
||||||
|
@ -68,155 +66,155 @@ static const int kMinTreeDepth = 4;
|
||||||
static const int kMaxTreeDepth = 16;
|
static const int kMaxTreeDepth = 16;
|
||||||
|
|
||||||
typedef struct Node0_struct {
|
typedef struct Node0_struct {
|
||||||
struct Node0_struct * left;
|
struct Node0_struct * left;
|
||||||
struct Node0_struct * right;
|
struct Node0_struct * right;
|
||||||
int i, j;
|
int i, j;
|
||||||
} Node0;
|
} Node0;
|
||||||
|
|
||||||
typedef Node0 *Node;
|
typedef Node0 *Node;
|
||||||
|
|
||||||
void init_Node(Node me, Node l, Node r) {
|
void init_Node(Node me, Node l, Node r) {
|
||||||
me -> left = l;
|
me -> left = l;
|
||||||
me -> right = r;
|
me -> right = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of iterations to use for a given tree depth
|
// Number of iterations to use for a given tree depth
|
||||||
static int NumIters(int i) {
|
static int NumIters(int i) {
|
||||||
return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
|
return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build tree top down, assigning to older objects.
|
// Build tree top down, assigning to older objects.
|
||||||
static void Populate(int iDepth, Node thisNode) {
|
static void Populate(int iDepth, Node thisNode) {
|
||||||
if (iDepth<=0) {
|
if (iDepth<=0) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
iDepth--;
|
iDepth--;
|
||||||
thisNode->left = GC_NEW(Node0);
|
thisNode->left = GC_NEW(Node0);
|
||||||
thisNode->right = GC_NEW(Node0);
|
thisNode->right = GC_NEW(Node0);
|
||||||
Populate (iDepth, thisNode->left);
|
Populate (iDepth, thisNode->left);
|
||||||
Populate (iDepth, thisNode->right);
|
Populate (iDepth, thisNode->right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build tree bottom-up
|
// Build tree bottom-up
|
||||||
static Node MakeTree(int iDepth) {
|
static Node MakeTree(int iDepth) {
|
||||||
Node result;
|
Node result;
|
||||||
if (iDepth<=0) {
|
if (iDepth<=0) {
|
||||||
result = GC_NEW(Node0);
|
result = GC_NEW(Node0);
|
||||||
/* result is implicitly initialized in both cases. */
|
/* result is implicitly initialized in both cases. */
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
Node left = MakeTree(iDepth-1);
|
Node left = MakeTree(iDepth-1);
|
||||||
Node right = MakeTree(iDepth-1);
|
Node right = MakeTree(iDepth-1);
|
||||||
result = GC_NEW(Node0);
|
result = GC_NEW(Node0);
|
||||||
init_Node(result, left, right);
|
init_Node(result, left, right);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintDiagnostics() {
|
static void PrintDiagnostics() {
|
||||||
#if 0
|
#if 0
|
||||||
long lFreeMemory = Runtime.getRuntime().freeMemory();
|
long lFreeMemory = Runtime.getRuntime().freeMemory();
|
||||||
long lTotalMemory = Runtime.getRuntime().totalMemory();
|
long lTotalMemory = Runtime.getRuntime().totalMemory();
|
||||||
|
|
||||||
System.out.print(" Total memory available="
|
System.out.print(" Total memory available="
|
||||||
+ lTotalMemory + " bytes");
|
+ lTotalMemory + " bytes");
|
||||||
System.out.println(" Free memory=" + lFreeMemory + " bytes");
|
System.out.println(" Free memory=" + lFreeMemory + " bytes");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TimeConstruction(int depth) {
|
static void TimeConstruction(int depth) {
|
||||||
long tStart, tFinish;
|
long tStart, tFinish;
|
||||||
int iNumIters = NumIters(depth);
|
int iNumIters = NumIters(depth);
|
||||||
Node tempTree;
|
Node tempTree;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("Creating %d trees of depth %d\n", iNumIters, depth);
|
printf("Creating %d trees of depth %d\n", iNumIters, depth);
|
||||||
|
|
||||||
tStart = currentTime();
|
tStart = currentTime();
|
||||||
for (i = 0; i < iNumIters; ++i) {
|
for (i = 0; i < iNumIters; ++i) {
|
||||||
tempTree = GC_NEW(Node0);
|
tempTree = GC_NEW(Node0);
|
||||||
Populate(depth, tempTree);
|
Populate(depth, tempTree);
|
||||||
tempTree = 0;
|
tempTree = 0;
|
||||||
}
|
}
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
printf("\tTop down construction took %d msec\n",
|
printf("\tTop down construction took %d msec\n",
|
||||||
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);
|
||||||
tempTree = 0;
|
tempTree = 0;
|
||||||
}
|
}
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
printf("\tBottom up construction took %d msec\n",
|
printf("\tBottom up construction took %d msec\n",
|
||||||
tFinish - tStart);
|
tFinish - tStart);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Node root;
|
Node root;
|
||||||
Node longLivedTree;
|
Node longLivedTree;
|
||||||
Node tempTree;
|
Node tempTree;
|
||||||
long tStart, tFinish;
|
long tStart, tFinish;
|
||||||
long tElapsed;
|
long tElapsed;
|
||||||
int i, d;
|
int i, d;
|
||||||
double *array;
|
double *array;
|
||||||
|
|
||||||
// GC_full_freq = 30;
|
// GC_full_freq = 30;
|
||||||
// GC_free_space_divisor = 16;
|
// GC_free_space_divisor = 16;
|
||||||
// GC_enable_incremental();
|
// GC_enable_incremental();
|
||||||
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) +
|
||||||
sizeof(double) * kArraySize);
|
sizeof(double) * kArraySize);
|
||||||
printf(" Stretching memory with a binary tree of depth %d\n",
|
printf(" Stretching memory with a binary tree of depth %d\n",
|
||||||
kStretchTreeDepth);
|
kStretchTreeDepth);
|
||||||
PrintDiagnostics();
|
PrintDiagnostics();
|
||||||
# ifdef PROFIL
|
# ifdef PROFIL
|
||||||
init_profiling();
|
init_profiling();
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
tStart = currentTime();
|
tStart = currentTime();
|
||||||
|
|
||||||
// Stretch the memory space quickly
|
// Stretch the memory space quickly
|
||||||
tempTree = MakeTree(kStretchTreeDepth);
|
tempTree = MakeTree(kStretchTreeDepth);
|
||||||
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);
|
||||||
longLivedTree = GC_NEW(Node0);
|
longLivedTree = GC_NEW(Node0);
|
||||||
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);
|
||||||
array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
|
array = GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
|
||||||
for (i = 0; i < kArraySize/2; ++i) {
|
for (i = 0; i < kArraySize/2; ++i) {
|
||||||
array[i] = 1.0/i;
|
array[i] = 1.0/i;
|
||||||
}
|
}
|
||||||
PrintDiagnostics();
|
PrintDiagnostics();
|
||||||
|
|
||||||
for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
|
for (d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
|
||||||
TimeConstruction(d);
|
TimeConstruction(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (longLivedTree == 0 || array[1000] != 1.0/1000)
|
if (longLivedTree == 0 || array[1000] != 1.0/1000)
|
||||||
fprintf(stderr, "Failed\n");
|
fprintf(stderr, "Failed\n");
|
||||||
// fake reference to LongLivedTree
|
// fake reference to LongLivedTree
|
||||||
// and array
|
// and array
|
||||||
// to keep them from being optimized away
|
// to keep them from being optimized away
|
||||||
|
|
||||||
tFinish = currentTime();
|
tFinish = currentTime();
|
||||||
tElapsed = tFinish - tStart;
|
tElapsed = tFinish - tStart;
|
||||||
PrintDiagnostics();
|
PrintDiagnostics();
|
||||||
printf("Completed in %d msec\n", tElapsed);
|
printf("Completed in %d msec\n", tElapsed);
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue