struct client_cbdata {
double *lat;
- struct timespec ts;
+ gdouble ts;
};
static void
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);
}
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);
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;
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;
}
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;
}
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;
}
gsize nelts, i;
gint lc;
gboolean all_good = TRUE;
- struct timespec ts1, ts2;
+ gdouble ts1, ts2;
double diff;
/* Test suite for the compressed trie */
}
#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))
#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);
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);
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);