From: Vsevolod Stakhov Date: Fri, 19 Dec 2014 10:53:22 +0000 (+0000) Subject: Measure time for shingles generation. X-Git-Tag: 0.8.0~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=918031c506cd7e229578fdcb11c0289938205813;p=rspamd.git Measure time for shingles generation. --- diff --git a/src/libutil/util.h b/src/libutil/util.h index de723ecd3..bd2d069a1 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -244,6 +244,8 @@ gsize rspamd_strlcpy_tolower (gchar *dst, const gchar *src, gsize siz); ((dbl) - (int)(dbl)) * 1000 * 1000; \ } while (0) #define tv_to_msec(tv) ((tv)->tv_sec * 1000LLU + (tv)->tv_usec / 1000LLU) +#define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU + \ + (ts)->tv_nsec / 1000LLU) /* Compare two emails for building emails tree */ gint rspamd_emails_cmp (gconstpointer a, gconstpointer b); diff --git a/test/rspamd_shingles_test.c b/test/rspamd_shingles_test.c index 5084cd120..44bc1e789 100644 --- a/test/rspamd_shingles_test.c +++ b/test/rspamd_shingles_test.c @@ -93,18 +93,22 @@ test_case (gsize cnt, gsize max_len, gdouble perm_factor) struct rspamd_shingle *sgl, *sgl_permuted; gdouble res; guchar key[16]; + struct timespec ts1, ts2; ottery_rand_bytes (key, sizeof (key)); input = generate_fuzzy_words (cnt, max_len); + clock_gettime (CLOCK_MONOTONIC, &ts1); sgl = rspamd_shingles_generate (input, key, NULL, rspamd_shingles_default_filter, NULL); + clock_gettime (CLOCK_MONOTONIC, &ts2); permute_vector (input, perm_factor); sgl_permuted = rspamd_shingles_generate (input, key, NULL, rspamd_shingles_default_filter, NULL); res = rspamd_shingles_compare (sgl, sgl_permuted); - msg_debug ("percentage of common shingles: %.3f", res); + msg_debug ("percentage of common shingles: %.3f, generate time: %Hd usec", + res, ts_to_usec (&ts2) - ts_to_usec (&ts1)); g_assert_cmpfloat (fabs ((1.0 - res) - sqrt (perm_factor)), <=, 0.20); free_fuzzy_words (input); @@ -117,8 +121,8 @@ rspamd_shingles_test_func (void) { //test_case (5, 100, 0.5); test_case (200, 10, 0.1); - test_case (500, 100, 0.01); - test_case (5000, 200, 0.01); - test_case (5000, 100, 0); - test_case (5000, 100, 1.0); + test_case (500, 20, 0.01); + test_case (5000, 20, 0.01); + test_case (5000, 15, 0); + test_case (5000, 30, 1.0); }