Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Written by fede.tft, public domain
- #include <iostream>
- #include <chrono>
- #include <algorithm>
- #include <limits>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- using namespace std;
- using namespace std::chrono;
- const int n=100000000; //Number of iterations
- int main()
- {
- int fd=open("/dev/null",O_RDWR);
- if(fd<0) return 1;
- long long minVal=numeric_limits<long long>::max(), avgVal=0;
- for(int i=0;i<n;i++)
- {
- char c=0;
- auto t1=high_resolution_clock::now();
- if(write(fd,&c,1)!=1) return 1;
- auto t2=high_resolution_clock::now();
- long long t=duration_cast<duration<double>>(t2-t1).count()*1e9;
- minVal=min(minVal,t);
- avgVal+=t;
- }
- close(fd);
- avgVal/=n;
- cout<<"min="<<minVal<<" ns\navg="<<avgVal<<" ns\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment