]>
git.proxmox.com Git - mirror_frr.git/blob - tests/test-timer-performance.c
2 * Test program which measures the time it takes to schedule and
5 * Copyright (C) 2013 by Open Source Routing.
6 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
8 * This file is part of Quagga
10 * Quagga is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * Quagga is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Quagga; see the file COPYING. If not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 #define SCHEDULE_TIMERS 1000000
35 #define REMOVE_TIMERS 500000
37 struct thread_master
*master
;
39 static int dummy_func(struct thread
*thread
)
44 int main(int argc
, char **argv
)
48 struct thread
**timers
;
49 struct timeval tv_start
, tv_lap
, tv_stop
;
50 unsigned long t_schedule
, t_remove
;
52 master
= thread_master_create();
54 timers
= calloc(SCHEDULE_TIMERS
, sizeof(*timers
));
56 /* create thread structures so they won't be allocated during the
58 for (i
= 0; i
< SCHEDULE_TIMERS
; i
++)
59 timers
[i
] = thread_add_timer_msec(master
, dummy_func
, NULL
, 0);
60 for (i
= 0; i
< SCHEDULE_TIMERS
; i
++)
61 thread_cancel(timers
[i
]);
63 quagga_gettime(QUAGGA_CLK_MONOTONIC
, &tv_start
);
65 for (i
= 0; i
< SCHEDULE_TIMERS
; i
++)
69 interval_msec
= prng_rand(prng
) % (100 * SCHEDULE_TIMERS
);
70 timers
[i
] = thread_add_timer_msec(master
, dummy_func
,
74 quagga_gettime(QUAGGA_CLK_MONOTONIC
, &tv_lap
);
76 for (i
= 0; i
< REMOVE_TIMERS
; i
++)
80 index
= prng_rand(prng
) % SCHEDULE_TIMERS
;
82 thread_cancel(timers
[index
]);
86 quagga_gettime(QUAGGA_CLK_MONOTONIC
, &tv_stop
);
88 t_schedule
= 1000 * (tv_lap
.tv_sec
- tv_start
.tv_sec
);
89 t_schedule
+= (tv_lap
.tv_usec
- tv_start
.tv_usec
) / 1000;
91 t_remove
= 1000 * (tv_stop
.tv_sec
- tv_lap
.tv_sec
);
92 t_remove
+= (tv_stop
.tv_usec
- tv_lap
.tv_usec
) / 1000;
94 printf("Scheduling %d random timers took %ld.%03ld seconds.\n",
95 SCHEDULE_TIMERS
, t_schedule
/1000, t_schedule
%1000);
96 printf("Removing %d random timers took %ld.%03ld seconds.\n",
97 REMOVE_TIMERS
, t_remove
/1000, t_remove
%1000);
101 thread_master_free(master
);