diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-02-09 17:02:57 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2011-03-01 15:19:15 +0000 |
commit | cfeab391c90f531ab99625347b35656b1782360c (patch) | |
tree | a129577aed791d8836388748f835cb7eb26020b0 | |
parent | dd30235ef2e63296fbfd6745dfff6279bd174fba (diff) |
Split the mempool test into a separate executable. Run more iterations.split-mempool-perf-test
-rw-r--r-- | dbus/.gitignore | 1 | ||||
-rw-r--r-- | dbus/Makefile.am | 8 | ||||
-rw-r--r-- | dbus/dbus-mempool.c | 2 | ||||
-rw-r--r-- | dbus/test-mempool.c | 203 |
4 files changed, 212 insertions, 2 deletions
diff --git a/dbus/.gitignore b/dbus/.gitignore index 34eace4d..19d31bbe 100644 --- a/dbus/.gitignore +++ b/dbus/.gitignore @@ -15,3 +15,4 @@ dbus-glib-error-enum.h *.gcno *.gcda versioninfo.rc +test-mempool diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 740def3e..880f2704 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -272,7 +272,9 @@ libdbus_internal_la_LDFLAGS=$(export_symbols_internal) @R_DYNAMIC_LDFLAG@ ## TESTS if DBUS_BUILD_TESTS TESTS_ENVIRONMENT=DBUS_TEST_DATA=$(top_builddir)/test/data DBUS_TEST_HOMEDIR=$(top_builddir)/dbus -TESTS=dbus-test +TESTS = \ + test-mempool \ + dbus-test else TESTS= endif @@ -281,6 +283,10 @@ endif ## even when not doing "make check" noinst_PROGRAMS=$(TESTS) +test_mempool_LDADD = libdbus-internal.la $(DBUS_TEST_LIBS) +test_mempool_LDFLAGS = @R_DYNAMIC_LDFLAG@ +test_mempool_SOURCES = test-mempool.c + dbus_test_SOURCES= \ dbus-test-main.c diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c index 563bffc6..9613c615 100644 --- a/dbus/dbus-mempool.c +++ b/dbus/dbus-mempool.c @@ -447,7 +447,7 @@ time_for_size (int size) clock_t start; clock_t end; #define FREE_ARRAY_SIZE 512 -#define N_ITERATIONS FREE_ARRAY_SIZE * 512 +#define N_ITERATIONS FREE_ARRAY_SIZE * 512 * 100 void *to_free[FREE_ARRAY_SIZE]; DBusMemPool *pool; diff --git a/dbus/test-mempool.c b/dbus/test-mempool.c new file mode 100644 index 00000000..230ddaf7 --- /dev/null +++ b/dbus/test-mempool.c @@ -0,0 +1,203 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-mempool.h Memory pools + * + * Copyright (C) 2002, 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <config.h> +#include "dbus-mempool.h" +#include "dbus-internals.h" +#include "dbus-test.h" + +#include <stdio.h> +#include <time.h> + +static void +time_for_size (int size) +{ + int i; + int j; + clock_t start; + clock_t end; +#define FREE_ARRAY_SIZE 512 +#define N_ITERATIONS FREE_ARRAY_SIZE * 512 * 10 + void *to_free[FREE_ARRAY_SIZE]; + DBusMemPool *pool; + + _dbus_verbose ("Timings for size %d\n", size); + + _dbus_verbose (" malloc\n"); + + start = clock (); + + i = 0; + j = 0; + while (i < N_ITERATIONS) + { + to_free[j] = dbus_malloc (size); + _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */ + + ++j; + + if (j == FREE_ARRAY_SIZE) + { + j = 0; + while (j < FREE_ARRAY_SIZE) + { + dbus_free (to_free[j]); + ++j; + } + + j = 0; + } + + ++i; + } + + end = clock (); + + _dbus_verbose (" created/destroyed %d elements in %g seconds\n", + N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC); + + + + _dbus_verbose (" mempools\n"); + + start = clock (); + + pool = _dbus_mem_pool_new (size, FALSE); + + i = 0; + j = 0; + while (i < N_ITERATIONS) + { + to_free[j] = _dbus_mem_pool_alloc (pool); + _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */ + + ++j; + + if (j == FREE_ARRAY_SIZE) + { + j = 0; + while (j < FREE_ARRAY_SIZE) + { + _dbus_mem_pool_dealloc (pool, to_free[j]); + ++j; + } + + j = 0; + } + + ++i; + } + + _dbus_mem_pool_free (pool); + + end = clock (); + + _dbus_verbose (" created/destroyed %d elements in %g seconds\n", + N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC); + + _dbus_verbose (" zeroed malloc\n"); + + start = clock (); + + i = 0; + j = 0; + while (i < N_ITERATIONS) + { + to_free[j] = dbus_malloc0 (size); + _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */ + + ++j; + + if (j == FREE_ARRAY_SIZE) + { + j = 0; + while (j < FREE_ARRAY_SIZE) + { + dbus_free (to_free[j]); + ++j; + } + + j = 0; + } + + ++i; + } + + end = clock (); + + _dbus_verbose (" created/destroyed %d elements in %g seconds\n", + N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC); + + _dbus_verbose (" zeroed mempools\n"); + + start = clock (); + + pool = _dbus_mem_pool_new (size, TRUE); + + i = 0; + j = 0; + while (i < N_ITERATIONS) + { + to_free[j] = _dbus_mem_pool_alloc (pool); + _dbus_assert (to_free[j] != NULL); /* in a real app of course this is wrong */ + + ++j; + + if (j == FREE_ARRAY_SIZE) + { + j = 0; + while (j < FREE_ARRAY_SIZE) + { + _dbus_mem_pool_dealloc (pool, to_free[j]); + ++j; + } + + j = 0; + } + + ++i; + } + + _dbus_mem_pool_free (pool); + + end = clock (); + + _dbus_verbose (" created/destroyed %d elements in %g seconds\n", + N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC); +} + +int +main (void) +{ + int i; + int element_sizes[] = { 4, 8, 16, 50, 124 }; + + i = 0; + while (i < _DBUS_N_ELEMENTS (element_sizes)) + { + time_for_size (element_sizes[i]); + ++i; + } + + return 0; +} |