fork download
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <sys/time.h>
  5. #include <math.h>
  6.  
  7. #include "osm.h"
  8.  
  9.  
  10. #define INVALID_ITERATIONS 0
  11. #define DEFAULT_ITERATIONS 1000
  12. #define HOST_NAME_LEN 100
  13. #define TO_NANO 1000
  14.  
  15. using namespace std;
  16. int main()
  17. {
  18. unsigned int iterations = (unsigned int) pow( 10, 9);
  19.  
  20. measureTimes( iterations, iterations);
  21.  
  22. return 0;
  23. }
  24.  
  25. void foo();
  26.  
  27. timeMeasurmentStructure measureTimes (unsigned int operation_iterations,
  28. unsigned int function_iterations)
  29. {
  30.  
  31. double functionTimeNanoSecond;
  32.  
  33. functionTimeNanoSecond = osm_function_time( function_iterations);
  34. cout << "functionTimeNanoSecond: " << functionTimeNanoSecond << "\n";;
  35.  
  36. double instructionTimeNanoSecond;
  37.  
  38. instructionTimeNanoSecond = osm_operation_time( operation_iterations);
  39. cout << "instructionTimeNanoSecond: " << instructionTimeNanoSecond << "\n";
  40. }
  41.  
  42.  
  43. double osm_operation_time(unsigned int iterations)
  44. {
  45. timeval start;
  46. gettimeofday(&start, NULL);
  47.  
  48. for( int i = 0; i < iterations; i++ )
  49. {
  50. 1+1;
  51. }
  52.  
  53. timeval end;
  54. gettimeofday(&end, NULL);
  55.  
  56. timeval diff;
  57. timersub(&end, &start, &diff);
  58.  
  59. double micro_seconds =(double) (end.tv_usec - start.tv_usec);
  60.  
  61. double ret = diff.tv_usec / ((double) iterations);
  62.  
  63.  
  64. return ret * TO_NANO;
  65. }
  66.  
  67. double osm_function_time(unsigned int iterations)
  68. {
  69. timeval start;
  70. gettimeofday(&start, NULL);
  71.  
  72. for( int i = 0; i < iterations; i++ )
  73. {
  74. foo();
  75. }
  76.  
  77. timeval end;
  78. gettimeofday(&end, NULL);
  79.  
  80. timeval diff;
  81. timersub(&end, &start, &diff);
  82.  
  83. double micro_seconds = (double) (end.tv_usec - start.tv_usec);
  84.  
  85. double ret = diff.tv_usec / ((double) iterations);
  86.  
  87. return ret * TO_NANO;
  88. }
  89.  
  90. void foo()
  91. {
  92. return;
  93. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:7:21: fatal error: osm.h: No such file or directory
compilation terminated.
stdout
Standard output is empty