aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-03-27 16:37:12 +0000
committerEvan Huus <eapache@gmail.com>2013-03-27 16:37:12 +0000
commit0d2e02954f2452ca05f8f884044380077a941dd8 (patch)
tree4f9a79483cd7acd0ff53b832f57a21e45e20ecbe
parent9ace098f37d547b649adb78741951d4863763c83 (diff)
Add a timing test to check that the block allocator is actually faster than the
simple one. At the moment it seems to be between 2x and 2.5x faster in the common case (a simple sequence of allocations followed by free_all). svn path=/trunk/; revision=48588
-rw-r--r--epan/wmem/wmem_test.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c
index aa4d904444..20604cdb0f 100644
--- a/epan/wmem/wmem_test.c
+++ b/epan/wmem/wmem_test.c
@@ -174,6 +174,47 @@ wmem_test_allocator(wmem_allocator_type_t type, wmem_verify_func verify)
}
static void
+wmem_time_allocator(wmem_allocator_type_t type)
+{
+ int i;
+ wmem_allocator_t *allocator;
+
+ allocator = wmem_allocator_force_new(type);
+
+ for (i=0; i<MAX_SIMULTANEOUS_ALLOCS; i++) {
+ wmem_alloc(allocator, 8);
+ }
+ wmem_free_all(allocator);
+
+ for (i=0; i<MAX_SIMULTANEOUS_ALLOCS; i++) {
+ wmem_alloc(allocator, 256);
+ }
+ wmem_free_all(allocator);
+
+ for (i=0; i<MAX_SIMULTANEOUS_ALLOCS; i++) {
+ wmem_alloc(allocator, 1024);
+ }
+
+ wmem_destroy_allocator(allocator);
+}
+
+static void
+wmem_time_allocators(void)
+{
+ double simple_time, block_time;
+
+ g_test_timer_start();
+ wmem_time_allocator(WMEM_ALLOCATOR_SIMPLE);
+ simple_time = g_test_timer_elapsed();
+
+ g_test_timer_start();
+ wmem_time_allocator(WMEM_ALLOCATOR_BLOCK);
+ block_time = g_test_timer_elapsed();
+
+ g_assert(simple_time > block_time);
+}
+
+static void
wmem_test_allocator_block(void)
{
wmem_test_allocator(WMEM_ALLOCATOR_BLOCK, &wmem_block_verify);
@@ -199,6 +240,7 @@ main(int argc, char **argv)
g_test_add_func("/wmem/allocator/block", wmem_test_allocator_block);
g_test_add_func("/wmem/allocator/simple", wmem_test_allocator_simple);
g_test_add_func("/wmem/allocator/strict", wmem_test_allocator_strict);
+ g_test_add_func("/wmem/allocator/times", wmem_time_allocators);
return g_test_run();
}