aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-05 18:25:13 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-05 18:25:13 +0000
commit13ba689e07c82f7803bcaf448e48bdb78fdd543d (patch)
tree35940b1bc11497801e7c10359f91ca4440625d29
parentf2d8ad8d000772fff31a5062513550dce48db149 (diff)
downloadrspamd-13ba689e07c82f7803bcaf448e48bdb78fdd543d.tar.gz
rspamd-13ba689e07c82f7803bcaf448e48bdb78fdd543d.zip
Fix clock_gettime invocation.
-rw-r--r--test/rspamd_http_test.c31
-rw-r--r--test/rspamd_radix_test.c37
-rw-r--r--test/rspamd_shingles_test.c8
3 files changed, 33 insertions, 43 deletions
diff --git a/test/rspamd_http_test.c b/test/rspamd_http_test.c
index 9bd570600..ab465638c 100644
--- a/test/rspamd_http_test.c
+++ b/test/rspamd_http_test.c
@@ -104,7 +104,7 @@ rspamd_client_body (struct rspamd_http_connection *conn,
struct client_cbdata {
double *lat;
- struct timespec ts;
+ gdouble ts;
};
static void
@@ -125,9 +125,7 @@ rspamd_client_finish (struct rspamd_http_connection *conn,
struct client_cbdata *cb = conn->ud;
struct timespec ts;
- clock_gettime (CLOCK_MONOTONIC, &ts);
- *(cb->lat) = (ts.tv_sec - cb->ts.tv_sec) * 1000. + /* Seconds */
- (ts.tv_nsec - cb->ts.tv_nsec) / 1000000.; /* Nanoseconds */
+ *(cb->lat) = rspamd_get_ticks () * 1000.;
close (conn->fd);
rspamd_http_connection_unref (conn);
g_free (cb);
@@ -162,7 +160,7 @@ rspamd_http_client_func (const gchar *path, rspamd_inet_addr_t *addr,
}
cb = g_malloc (sizeof (*cb));
- clock_gettime (CLOCK_MONOTONIC, &cb->ts);
+ cb->ts = rspamd_get_ticks ();
cb->lat = latency;
rspamd_http_connection_write_message (conn, msg, NULL, NULL, cb,
fd, NULL, ev_base);
@@ -209,7 +207,7 @@ rspamd_http_test_func (void)
struct rspamd_keypair_cache *c;
rspamd_mempool_mutex_t *mtx;
rspamd_inet_addr_t addr;
- struct timespec ts1, ts2;
+ gdouble ts1, ts2;
gchar filepath[PATH_MAX], buf[512];
gint fd, i, j;
pid_t sfd;
@@ -250,11 +248,10 @@ rspamd_http_test_func (void)
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
NULL, NULL, c, ev_base, &latency[i * pconns + j]);
}
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
event_base_loop (ev_base, 0);
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
total_diff += diff;
}
@@ -279,11 +276,10 @@ rspamd_http_test_func (void)
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
client_key, peer_key, c, ev_base, &latency[i * pconns + j]);
}
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
event_base_loop (ev_base, 0);
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
total_diff += diff;
}
@@ -314,11 +310,10 @@ rspamd_http_test_func (void)
rspamd_http_client_func (filepath + sizeof ("/tmp") - 1, &addr,
client_key, peer_key, c, ev_base, &latency[i * pconns + j]);
}
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
event_base_loop (ev_base, 0);
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
total_diff += diff;
}
diff --git a/test/rspamd_radix_test.c b/test/rspamd_radix_test.c
index b3d67465a..388f95a9a 100644
--- a/test/rspamd_radix_test.c
+++ b/test/rspamd_radix_test.c
@@ -153,7 +153,7 @@ rspamd_radix_test_func (void)
gsize nelts, i;
gint lc;
gboolean all_good = TRUE;
- struct timespec ts1, ts2;
+ gdouble ts1, ts2;
double diff;
/* Test suite for the compressed trie */
@@ -171,54 +171,50 @@ rspamd_radix_test_func (void)
}
#if 0
msg_info ("old radix performance (%z elts)", nelts);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
for (i = 0; i < nelts; i ++) {
guint32 mask = G_MAXUINT32 << (32 - addrs[i].mask);
radix32tree_insert (tree, addrs[i].addr, mask, 1);
}
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
msg_info ("Added %z elements in %.6f ms", nelts, diff);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
for (lc = 0; lc < lookup_cycles; lc ++) {
for (i = 0; i < nelts; i ++) {
g_assert (radix32tree_find (tree, addrs[i].addr) != RADIX_NO_VALUE);
}
}
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
msg_info ("Checked %z elements in %.6f ms", nelts, diff);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
for (i = 0; i < nelts; i ++) {
radix32tree_delete (tree, addrs[i].addr, addrs[i].mask);
}
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.;
msg_info ("Deleted %z elements in %.6f ms", nelts, diff);
radix_tree_free (tree);
#endif
msg_info ("new radix performance (%z elts)", nelts);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
for (i = 0; i < nelts; i ++) {
radix_insert_compressed (comp_tree, addrs[i].addr6, sizeof (addrs[i].addr6),
128 - addrs[i].mask6, i);
}
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
msg_info ("Added %z elements in %.6f ms", nelts, diff);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
for (lc = 0; lc < lookup_cycles; lc ++) {
for (i = 0; i < nelts; i ++) {
if (radix_find_compressed (comp_tree, addrs[i].addr6, sizeof (addrs[i].addr6))
@@ -241,9 +237,8 @@ rspamd_radix_test_func (void)
#endif
g_assert (all_good);
- clock_gettime (CLOCK_MONOTONIC, &ts2);
- diff = (ts2.tv_sec - ts1.tv_sec) * 1000. + /* Seconds */
- (ts2.tv_nsec - ts1.tv_nsec) / 1000000.; /* Nanoseconds */
+ ts2 = rspamd_get_ticks ();
+ diff = (ts2 - ts1) * 1000.0;
msg_info ("Checked %z elements in %.6f ms", nelts, diff);
radix_destroy_compressed (comp_tree);
diff --git a/test/rspamd_shingles_test.c b/test/rspamd_shingles_test.c
index e6cd0abb3..1a96b64bc 100644
--- a/test/rspamd_shingles_test.c
+++ b/test/rspamd_shingles_test.c
@@ -93,14 +93,14 @@ 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;
+ gdouble ts1, ts2;
ottery_rand_bytes (key, sizeof (key));
input = generate_fuzzy_words (cnt, max_len);
- clock_gettime (CLOCK_MONOTONIC, &ts1);
+ ts1 = rspamd_get_ticks ();
sgl = rspamd_shingles_generate (input, key, NULL,
rspamd_shingles_default_filter, NULL);
- clock_gettime (CLOCK_MONOTONIC, &ts2);
+ ts2 = rspamd_get_ticks ();
permute_vector (input, perm_factor);
sgl_permuted = rspamd_shingles_generate (input, key, NULL,
rspamd_shingles_default_filter, NULL);
@@ -108,7 +108,7 @@ test_case (gsize cnt, gsize max_len, gdouble perm_factor)
res = rspamd_shingles_compare (sgl, sgl_permuted);
msg_debug ("percentage of common shingles: %.3f, generate time: %hd usec",
- res, ts_to_usec (&ts2) - ts_to_usec (&ts1));
+ res, (gint)(ts1 - ts2) * 1000);
g_assert_cmpfloat (fabs ((1.0 - res) - sqrt (perm_factor)), <=, 0.20);
free_fuzzy_words (input);