lat_syscall.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * lat_syscall.c - time simple system calls
  3. *
  4. * Copyright (c) 1996 Larry McVoy. Distributed under the FSF GPL with
  5. * additional restriction that results may published only if
  6. * (1) the benchmark is unmodified, and
  7. * (2) the version in the sccsid below is included in the report.
  8. */
  9. char *id = "$Id$\n";
  10. #include "bench.h"
  11. #define FNAME "/usr/include/x86_64-linux-gnu/sys/types.h"
  12. void
  13. do_write(int fd, char *s)
  14. {
  15. char c;
  16. if (write(fd, &c, 1) != 1) {
  17. perror(s);
  18. return;
  19. }
  20. }
  21. void
  22. do_read(int fd, char *s)
  23. {
  24. char c;
  25. if (read(fd, &c, 1) != 1) {
  26. perror(s);
  27. return;
  28. }
  29. }
  30. void
  31. do_stat(char *s)
  32. {
  33. struct stat sbuf;
  34. if (stat(s, &sbuf) == -1) {
  35. perror(s);
  36. return;
  37. }
  38. }
  39. void
  40. do_fstat(int fd)
  41. {
  42. struct stat sbuf;
  43. if (fstat(fd, &sbuf) == -1) {
  44. perror("fstat");
  45. return;
  46. }
  47. }
  48. void
  49. do_openclose(char *s)
  50. {
  51. int fd;
  52. fd = open(s, 0);
  53. if (fd == -1) {
  54. perror(s);
  55. return;
  56. }
  57. close(fd);
  58. }
  59. int
  60. main(int ac, char **av)
  61. {
  62. int fd;
  63. char *file;
  64. if (ac < 2) goto usage;
  65. file = av[2] ? av[2] : FNAME;
  66. if (!strcmp("null", av[1])) {
  67. BENCH(getppid(), 0);
  68. micro("Simple syscall", get_n());
  69. } else if (!strcmp("write", av[1])) {
  70. file = av[2] ? av[2] : "/dev/null";
  71. fd = open(file, 1);
  72. if (fd == -1) {
  73. fprintf(stderr, "Write from %s: %s\n", file, strerror(errno));
  74. return(1);
  75. }
  76. BENCH(do_write(fd, file), 0);;
  77. micro("Simple write", get_n());
  78. close(fd);
  79. } else if (!strcmp("read", av[1])) {
  80. file = av[2] ? av[2] : "/dev/null";
  81. fd = open(file, 0);
  82. if (fd == -1) {
  83. fprintf(stderr, "Read from %s: %s\n", file, strerror(errno));
  84. return(1);
  85. }
  86. BENCH(do_read(fd, file), 0);
  87. micro("Simple read", get_n());
  88. close(fd);
  89. } else if (!strcmp("stat", av[1])) {
  90. BENCH(do_stat(file), 0);
  91. micro("Simple stat", get_n());
  92. } else if (!strcmp("fstat", av[1])) {
  93. fd = open(file, 0);
  94. BENCH(do_fstat(fd), 0);
  95. micro("Simple fstat", get_n());
  96. } else if (!strcmp("open", av[1])) {
  97. BENCH(do_openclose(file), 0);
  98. micro("Simple open/close", get_n());
  99. } else {
  100. usage: printf("Usage: %s null|read|write|stat|open\n", av[0]);
  101. }
  102. return(0);
  103. }