1
1

* make it easier to compare free timings with / without memory hooks enabled

This commit was SVN r8059.
Этот коммит содержится в:
Brian Barrett 2005-11-09 18:20:08 +00:00
родитель 05f8785e4f
Коммит 586a9be557
2 изменённых файлов: 103 добавлений и 12 удалений

Просмотреть файл

@ -29,20 +29,17 @@ TESTS = \
opal_memory_basic_SOURCES = opal_memory_basic.c opal_memory_basic_SOURCES = opal_memory_basic.c
opal_memory_basic_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_basic_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
opal_memory_basic_LDADD = \ opal_memory_basic_LDADD = \
$(top_builddir)/opal/libopal.la \ $(top_builddir)/opal/libopal.la
$(top_builddir)/test/support/libsupport.a
opal_memory_basic_DEPENDENCIES = $(opal_memory_basic_LDADD) opal_memory_basic_DEPENDENCIES = $(opal_memory_basic_LDADD)
opal_memory_speed_SOURCES = opal_memory_speed.c opal_memory_speed_SOURCES = opal_memory_speed.c
opal_memory_speed_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_speed_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
opal_memory_speed_LDADD = \ opal_memory_speed_LDADD = \
$(top_builddir)/opal/libopal.la \ $(top_builddir)/opal/libopal.la
$(top_builddir)/test/support/libsupport.a
opal_memory_speed_DEPENDENCIES = $(opal_memory_speed_LDADD) opal_memory_speed_DEPENDENCIES = $(opal_memory_speed_LDADD)
opal_memory_cxx_SOURCES = opal_memory_cxx.cc opal_memory_cxx_SOURCES = opal_memory_cxx.cc
opal_memory_cxx_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_cxx_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
opal_memory_cxx_LDADD = \ opal_memory_cxx_LDADD = \
$(top_builddir)/opal/libopal.la \ $(top_builddir)/opal/libopal.la
$(top_builddir)/test/support/libsupport.a
opal_memory_cxx_DEPENDENCIES = $(opal_memory_cxx_LDADD) opal_memory_cxx_DEPENDENCIES = $(opal_memory_cxx_LDADD)

Просмотреть файл

@ -26,26 +26,40 @@
#include "opal/runtime/opal.h" #include "opal/runtime/opal.h"
#include "opal/memory/memory.h" #include "opal/memory/memory.h"
#define iters 10000 #define iters 100000
#define mask 0xfff
static void* ptrs[iters]; static void* ptrs[iters];
static void
callback(void *buf, size_t length, void *cbdata)
{
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i; int i, retval;
struct timeval start, end; struct timeval start, end;
long time; long time;
opal_init();
if (!opal_mem_free_is_supported()) {
printf("no memory registration supported. skipping\n");
return 77;
}
printf("speed without a handler:\n");
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) { for (i = 0 ; i < iters ; ++i) {
/* malloc out a random size from 1 to 256 bytes */ /* malloc out a random size */
ptrs[i] = malloc((rand() & 0xff) + 1); ptrs[i] = malloc((rand() & mask) + 1);
} }
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) + time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec); (end.tv_usec - start.tv_usec);
printf("malloc: %d calls in %ld microseconds. %lf microseconds/call\n", printf(" malloc: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters); iters, time, (double) time / iters);
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) { for (i = 0 ; i < iters ; ++i) {
@ -54,8 +68,88 @@ main(int argc, char *argv[])
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) + time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec); (end.tv_usec - start.tv_usec);
printf("free: %d calls in %ld microseconds. %lf microseconds/call\n", printf(" free: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters); iters, time, (double) time / iters);
printf("speed with empty handler:\n");
retval = opal_mem_free_register_handler(callback, NULL);
if (retval != OMPI_SUCCESS) {
printf("handler registration failed\n");
return retval;
}
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
/* malloc out a random size */
ptrs[i] = malloc((rand() & mask) + 1);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" malloc: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
free(ptrs[i]);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" free: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
opal_mem_free_unregister_handler(callback);
printf("speed without a handler:\n");
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
/* malloc out a random size */
ptrs[i] = malloc((rand() & mask) + 1);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" malloc: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
free(ptrs[i]);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" free: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
printf("speed with empty handler:\n");
retval = opal_mem_free_register_handler(callback, NULL);
if (retval != OMPI_SUCCESS) {
printf("handler registration failed\n");
return retval;
}
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
/* malloc out a random size */
ptrs[i] = malloc((rand() & mask) + 1);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" malloc: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
gettimeofday(&start, NULL);
for (i = 0 ; i < iters ; ++i) {
free(ptrs[i]);
}
gettimeofday(&end, NULL);
time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) +
(end.tv_usec - start.tv_usec);
printf(" free: %d calls in %ld microseconds. %lf microseconds/call\n",
iters, time, (double) time / iters);
opal_mem_free_unregister_handler(callback);
opal_finalize();
return 0; return 0;
} }