Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. #include <iostream>
  2. #include "DefaultClock.h"
  3. #include <stdio.h>
  4.  
  5. #include <cstring>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <fcntl.h>
  11. #include <string.h>
  12. #include <errno.h>
  13. #include <unistd.h>
  14. #define ONEGB (1000000000)
  15.  
  16.  
  17. #define READ_SYSTEM_CALL 0
  18. #define WRITE_SYSTEM_CALL 1
  19. #define OPEN_SYSTEM_CALL 2
  20. #define CLOSE_SYSTEM_CALL 3
  21.  
  22.  
  23. using AccurateClock::DefaultClock;
  24. using std::cout;
  25. using std::endl;
  26.  
  27. size_t my_write(int fd, const void *buffer, size_t size) {
  28. ssize_t returnValue;
  29. returnValue = syscall(WRITE_SYSTEM_CALL,fd,buffer,size);
  30. return returnValue;
  31. };
  32.  
  33. int my_open(const char *filename, int flag, mode_t mode){
  34. int returnValue;
  35. returnValue = syscall(OPEN_SYSTEM_CALL, filename, flag, mode);
  36. return returnValue;
  37. };
  38.  
  39.  
  40. int my_close(const char *filename, int flag, mode_t mode){
  41. int returnValue;
  42. returnValue = syscall(CLOSE_SYSTEM_CALL, filename, flag, mode);
  43. return returnValue;
  44. };
  45.  
  46.  
  47. size_t my_read(int fd, const void *buffer, size_t size) {
  48. ssize_t returnValue;
  49. returnValue = syscall(READ_SYSTEM_CALL,fd,buffer,size);
  50. return returnValue;
  51. };
  52.  
  53.  
  54.  
  55. int main(int argc, char *argv[]) {
  56.  
  57. int buffer_size;
  58. char * file_name;
  59. int write_count;
  60.  
  61. if(argc != 7){
  62. return 0;
  63. }
  64.  
  65. for (int i = 1 ;i < argc - 1; i++){
  66. if(strcmp(argv[i], "--buffer_size") == 0){
  67. buffer_size = atoi(argv[i+1]);
  68. }
  69.  
  70. else if(strcmp(argv[i],"--file_name") == 0){
  71. file_name = argv[i+1];
  72. }
  73. else if(strcmp(argv[i],"--write_count") == 0){
  74. write_count = atoi(argv[i+1]);
  75. }
  76. }
  77. printf("\n%s, %d, %d\n", file_name, buffer_size, write_count);
  78. for (int i = 1; i < argc -1; i++){
  79. if (strcmp(argv[i],"--write_count") == 0){
  80. auto clock = DefaultClock();
  81. // int Buffer = strtol(argv[1], NULL, 10);
  82. char BuffChar[buffer_size];
  83. int myDirectory;
  84. myDirectory = my_open(file_name,O_RDWR|O_CREAT|O_TRUNC,0666);
  85. double timesToWrite = (buffer_size);
  86. auto start = clock.getTime();
  87. for(int i = 0; i < timesToWrite; i++)
  88. {
  89. my_write(myDirectory, BuffChar, buffer_size);
  90. }
  91.  
  92.  
  93.  
  94.  
  95. auto end = clock.getTime();
  96.  
  97. auto duration = end - start;
  98.  
  99. duration.print(cout << "Program took ");
  100.  
  101. cout << endl;
  102.  
  103. cout << "start time: ";
  104. start.print(cout);
  105. cout << endl;
  106.  
  107. cout << "end time: ";
  108. end.print(cout);
  109. cout << endl;
  110. }
  111.  
  112.  
  113.  
  114. else if (strcmp(argv[i],"--read_count") == 0){
  115. auto clock = DefaultClock();
  116. // int Buffer = strtol(argv[1], NULL, 10);
  117. char BuffChar[buffer_size];
  118. int myDirectory;
  119. myDirectory = my_read(file_name,O_RDWR|O_CREAT|O_TRUNC,0666);
  120. double timesToWrite = (buffer_size);
  121. auto start = clock.getTime();
  122. for(int i = 0; i < timesToWrite; i++)
  123. {
  124. my_read(myDirectory, BuffChar, buffer_size);
  125. }
  126.  
  127. auto end = clock.getTime();
  128.  
  129. auto duration = end - start;
  130.  
  131. duration.print(cout << "Program took ");
  132.  
  133. cout << endl;
  134.  
  135. cout << "start time: ";
  136. start.print(cout);
  137. cout << endl;
  138.  
  139. cout << "end time: ";
  140. end.print(cout);
  141. cout << endl;
  142. }
  143.  
  144. }
  145. return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement