18
const gchar *hn = NULL;
22
dns_cache_set_params(50000, 3, 1, NULL);
24
for (i = 0; i < 10000; i++)
26
guint32 ni = htonl(i);
28
dns_cache_store(FALSE, AF_INET, (void *) &ni, i < 5000 ? "hostname" : NULL, i < 5000);
31
for (i = 0; i < 10000; i++)
33
guint32 ni = htonl(i);
37
if (!dns_cache_lookup(AF_INET, (void *) &ni, &hn, &positive))
39
fprintf(stderr, "hmmm cache forgot the cache entry too early, i=%d, hn=%s\n", i, hn);
46
if (!positive || strcmp(hn, "hostname") != 0)
48
fprintf(stderr, "hmm, cached returned an positive match, but cached name invalid, i=%d, hn=%s\n", i, hn);
54
if (positive || hn != NULL)
56
fprintf(stderr, "hmm, cache returned a positive match, where a negative match was expected, i=%d, hn=%s\n", i, hn);
64
/* negative entries should expire by now, positive ones still present */
66
invalidate_cached_time();
68
for (i = 0; i < 10000; i++)
70
guint32 ni = htonl(i);
76
if (!dns_cache_lookup(AF_INET, (void *) &ni, &hn, &positive) || !positive)
78
fprintf(stderr, "hmmm cache forgot positive entries too early, i=%d\n", i);
84
if (dns_cache_lookup(AF_INET, (void *) &ni, &hn, &positive) || positive)
86
fprintf(stderr, "hmmm cache didn't forget negative entries in time, i=%d\n", i);
92
/* everything should be expired by now */
95
invalidate_cached_time();
97
for (i = 0; i < 10000; i++)
99
guint32 ni = htonl(i);
103
if (dns_cache_lookup(AF_INET, (void *) &ni, &hn, &positive))
105
fprintf(stderr, "hmmm cache did not forget an expired entry, i=%d\n", i);
112
test_dns_cache_benchmark(void)
120
dns_cache_set_params(50000, 600, 300, NULL);
122
for (i = 0; i < 10000; i++)
124
guint32 ni = htonl(i);
126
dns_cache_store(FALSE, AF_INET, (void *) &ni, "hostname", TRUE);
129
g_get_current_time(&start);
131
for (i = 0; i < 10000; i++)
133
guint32 ni = htonl(i % 10000);
136
if (!dns_cache_lookup(AF_INET, (void *) &ni, &hn, &positive))
138
fprintf(stderr, "hmm, dns cache entries expired during benchmarking, this is unexpected\n, i=%d", i);
141
g_get_current_time(&end);
142
printf("DNS cache speed: %12.3f iters/sec\n", i * 1e6 / g_time_val_diff(&end, &start));
146
test_inet_ntop_benchmark(void)
152
g_get_current_time(&start);
154
for (i = 0; i < 10000; i++)
156
guint32 ni = htonl(i % 10000);
158
inet_ntop(AF_INET, (void *) &ni, buf, sizeof(buf));
160
g_get_current_time(&end);
161
printf("inet_ntop speed: %12.3f iters/sec\n", i * 1e6 / g_time_val_diff(&end, &start));
18
dns_cache_set_params(50000, 2, 1, NULL);
20
for (i = 0; i < 10000; i++)
22
guint32 ni = htonl(i);
24
dns_cache_store(FALSE, AF_INET, (void *) &ni, "hostname");
27
for (i = 0; i < 10000; i++)
29
guint32 ni = htonl(i);
30
const gchar *hn = NULL;
32
if (!dns_cache_lookup(AF_INET, (void *) &ni, &hn) || strcmp(hn, "hostname") != 0)
34
fprintf(stderr, "hmmm cache forgot the hostname, i=%d, hn=%s\n", i, hn);
42
for (i = 0; i < 10000; i++)
44
guint32 ni = htonl(i);
45
const gchar *hn = NULL;
47
if (dns_cache_lookup(AF_INET, (void *) &ni, &hn))
49
fprintf(stderr, "hmmm cache did not forget the hostname, i=%d\n", i);
170
test_dns_cache_benchmark();
171
test_inet_ntop_benchmark();