klib
[Ported from github.com/attractivechaos/klib] added block arena
Brought by drakestapleton
| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <time.h> |
| 4 | #include "kstring.h" |
| 5 | |
| 6 | #define N 10000000 |
| 7 | |
| 8 | int main() |
| 9 | { |
| 10 | int i; |
| 11 | clock_t t; |
| 12 | kstring_t s, s2; |
| 13 | srand48(11); |
| 14 | s.l = s.m = 0; s.s = 0; |
| 15 | t = clock(); |
| 16 | for (i = 0; i < N; ++i) { |
| 17 | int x = lrand48(); |
| 18 | s.l = 0; |
| 19 | kputw(x, &s); |
| 20 | } |
| 21 | fprintf(stderr, "kputw: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC); |
| 22 | srand48(11); |
| 23 | t = clock(); |
| 24 | for (i = 0; i < N; ++i) { |
| 25 | int x = lrand48(); |
| 26 | s.l = 0; |
| 27 | ksprintf(&s, "%d", x); |
| 28 | } |
| 29 | fprintf(stderr, "ksprintf: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC); |
| 30 | |
| 31 | srand48(11); |
| 32 | s2.l = s2.m = 0; s2.s = 0; |
| 33 | t = clock(); |
| 34 | for (i = 0; i < N; ++i) { |
| 35 | int x = lrand48(); |
| 36 | s2.l = s.l = 0; |
| 37 | kputw(x, &s2); |
| 38 | kputs(s2.s, &s); |
| 39 | } |
| 40 | fprintf(stderr, "kputw+kputs: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC); |
| 41 | srand48(11); |
| 42 | t = clock(); |
| 43 | for (i = 0; i < N; ++i) { |
| 44 | int x = lrand48(); |
| 45 | s2.l = s.l = 0; |
| 46 | kputw(x, &s2); |
| 47 | ksprintf(&s, "%s", s2.s); |
| 48 | } |
| 49 | fprintf(stderr, "kputw+ksprintf: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC); |
| 50 | return 0; |
| 51 | } |