summaryrefslogtreecommitdiff
path: root/cli/bench/stdio/stdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'cli/bench/stdio/stdio.c')
-rw-r--r--cli/bench/stdio/stdio.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/bench/stdio/stdio.c b/cli/bench/stdio/stdio.c
new file mode 100644
index 000000000..8125a0d00
--- /dev/null
+++ b/cli/bench/stdio/stdio.c
@@ -0,0 +1,29 @@
+// From https://github.com/just-js/benchmarks/tree/main/01-stdio
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char *argv[]) {
+ unsigned int blocksize = 65536;
+ if (argc == 2) {
+ blocksize = atoi(argv[1]);
+ }
+ char buf[blocksize];
+ unsigned long size = 0;
+ unsigned int reads = 0;
+ int n = read(STDIN_FILENO, buf, blocksize);
+ while (n > 0) {
+ reads++;
+ size += n;
+ n = read(STDIN_FILENO, buf, blocksize);
+ }
+ if (n < 0) {
+ fprintf(stderr, "read: %s (%i)\n", strerror(errno), errno);
+ exit(1);
+ }
+ fprintf(stdout, "size %lu reads %u blocksize %u\n", size, reads, blocksize);
+} \ No newline at end of file