1 #include <stdio.h>
2 #include <string.h>
3 #include <netdb.h>
4 #include <sys/types.h>
5 #include <netinet/in.h>
6 #include <arpa/inet.h>
7 #include <sys/time.h>
8 #include <unistd.h>
9 #include "firemake.h"
10 #include "firedns.h"
11 
12 #define TESTS 10000
13 #define TEST_HOST "aol.com"
14 
15 struct timeval tv;
16 
start_time()17 void start_time() {
18 	if (gettimeofday(&tv,NULL) != 0) {
19 		perror("gettimeofday()");
20 		exit(102);
21 	}
22 }
23 
end_time()24 double end_time() {
25 	struct timeval end;
26 	double timetaken;
27 
28 	if (gettimeofday(&end,NULL) != 0) {
29 		perror("gettimeofday()");
30 		exit(102);
31 	}
32 
33 
34 	timetaken = end.tv_sec + end.tv_usec / 1000000.0;
35 	timetaken -= tv.tv_sec + tv.tv_usec / 1000000.0;
36 
37 	printf("Delta seconds: %f\n",timetaken);
38 
39 	return timetaken;
40 }
41 
main()42 int main() {
43 	int i;
44 	double libc, fire;
45 
46 	printf("Testing %d firedns_resolveip4list(\"%s\"):\n",TESTS,TEST_HOST);
47 	start_time();
48 	for (i = 0; i < TESTS; i++)
49 		firedns_resolveip4list(TEST_HOST);
50 	fire = end_time();
51 
52 	printf("Testing %d gethostbyname(\"%s\"):\n",TESTS,TEST_HOST);
53 	start_time();
54 	for (i = 0; i < TESTS; i++)
55 		gethostbyname(TEST_HOST);
56 	libc = end_time();
57 
58 	if (libc > fire)
59 		printf("Speedup: %d%%\n",(int) (((libc - fire) / libc) * 100.0));
60 	else
61 		printf("Slowdown: %d%%\n",(int) (((fire - libc) / libc) * 100.0));
62 
63 	return 0;
64 }
65