Last active
November 10, 2016 07:23
-
-
Save JackDrogon/b9571701c7df15b19311e1f96c94007d to your computer and use it in GitHub Desktop.
pipe atime benckmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Profile with oprofile.
with atime:
without atime