Guest User

Untitled

a guest
Jan 10th, 2018
301
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Written by fede.tft, public domain
  3.  
  4. #include <iostream>
  5. #include <chrono>
  6. #include <algorithm>
  7. #include <limits>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12.  
  13. using namespace std;
  14. using namespace std::chrono;
  15.  
  16. const int n=100000000; //Number of iterations
  17.  
  18. int main()
  19. {
  20.     int fd=open("/dev/null",O_RDWR);
  21.     if(fd<0) return 1;
  22.     long long minVal=numeric_limits<long long>::max(), avgVal=0;
  23.     for(int i=0;i<n;i++)
  24.     {
  25.         char c=0;
  26.         auto t1=high_resolution_clock::now();
  27.         if(write(fd,&c,1)!=1) return 1;
  28.         auto t2=high_resolution_clock::now();
  29.         long long t=duration_cast<duration<double>>(t2-t1).count()*1e9;
  30.         minVal=min(minVal,t);
  31.         avgVal+=t;
  32.     }
  33.     close(fd);
  34.     avgVal/=n;
  35.     cout<<"min="<<minVal<<" ns\navg="<<avgVal<<" ns\n";
  36.     return 0;
  37. }
RAW Paste Data