MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / timer_ratio

Function timer_ratio

deps/jemalloc/test/src/timer.c:24–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24void
25timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
26 uint64_t t0 = timer_usec(a);
27 uint64_t t1 = timer_usec(b);
28 uint64_t mult;
29 size_t i = 0;
30 size_t j, n;
31
32 /* Whole. */
33 n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);
34 i += n;
35 if (i >= buflen) {
36 return;
37 }
38 mult = 1;
39 for (j = 0; j < n; j++) {
40 mult *= 10;
41 }
42
43 /* Decimal. */
44 n = malloc_snprintf(&buf[i], buflen-i, ".");
45 i += n;
46
47 /* Fraction. */
48 while (i < buflen-1) {
49 uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10
50 >= 5)) ? 1 : 0;
51 n = malloc_snprintf(&buf[i], buflen-i,
52 "%"FMTu64, (t0 * mult / t1) % 10 + round);
53 i += n;
54 mult *= 10;
55 }
56}

Callers 1

compare_funcsFunction · 0.50

Calls 1

timer_usecFunction · 0.70

Tested by

no test coverage detected