Oops, ensure the copy gets freed.
[beanstalkd.git] / perf.c
blob9dbd961d6361c786fe53a5687e9ad6d39522abb4
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <sys/time.h>
6 #include "tube.h"
7 #include "job.h"
8 #include "util.h"
9 #include "pq.h"
11 static tube default_tube;
13 static void
14 elapsed(struct timeval *t0, struct timeval *t1)
16 printf("elapsed %zdms\n",
17 (1000 * (t1->tv_sec - t0->tv_sec)) +
18 (t1->tv_usec / 1000) - (t0->tv_usec / 1000));
21 int
22 main(int argc, char **argv)
24 int i;
25 job j;
26 struct timeval t0, t1, t2, t3, t4;
28 progname = argv[0];
30 job_init();
31 TUBE_ASSIGN(default_tube, make_tube("default"));
33 printf("inserting 2M ");
34 fflush(stdout);
35 gettimeofday(&t0, NULL);
36 for (i = 0; i < 2000000; i++) {
37 j = make_job(1, 0, 1, 0, default_tube);
39 gettimeofday(&t1, NULL);
40 elapsed(&t0, &t1);
42 printf("removing 200K ");
43 fflush(stdout);
44 for (i = 0; i < 200000; i++) {
45 j = job_find(i);
46 if (j) job_free(j);
48 gettimeofday(&t2, NULL);
49 elapsed(&t1, &t2);
51 printf("inserting 2M ");
52 fflush(stdout);
53 for (i = 0; i < 2000000; i++) {
54 j = make_job(1, 0, 1, 0, default_tube);
56 gettimeofday(&t3, NULL);
57 elapsed(&t2, &t3);
59 printf("removing 200K ");
60 fflush(stdout);
61 for (i = 0; i < 200000; i++) {
62 j = job_find(i + 2000000);
63 if (j) job_free(j);
65 gettimeofday(&t4, NULL);
66 elapsed(&t3, &t4);
68 printf("total ");
69 elapsed(&t0, &t4);
70 return 0;