summaryrefslogtreecommitdiffstats
path: root/bench/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-10-23 18:45:56 +0000
committerTavian Barnes <tavianator@gmail.com>2009-10-23 18:45:56 +0000
commit1742345f241268e493dcbfe4b54e62c77ccbfadc (patch)
tree1ca4037a6120e461eb28764b2c7942735b5cf04b /bench/libdimension
parentd7c2ee8dbdf9f79588b2d6b2f2d34861638ae231 (diff)
downloaddimension-1742345f241268e493dcbfe4b54e62c77ccbfadc.tar.xz
Upgrade benchmarks to latest libsandglass.
Diffstat (limited to 'bench/libdimension')
-rw-r--r--bench/libdimension/array.c85
-rw-r--r--bench/libdimension/geometry.c48
-rw-r--r--bench/libdimension/kD_splay_tree.c52
3 files changed, 53 insertions, 132 deletions
diff --git a/bench/libdimension/array.c b/bench/libdimension/array.c
index 692fae3..1909b85 100644
--- a/bench/libdimension/array.c
+++ b/bench/libdimension/array.c
@@ -33,7 +33,7 @@ main()
const unsigned int count = 32;
sandglass_t sandglass;
- sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_REALTICKS };
+ sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
@@ -41,7 +41,7 @@ main()
}
/* Benchmark allocation and deallocation */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
array = dmnsn_new_array(sizeof(object));
dmnsn_delete_array(array);
});
@@ -54,79 +54,43 @@ main()
printf("dmnsn_array_push():");
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
for (i = 0; i < count; ++i) {
- sandglass_begin(&sandglass);
- dmnsn_array_push(array, &object);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
-
+ sandglass_bench_noprecache(&sandglass, dmnsn_array_push(array, &object));
printf(" %ld", sandglass.grains);
}
printf("\n");
/* dmnsn_array_get() */
- sandglass_bench(&sandglass, dmnsn_array_get(array, count/2, &object));
+ sandglass_bench_fine(&sandglass, dmnsn_array_get(array, count/2, &object));
printf("dmnsn_array_get(): %ld\n", sandglass.grains);
/* dmnsn_array_set() */
- sandglass_bench(&sandglass, dmnsn_array_set(array, count/2, &object));
+ sandglass_bench_fine(&sandglass, dmnsn_array_set(array, count/2, &object));
printf("dmnsn_array_set(): %ld\n", sandglass.grains);
/* dmnsn_array_at() */
- sandglass_bench(&sandglass, ptr = dmnsn_array_at(array, count/2));
+ sandglass_bench_fine(&sandglass, ptr = dmnsn_array_at(array, count/2));
printf("dmnsn_array_at(): %ld\n", sandglass.grains);
/* dmnsn_array_size() */
- sandglass_bench(&sandglass, size = dmnsn_array_size(array));
+ sandglass_bench_fine(&sandglass, size = dmnsn_array_size(array));
printf("dmnsn_array_size(): %ld\n", sandglass.grains);
/* dmnsn_array_resize() */
-
dmnsn_array_resize(array, count);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
- sandglass_begin(&sandglass);
- dmnsn_array_resize(array, count * 2);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
+ sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count * 2));
printf("dmnsn_array_resize(): %ld", sandglass.grains);
- sandglass_begin(&sandglass);
- dmnsn_array_resize(array, count);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
+ sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count));
printf(" %ld\n", sandglass.grains);
/* dmnsn_array_insert() */
printf("dmnsn_array_insert():");
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
for (i = 0; i < count; ++i) {
- sandglass_begin(&sandglass);
- dmnsn_array_insert(array, count/2, &object);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
-
+ sandglass_bench_noprecache(&sandglass,
+ dmnsn_array_insert(array, count/2, &object));
printf(" %ld", sandglass.grains);
}
printf("\n");
@@ -135,19 +99,9 @@ main()
printf("dmnsn_array_remove():");
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
for (i = 0; i < count; ++i) {
- sandglass_begin(&sandglass);
- dmnsn_array_remove(array, count/2);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
-
+ sandglass_bench_noprecache(&sandglass,
+ dmnsn_array_remove(array, count/2));
printf(" %ld", sandglass.grains);
}
printf("\n");
@@ -156,19 +110,8 @@ main()
printf("dmnsn_array_pop():");
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
for (i = 0; i < count; ++i) {
- sandglass_begin(&sandglass);
- dmnsn_array_pop(array, &object);
- sandglass_elapse(&sandglass);
- sandglass.grains -= sandglass.baseline;
-
+ sandglass_bench_noprecache(&sandglass, dmnsn_array_pop(array, &object));
printf(" %ld", sandglass.grains);
}
printf("\n");
diff --git a/bench/libdimension/geometry.c b/bench/libdimension/geometry.c
index 074f34c..a80c0ff 100644
--- a/bench/libdimension/geometry.c
+++ b/bench/libdimension/geometry.c
@@ -30,7 +30,7 @@ main()
double result;
sandglass_t sandglass;
- sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_REALTICKS };
+ sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
if (sandglass_create(&sandglass, &attr, &attr) != 0) {
perror("sandglass_create()");
@@ -38,13 +38,13 @@ main()
}
/* dmnsn_vector_construct() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_construct(1.0, 2.0, 3.0);
});
printf("dmnsn_vector_construct(): %ld\n", sandglass.grains);
/* dmnsn_matrix_construct() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_matrix_construct(1.0, 1.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0,
0.0, 1.0, 1.0, 0.0,
@@ -53,86 +53,86 @@ main()
printf("dmnsn_matrix_construct(): %ld\n", sandglass.grains);
/* dmnsn_identity_matrix() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_identity_matrix();
});
printf("dmnsn_identity_matrix(): %ld\n", sandglass.grains);
/* dmnsn_scale_matrix() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_scale_matrix(vector);
});
printf("dmnsn_scale_matrix(): %ld\n", sandglass.grains);
/* dmnsn_identity_matrix() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_translation_matrix(vector);
});
printf("dmnsn_translation_matrix(): %ld\n", sandglass.grains);
/* dmnsn_rotation_matrix() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_rotation_matrix(vector);
});
printf("dmnsn_rotation_matrix(): %ld\n", sandglass.grains);
/* dmnsn_line_construct() */
vector2 = dmnsn_vector_construct(3.0, 2.0, 1.0);
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
line = dmnsn_line_construct(vector, vector2);
});
printf("dmnsn_line_construct(): %ld\n", sandglass.grains);
/* dmnsn_vector_add() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_add(vector, vector2);
});
printf("dmnsn_vector_add(): %ld\n", sandglass.grains);
/* dmnsn_vector_sub() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_sub(vector, vector2);
});
printf("dmnsn_vector_sub(): %ld\n", sandglass.grains);
/* dmnsn_vector_mul() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_mul(2.0, vector);
});
printf("dmnsn_vector_mul(): %ld\n", sandglass.grains);
/* dmnsn_vector_div() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_div(vector, 2.0);
});
printf("dmnsn_vector_div(): %ld\n", sandglass.grains);
/* dmnsn_vector_cross() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_cross(vector, vector2);
});
printf("dmnsn_vector_cross(): %ld\n", sandglass.grains);
/* dmnsn_vector_dot() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
result = dmnsn_vector_dot(vector, vector2);
});
printf("dmnsn_vector_dot(): %ld\n", sandglass.grains);
/* dmnsn_vector_norm() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
result = dmnsn_vector_norm(vector);
});
printf("dmnsn_vector_norm(): %ld\n", sandglass.grains);
/* dmnsn_vector_normalize() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_vector_normalize(vector);
});
printf("dmnsn_vector_normalize(): %ld\n", sandglass.grains);
/* dmnsn_matrix_inverse() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_matrix_inverse(matrix);
});
printf("dmnsn_matrix_inverse(): %ld\n", sandglass.grains);
@@ -142,37 +142,37 @@ main()
1.0, 1.0, 1.0, 0.0,
0.0, 1.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
- sandglass_bench(&sandglass, {
- matrix2 = dmnsn_matrix_inverse(matrix2);
+ sandglass_bench_fine(&sandglass, {
+ matrix = dmnsn_matrix_inverse(matrix2);
});
printf("dmnsn_matrix_inverse(HARD): %ld\n", sandglass.grains);
/* dmnsn_matrix_mul() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
matrix = dmnsn_matrix_mul(matrix, matrix2);
});
printf("dmnsn_matrix_mul(): %ld\n", sandglass.grains);
/* dmnsn_matrix_vector_mul() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_matrix_vector_mul(matrix, vector);
});
printf("dmnsn_matrix_vector_mul(): %ld\n", sandglass.grains);
/* dmnsn_matrix_line_mul() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
line = dmnsn_matrix_line_mul(matrix, line);
});
printf("dmnsn_matrix_line_mul(): %ld\n", sandglass.grains);
/* dmnsn_line_point() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
vector = dmnsn_line_point(line, result);
});
printf("dmnsn_line_point(): %ld\n", sandglass.grains);
/* dmnsn_line_index() */
- sandglass_bench(&sandglass, {
+ sandglass_bench_fine(&sandglass, {
result = dmnsn_line_index(line, vector);
});
printf("dmnsn_line_index(): %ld\n", sandglass.grains);
diff --git a/bench/libdimension/kD_splay_tree.c b/bench/libdimension/kD_splay_tree.c
index d6d0936..63edb0f 100644
--- a/bench/libdimension/kD_splay_tree.c
+++ b/bench/libdimension/kD_splay_tree.c
@@ -47,13 +47,12 @@ int
main()
{
dmnsn_kD_splay_tree *tree;
- dmnsn_object *object;
- dmnsn_array *objects;
- dmnsn_intersection *intersection;
+ dmnsn_intersection *intersection;
dmnsn_line ray;
+ const unsigned int nobjects = 128;
+ dmnsn_object *objects[nobjects];
unsigned int i;
long grains;
- const unsigned int nobjects = 128;
sandglass_t sandglass;
sandglass_attributes_t attr = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
@@ -64,39 +63,27 @@ main()
}
tree = dmnsn_new_kD_splay_tree();
- objects = dmnsn_new_array(sizeof(dmnsn_object *));
for (i = 0; i < nobjects; ++i) {
- object = dmnsn_new_object();
- if (!object) {
+ objects[i] = dmnsn_new_object();
+ if (!objects[i]) {
fprintf(stderr, "--- Couldn't allocate object! ---\n");
return EXIT_FAILURE;
}
/* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */
- object->min = dmnsn_random_vector(dmnsn_vector_construct(-1.0, -1.0, -1.0));
- object->max = dmnsn_random_vector(object->min);
- object->intersection_fn = &dmnsn_fake_intersection_fn;
- dmnsn_array_push(objects, &object);
+ objects[i]->min =
+ dmnsn_random_vector(dmnsn_vector_construct(-1.0, -1.0, -1.0));
+ objects[i]->max = dmnsn_random_vector(objects[i]->min);
+ objects[i]->intersection_fn = &dmnsn_fake_intersection_fn;
}
/* dmnsn_kD_splay_insert() */
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
grains = 0;
for (i = 0; i < nobjects; ++i) {
- dmnsn_array_get(objects, i, &object);
-
- sandglass_begin(&sandglass);
- dmnsn_kD_splay_insert(tree, object);
- sandglass_elapse(&sandglass);
-
+ sandglass_bench_noprecache(&sandglass,
+ dmnsn_kD_splay_insert(tree, objects[i]));
sandglass.grains += grains;
grains = sandglass.grains;
}
@@ -107,27 +94,18 @@ main()
ray.x0 = dmnsn_vector_construct(0.0, 0.0, -2.0);
ray.n = dmnsn_vector_construct(0.0, 0.0, 1.0);
- dmnsn_delete_intersection((*object->intersection_fn)(object, ray));
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
-
- sandglass_begin(&sandglass);
- sandglass_elapse(&sandglass);
- sandglass.baseline = sandglass.grains;
-
- sandglass_begin(&sandglass);
+ dmnsn_delete_intersection((*objects[0]->intersection_fn)(objects[0], ray));
+ sandglass_bench_noprecache(&sandglass, {
intersection = dmnsn_kD_splay_search(tree, ray);
- sandglass_elapse(&sandglass);
+ });
dmnsn_delete_intersection(intersection);
printf("dmnsn_kD_splay_search(): %ld\n", sandglass.grains);
/* Cleanup */
dmnsn_delete_kD_splay_tree(tree);
for (i = 0; i < nobjects; ++i) {
- dmnsn_array_get(objects, i, &object);
- dmnsn_delete_object(object);
+ dmnsn_delete_object(objects[i]);
}
- dmnsn_delete_array(objects);
return EXIT_SUCCESS;
}