diff options
Diffstat (limited to 'dbus/dbus-mempool.c')
-rw-r--r-- | dbus/dbus-mempool.c | 199 |
1 files changed, 2 insertions, 197 deletions
diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c index 638799e1..83aa2722 100644 --- a/dbus/dbus-mempool.c +++ b/dbus/dbus-mempool.c @@ -2,6 +2,8 @@ /* dbus-mempool.h Memory pools * * Copyright (C) 2002, 2003 Red Hat, Inc. + * Copyright (C) 2003 CodeFactory AB + * Copyright (C) 2011-2012 Collabora Ltd. * * Licensed under the Academic Free License version 2.1 * @@ -448,200 +450,3 @@ _dbus_mem_pool_get_stats (DBusMemPool *pool, #endif /* DBUS_ENABLE_STATS */ /** @} */ - -#ifdef DBUS_ENABLE_EMBEDDED_TESTS -#include "dbus-test.h" -#include <stdio.h> -#include <time.h> - -static void -time_for_size (int size) -{ - int i; - int j; -#ifdef DBUS_ENABLE_VERBOSE_MODE - clock_t start; - clock_t end; -#endif -#define FREE_ARRAY_SIZE 512 -#define N_ITERATIONS FREE_ARRAY_SIZE * 512 - void *to_free[FREE_ARRAY_SIZE]; - DBusMemPool *pool; - - _dbus_verbose ("Timings for size %d\n", size); - - _dbus_verbose (" malloc\n"); - -#ifdef DBUS_ENABLE_VERBOSE_MODE - start = clock (); -#endif - - 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; - } - -#ifdef DBUS_ENABLE_VERBOSE_MODE - 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 (); -#endif - - 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); - -#ifdef DBUS_ENABLE_VERBOSE_MODE - 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 (); -#endif - - 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; - } - -#ifdef DBUS_ENABLE_VERBOSE_MODE - 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 (); -#endif - - 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); - -#ifdef DBUS_ENABLE_VERBOSE_MODE - end = clock (); - - _dbus_verbose (" created/destroyed %d elements in %g seconds\n", - N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC); -#endif -} - -/** - * @ingroup DBusMemPoolInternals - * Unit test for DBusMemPool - * @returns #TRUE on success. - */ -dbus_bool_t -_dbus_mem_pool_test (const char *test_data_dir _DBUS_GNUC_UNUSED) -{ - 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 TRUE; -} - -#endif /* DBUS_ENABLE_EMBEDDED_TESTS */ |