mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Convert bench_dmap to produce reasonable output.
This commit is contained in:
parent
ff93535c71
commit
4c9b6df84d
@ -61,6 +61,9 @@ perftime(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define NANOCOUNT(start,end,iters) \
|
||||
( ((double)((end)-(start))) / (iters) )
|
||||
|
||||
/** Run AES performance benchmarks. */
|
||||
static void
|
||||
bench_aes(void)
|
||||
@ -86,7 +89,7 @@ bench_aes(void)
|
||||
tor_free(b1);
|
||||
tor_free(b2);
|
||||
printf("%d bytes: %.2f nsec per byte\n", len,
|
||||
((double)(end-start))/(iters*len));
|
||||
NANOCOUNT(start, end, iters*len));
|
||||
}
|
||||
crypto_free_cipher_env(c);
|
||||
}
|
||||
@ -114,7 +117,7 @@ bench_cell_aes(void)
|
||||
}
|
||||
end = perftime();
|
||||
printf("%d bytes, misaligned by %d: %.2f nsec per byte\n", len, misalign,
|
||||
((double)(end-start))/(iters*len));
|
||||
NANOCOUNT(start, end, iters*len));
|
||||
}
|
||||
|
||||
crypto_free_cipher_env(c);
|
||||
@ -127,10 +130,10 @@ bench_dmap(void)
|
||||
{
|
||||
smartlist_t *sl = smartlist_create();
|
||||
smartlist_t *sl2 = smartlist_create();
|
||||
struct timeval start, end, pt2, pt3, pt4;
|
||||
const int iters = 10000;
|
||||
uint64_t start, end, pt2, pt3, pt4;
|
||||
int iters = 8192;
|
||||
const int elts = 4000;
|
||||
const int fpostests = 1000000;
|
||||
const int fpostests = 100000;
|
||||
char d[20];
|
||||
int i,n=0, fp = 0;
|
||||
digestmap_t *dm = digestmap_new();
|
||||
@ -146,37 +149,48 @@ bench_dmap(void)
|
||||
}
|
||||
printf("nbits=%d\n", ds->mask+1);
|
||||
|
||||
tor_gettimeofday(&start);
|
||||
reset_perftime();
|
||||
|
||||
start = perftime();
|
||||
for (i = 0; i < iters; ++i) {
|
||||
SMARTLIST_FOREACH(sl, const char *, cp, digestmap_set(dm, cp, (void*)1));
|
||||
}
|
||||
tor_gettimeofday(&pt2);
|
||||
pt2 = perftime();
|
||||
printf("digestmap_set: %.2f ns per element\n",
|
||||
NANOCOUNT(start, pt2, iters*elts));
|
||||
|
||||
for (i = 0; i < iters; ++i) {
|
||||
SMARTLIST_FOREACH(sl, const char *, cp, digestmap_get(dm, cp));
|
||||
SMARTLIST_FOREACH(sl2, const char *, cp, digestmap_get(dm, cp));
|
||||
}
|
||||
tor_gettimeofday(&pt3);
|
||||
pt3 = perftime();
|
||||
printf("digestmap_get: %.2f ns per element\n",
|
||||
NANOCOUNT(pt2, pt3, iters*elts*2));
|
||||
|
||||
for (i = 0; i < iters; ++i) {
|
||||
SMARTLIST_FOREACH(sl, const char *, cp, digestset_add(ds, cp));
|
||||
}
|
||||
tor_gettimeofday(&pt4);
|
||||
pt4 = perftime();
|
||||
printf("digestset_add: %.2f ns per element\n",
|
||||
NANOCOUNT(pt3, pt4, iters*elts));
|
||||
|
||||
for (i = 0; i < iters; ++i) {
|
||||
SMARTLIST_FOREACH(sl, const char *, cp, n += digestset_isin(ds, cp));
|
||||
SMARTLIST_FOREACH(sl2, const char *, cp, n += digestset_isin(ds, cp));
|
||||
}
|
||||
tor_gettimeofday(&end);
|
||||
end = perftime();
|
||||
printf("digestset_isin: %.2f ns per element.\n",
|
||||
NANOCOUNT(pt4, end, iters*elts*2));
|
||||
/* We need to use this, or else the whole loop gets optimized out. */
|
||||
printf("Hits == %d\n", n);
|
||||
|
||||
for (i = 0; i < fpostests; ++i) {
|
||||
crypto_rand(d, 20);
|
||||
if (digestset_isin(ds, d)) ++fp;
|
||||
}
|
||||
printf("False positive rate on digestset: %.2f%%\n",
|
||||
(fp/(double)fpostests)*100);
|
||||
|
||||
printf("%ld\n",(unsigned long)tv_udiff(&start, &pt2));
|
||||
printf("%ld\n",(unsigned long)tv_udiff(&pt2, &pt3));
|
||||
printf("%ld\n",(unsigned long)tv_udiff(&pt3, &pt4));
|
||||
printf("%ld\n",(unsigned long)tv_udiff(&pt4, &end));
|
||||
printf("-- %d\n", n);
|
||||
printf("++ %f\n", fp/(double)fpostests);
|
||||
digestmap_free(dm, NULL);
|
||||
digestset_free(ds);
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
|
Loading…
Reference in New Issue
Block a user