diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-11 10:08:52 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-11 10:08:52 +0100 |
commit | 79726e1186c8bcb1012bb1c4ae8635154ee39ae8 (patch) | |
tree | 53ab1d9eba6ac1cc3363cd1f3b9245b928022419 /test/rspamd_heap_test.c | |
parent | 4042cbffcaf3f9e0d273806b065d18d703d4e78e (diff) | |
download | rspamd-79726e1186c8bcb1012bb1c4ae8635154ee39ae8.tar.gz rspamd-79726e1186c8bcb1012bb1c4ae8635154ee39ae8.zip |
[Test] Evaluate heap performance
Diffstat (limited to 'test/rspamd_heap_test.c')
-rw-r--r-- | test/rspamd_heap_test.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/rspamd_heap_test.c b/test/rspamd_heap_test.c index 634c648d2..56f9e0b9c 100644 --- a/test/rspamd_heap_test.c +++ b/test/rspamd_heap_test.c @@ -34,6 +34,39 @@ new_elt (guint pri) return elt; } +static gdouble +heap_nelts_test (guint nelts) +{ + struct rspamd_min_heap *heap; + struct rspamd_min_heap_elt *elts; + gdouble t1, t2; + guint i; + + heap = rspamd_min_heap_create (nelts); + /* Preallocate all elts */ + elts = g_slice_alloc (sizeof (*elts) * nelts); + + for (i = 0; i < nelts; i ++) { + elts[i].pri = ottery_rand_uint32 () % G_MAXINT32 + 1; + elts[i].idx = NULL; + } + + t1 = rspamd_get_virtual_ticks (); + for (i = 0; i < nelts; i ++) { + rspamd_min_heap_push (heap, &elts[i]); + } + + for (i = 0; i < nelts; i ++) { + (void)rspamd_min_heap_pop (heap); + } + t2 = rspamd_get_virtual_ticks (); + + g_slice_free1 (sizeof (*elts) * nelts, elts); + rspamd_min_heap_destroy (heap); + + return (t2 - t1); +} + void rspamd_heap_test_func (void) { @@ -41,6 +74,7 @@ rspamd_heap_test_func (void) struct rspamd_min_heap_elt *elt; gint i; guint prev; + gdouble t[16]; heap = rspamd_min_heap_create (32); @@ -96,4 +130,14 @@ rspamd_heap_test_func (void) rspamd_min_heap_update_elt (heap, elt, 0); elt = rspamd_min_heap_pop (heap); g_assert (elt->idx == GINT_TO_POINTER (3)); + + rspamd_min_heap_destroy (heap); + + for (i = 1; i <= G_N_ELEMENTS (t); i ++) { + t[i - 1] = heap_nelts_test (0x1 << (i + 4)); + } + + for (i = 1; i <= G_N_ELEMENTS (t); i ++) { + rspamd_printf ("Elements: %d, time: %.4f\n", 0x1 << (i + 4), t[i - 1]); + } } |