stdio and malloc bench
[libc-test] / src / stdio / bench.c
diff --git a/src/stdio/bench.c b/src/stdio/bench.c
new file mode 100644 (file)
index 0000000..625a217
--- /dev/null
@@ -0,0 +1,35 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "test.h"
+
+void bench_stdio_putcgetc() {
+       FILE *f = tmpfile();
+       size_t i;
+       size_t cs = 0;
+
+       for (i=0; i<N; i++)
+               putc('x', f);
+       fseeko(f, 0, SEEK_SET);
+       for (i=0; i<N; i++)
+               cs += getc(f);
+       fclose(f);
+       if (cs != (size_t)N*'x')
+               abort();
+}
+
+void bench_stdio_putcgetc_unlocked() {
+       FILE *f = tmpfile();
+       size_t i;
+       size_t cs = 0;
+
+       for (i=0; i<N; i++)
+               putc_unlocked('x', f);
+       fseeko(f, 0, SEEK_SET);
+       for (i=0; i<N; i++)
+               cs += getc_unlocked(f);
+       fclose(f);
+       if (cs != (size_t)N*'x')
+               abort();
+}