bench: pass N as argument, update readme
[libc-test] / src / stdio / bench.c
1 #define _POSIX_C_SOURCE 200809L
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "test.h"
6
7 void bench_stdio_putcgetc(int N) {
8         FILE *f = tmpfile();
9         size_t i;
10         size_t cs = 0;
11
12         for (i=0; i<N; i++)
13                 putc('x', f);
14         fseeko(f, 0, SEEK_SET);
15         for (i=0; i<N; i++)
16                 cs += getc(f);
17         fclose(f);
18         if (cs != (size_t)N*'x')
19                 abort();
20 }
21
22 void bench_stdio_putcgetc_unlocked(int N) {
23         FILE *f = tmpfile();
24         size_t i;
25         size_t cs = 0;
26
27         for (i=0; i<N; i++)
28                 putc_unlocked('x', f);
29         fseeko(f, 0, SEEK_SET);
30         for (i=0; i<N; i++)
31                 cs += getc_unlocked(f);
32         fclose(f);
33         if (cs != (size_t)N*'x')
34                 abort();
35 }