Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * # perf stat --all-kernel ./open open.c p |&grep -e cycles:khH -e instructions:khH
- * 5,412,222,342 cycles:khH # 2.715 GHz
- * 5,878,446,552 instructions:khH # 1.09 insn per cycle
- * # perf stat --all-kernel ./open open.c r |&grep -e cycles:khH -e instructions:khH
- * 8,654,592,565 cycles:khH # 3.328 GHz
- * 8,223,833,831 instructions:khH # 0.95 insn per cycle
- * # perf stat --all-kernel ./open open.c w |&grep -e cycles:khH -e instructions:khH
- * 9,799,845,626 cycles:khH # 3.417 GHz
- * 9,059,955,513 instructions:khH # 0.92 insn per cycle
- * # perf stat --all-kernel ./open open.c rw |&grep -e cycles:khH -e instructions:khH
- * 10,163,667,588 cycles:khH # 3.348 GHz
- * 9,351,841,216 instructions:khH # 0.92 insn per cycle
- */
- #define _GNU_SOURCE
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- int main(int argc, char *argv[])
- {
- char *filename, *mode;
- int fd, flags = O_PATH;
- if (argc < 3)
- return 1;
- filename = argv[1];
- mode = argv[2];
- if (!strcmp(mode, "r"))
- flags = O_RDONLY;
- else if (!strcmp(mode, "w"))
- flags = O_WRONLY;
- else if (!strcmp(mode, "rw"))
- flags = O_RDWR;
- for (int i = 0; i < 1000000; i++) {
- fd = open(filename, flags);
- close(fd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement