Skip to content

Instantly share code, notes, and snippets.

@drizzd
Last active October 3, 2018 08:22
Show Gist options
  • Save drizzd/8d498adeb310a5780ba1291dc607c155 to your computer and use it in GitHub Desktop.
Save drizzd/8d498adeb310a5780ba1291dc607c155 to your computer and use it in GitHub Desktop.
bash read performance
#include <stdio.h>
#include <unistd.h>
#define BUFSIZE 8192
char buf[BUFSIZE];
int main()
{
while (1) {
int i;
i = read(0, buf, BUFSIZE);
if (i < 0) {
perror("read");
exit(1);
} else if (i == 0) {
break;
}
fprintf(stdout, "%d\n", i);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
void usage()
{
fprintf(stderr, "usage: seq LAST\n");
exit(1);
}
int main(int argc, const char **argv)
{
long int last;
long int i;
char *endptr;
if (argc != 2) {
usage();
}
last = strtol(argv[1], &endptr, 10);
if (errno == ERANGE) {
fprintf(stderr, "seq: out of range\n");
exit(1);
}
if (endptr != argv[1] + strlen(argv[1])) {
fprintf(stderr, "seq: parse error\n");
exit(1);
}
if (last < 1) {
usage();
}
//setvbuf(stdout, NULL, _IONBF, BUFSIZ);
//setvbuf(stdout, NULL, _IOFBF, 4096);
fprintf(stderr, "BUFSIZ: %d\n", BUFSIZ);
for (i = 1; i <= last; i++) {
fputs("yes kajsldfjasldkfj alskdjf lksadj", stdout);
fputc('\n', stdout);
//fprintf(stdout, "yes kajsldfjasldkfj alskdjf lksadj\n");
//if ((last & 128-1) == 0) {
// fflush(stdout);
//}
//fprintf(stdout, "%d\n", i);
//fflush(stdout);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment