Advertisement
dan-masek

imshow microbench

Apr 5th, 2016
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <opencv2/opencv.hpp>
  2. #include <cstdint>
  3. #include <chrono>
  4. #include <iostream>
  5.  
  6. int main()
  7. {
  8.     using std::chrono::high_resolution_clock;
  9.     using std::chrono::duration_cast;
  10.     using std::chrono::microseconds;
  11.  
  12.     cv::Mat img(cv::Mat::zeros(1200, 1600, CV_8UC3));
  13.  
  14.     high_resolution_clock::time_point t1 = high_resolution_clock::now();
  15.  
  16.     for (uint32_t i(0); i < 256; ++i) {
  17.         cv::imshow("foo", img);
  18.         cv::waitKey(1);
  19.         img += 1;
  20.     }
  21.  
  22.     high_resolution_clock::time_point t2 = high_resolution_clock::now();
  23.  
  24.     auto duration = duration_cast<microseconds>(t2 - t1).count();
  25.     double t_ms(static_cast<double>(duration) / 1000.0);
  26.     std::cout
  27.         << "Total = " << t_ms << " ms\n"
  28.         << "Iteration = " << (t_ms / 256) << " ms\n"
  29.         << "FPS = " << (256 / t_ms * 1000.0) << "\n";
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement