Guest User

Untitled

a guest
Jul 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <QDirIterator>
  2. #include <chrono>
  3. #include <experimental/filesystem>
  4. #include <boost/filesystem.hpp>
  5. #include <iostream>
  6. #include <functional>
  7.  
  8. #define TEST_PATH "/home/master/test"
  9.  
  10. unsigned long long get_time_for_qiter() {
  11. using namespace std::chrono;
  12. QDirIterator qiter(TEST_PATH);
  13. int num_files = 0;
  14. auto start_time = high_resolution_clock::now();
  15. while (qiter.hasNext()) {
  16. num_files++;
  17. qiter.next();
  18. }
  19. return (high_resolution_clock::now() - start_time).count();
  20. }
  21.  
  22. unsigned long long get_time_for_ts() {
  23. using namespace std::chrono;
  24. using namespace std::experimental;
  25. int num_files = 0;
  26. auto start_time = high_resolution_clock::now();
  27. for (auto &_: filesystem::directory_iterator(TEST_PATH)) {
  28. num_files++;
  29. }
  30. return (high_resolution_clock::now() - start_time).count();
  31. }
  32.  
  33. unsigned long long get_time_for_boost() {
  34. using namespace std::chrono;
  35. using namespace boost;
  36. int num_files = 0;
  37. auto start_time = high_resolution_clock::now();
  38. for (auto &_: filesystem::directory_iterator(TEST_PATH)) {
  39. num_files++;
  40. }
  41. return (high_resolution_clock::now() - start_time).count();
  42. }
  43.  
  44.  
  45. unsigned long long loop_test(std::function<double()> func) {
  46. unsigned long long time_sum = 0;
  47. for (int i=0; i < 10; ++i)
  48. time_sum += func();
  49. return time_sum;
  50. }
  51.  
  52.  
  53. int main(int argc, char *argv[])
  54. {
  55. std::cout << "QDirIterator: " << loop_test(get_time_for_qiter) << " sesonds" << std::endl;
  56. std::cout << "boost directory_iterator: " << loop_test(get_time_for_boost) << " sesonds" << std::endl;
  57. std::cout << "c++17 directory_iterator: " << loop_test(get_time_for_ts) << " sesonds" << std::endl;
  58. }
Add Comment
Please, Sign In to add comment