Skip to content

Instantly share code, notes, and snippets.

@JackDrogon
Last active November 10, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JackDrogon/b9571701c7df15b19311e1f96c94007d to your computer and use it in GitHub Desktop.
Save JackDrogon/b9571701c7df15b19311e1f96c94007d to your computer and use it in GitHub Desktop.
pipe atime benckmark
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/unistd.h>
static int fds[2];
static pthread_t rp;
static void *rp_entry(void *arg) {
char c[1];
while (1 == read(fds[0], c, 1)) {
if (*c == 'Q') break;
}
fprintf(stderr, "pipe read ok\n");
return NULL;
}
int main(int argc, char *argv[]) {
long i, n;
int rc;
if (argc < 2) {
fprintf(stderr, "usage: pipe_test NNNNNN\n");
return -1;
}
n = atol(argv[1]);
pipe(fds);
pthread_create(&rp, NULL, rp_entry, NULL);
fprintf(stderr, "pipe write %ld...", n);
for (i = 0; i < n; i++) {
write(fds[1], "A", 1);
}
write(fds[1], "Q", 1);
fprintf(stderr, "ok\n");
pthread_join(rp, NULL);
close(fds[0]);
close(fds[1]);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/unistd.h>
static int fds[2];
static pthread_t rp;
static void *rp_entry(void *arg) {
char c[1];
while (1 == read(fds[0], c, 1)) {
if (*c == 'Q') break;
}
fprintf(stderr, "pipe read ok\n");
return NULL;
}
int main(int argc, char *argv[]) {
long i, n;
int rc;
if (argc < 2) {
fprintf(stderr, "usage: pipe_test NNNNNN\n");
return -1;
}
n = atol(argv[1]);
pipe(fds);
//fcntl(fds[0], F_SETFL, O_NOATIME);
pthread_create(&rp, NULL, rp_entry, NULL);
fprintf(stderr, "pipe write %ld...", n);
for (i = 0; i < n; i++) {
write(fds[1], "A", 1);
}
write(fds[1], "Q", 1);
fprintf(stderr, "ok\n");
pthread_join(rp, NULL);
close(fds[0]);
close(fds[1]);
return 0;
}
@JackDrogon
Copy link
Author

Profile with oprofile.
with atime:

2345      0.5745  vmlinux                  touch_atime
901       0.2208  vmlinux                  pipe_writev
233       0.0571  vmlinux                  pipe_readv

without atime

1001      0.1592  vmlinux                  pipe_readv
925       0.1471  vmlinux                  pipe_writev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment