MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/timer/benchmarks/expected-usage.c:13–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#define CONN_TIMEOUT_MS 30000
12
13int main(int argc, char *argv[])
14{
15 struct timespec start, curr;
16 struct timers timers;
17 struct list_head expired;
18 struct timer t[PER_CONN_TIME];
19 unsigned int i, num;
20 bool check = false;
21
22 opt_register_noarg("-c|--check", opt_set_bool, &check,
23 "Check timer structure during progress");
24
25 opt_parse(&argc, argv, opt_log_stderr_exit);
26
27 num = argv[1] ? atoi(argv[1]) : (check ? 100000 : 100000000);
28
29 list_head_init(&expired);
30 curr = start = time_now();
31 timers_init(&timers, start);
32
33 for (i = 0; i < num; i++) {
34 curr = time_add(curr, time_from_msec(1));
35 if (check)
36 timers_check(&timers, NULL);
37 if (timers_expire(&timers, curr))
38 abort();
39 if (check)
40 timers_check(&timers, NULL);
41
42 if (i >= PER_CONN_TIME) {
43 timer_del(&timers, &t[i%PER_CONN_TIME]);
44 if (check)
45 timers_check(&timers, NULL);
46 }
47 timer_add(&timers, &t[i%PER_CONN_TIME],
48 time_add(curr, time_from_msec(CONN_TIMEOUT_MS)));
49 if (check)
50 timers_check(&timers, NULL);
51 }
52 if (num > PER_CONN_TIME) {
53 for (i = 0; i < PER_CONN_TIME; i++)
54 timer_del(&timers, &t[i]);
55 }
56
57 curr = time_sub(time_now(), start);
58 if (check)
59 timers_check(&timers, NULL);
60 timers_cleanup(&timers);
61 opt_free_table();
62
63 for (i = 0; i < ARRAY_SIZE(timers.level); i++)
64 if (!timers.level[i])
65 break;
66
67 printf("%u in %lu.%09lu (%u levels / %zu)\n",
68 num, (long)curr.tv_sec, curr.tv_nsec,
69 i, ARRAY_SIZE(timers.level));
70 return 0;

Callers

nothing calls this directly

Calls 12

opt_parseFunction · 0.85
list_head_initFunction · 0.85
time_nowFunction · 0.85
timers_initFunction · 0.85
time_from_msecFunction · 0.85
timers_checkFunction · 0.85
timers_expireFunction · 0.85
abortFunction · 0.85
timer_delFunction · 0.85
time_subFunction · 0.85
timers_cleanupFunction · 0.85
opt_free_tableFunction · 0.85

Tested by

no test coverage detected