From 586a9be55759e667ab0532fa89a19b2341e35970 Mon Sep 17 00:00:00 2001 From: Brian Barrett Date: Wed, 9 Nov 2005 18:20:08 +0000 Subject: [PATCH] * make it easier to compare free timings with / without memory hooks enabled This commit was SVN r8059. --- test/memory/Makefile.am | 9 +-- test/memory/opal_memory_speed.c | 106 ++++++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 12 deletions(-) diff --git a/test/memory/Makefile.am b/test/memory/Makefile.am index 8d771b2ec1..666d791473 100644 --- a/test/memory/Makefile.am +++ b/test/memory/Makefile.am @@ -29,20 +29,17 @@ TESTS = \ opal_memory_basic_SOURCES = opal_memory_basic.c opal_memory_basic_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_basic_LDADD = \ - $(top_builddir)/opal/libopal.la \ - $(top_builddir)/test/support/libsupport.a + $(top_builddir)/opal/libopal.la opal_memory_basic_DEPENDENCIES = $(opal_memory_basic_LDADD) opal_memory_speed_SOURCES = opal_memory_speed.c opal_memory_speed_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_speed_LDADD = \ - $(top_builddir)/opal/libopal.la \ - $(top_builddir)/test/support/libsupport.a + $(top_builddir)/opal/libopal.la opal_memory_speed_DEPENDENCIES = $(opal_memory_speed_LDADD) opal_memory_cxx_SOURCES = opal_memory_cxx.cc opal_memory_cxx_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS) opal_memory_cxx_LDADD = \ - $(top_builddir)/opal/libopal.la \ - $(top_builddir)/test/support/libsupport.a + $(top_builddir)/opal/libopal.la opal_memory_cxx_DEPENDENCIES = $(opal_memory_cxx_LDADD) diff --git a/test/memory/opal_memory_speed.c b/test/memory/opal_memory_speed.c index 2d89f37e7e..1da6e079ca 100644 --- a/test/memory/opal_memory_speed.c +++ b/test/memory/opal_memory_speed.c @@ -26,26 +26,40 @@ #include "opal/runtime/opal.h" #include "opal/memory/memory.h" -#define iters 10000 +#define iters 100000 +#define mask 0xfff static void* ptrs[iters]; +static void +callback(void *buf, size_t length, void *cbdata) +{ +} + int main(int argc, char *argv[]) { - int i; + int i, retval; struct timeval start, end; 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); for (i = 0 ; i < iters ; ++i) { - /* malloc out a random size from 1 to 256 bytes */ - ptrs[i] = malloc((rand() & 0xff) + 1); + /* 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", + 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) { @@ -54,8 +68,88 @@ main(int argc, char *argv[]) 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", + 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); + + 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; }