Created
July 21, 2018 23:04
-
-
Save Motherboard/9bce170327140a709dd40ac23bd863fa to your computer and use it in GitHub Desktop.
Compare boost directory_iterator and QDirIterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QDirIterator> | |
#include <chrono> | |
#include <experimental/filesystem> | |
#include <boost/filesystem.hpp> | |
#include <iostream> | |
#include <functional> | |
#define TEST_PATH "/home/master/test" | |
unsigned long long get_time_for_qiter() { | |
using namespace std::chrono; | |
QDirIterator qiter(TEST_PATH); | |
int num_files = 0; | |
auto start_time = high_resolution_clock::now(); | |
while (qiter.hasNext()) { | |
num_files++; | |
qiter.next(); | |
} | |
return (high_resolution_clock::now() - start_time).count(); | |
} | |
unsigned long long get_time_for_ts() { | |
using namespace std::chrono; | |
using namespace std::experimental; | |
int num_files = 0; | |
auto start_time = high_resolution_clock::now(); | |
for (auto &_: filesystem::directory_iterator(TEST_PATH)) { | |
num_files++; | |
} | |
return (high_resolution_clock::now() - start_time).count(); | |
} | |
unsigned long long get_time_for_boost() { | |
using namespace std::chrono; | |
using namespace boost; | |
int num_files = 0; | |
auto start_time = high_resolution_clock::now(); | |
for (auto &_: filesystem::directory_iterator(TEST_PATH)) { | |
num_files++; | |
} | |
return (high_resolution_clock::now() - start_time).count(); | |
} | |
unsigned long long loop_test(std::function<double()> func) { | |
unsigned long long time_sum = 0; | |
for (int i=0; i < 10; ++i) | |
time_sum += func(); | |
return time_sum; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
std::cout << "QDirIterator: " << loop_test(get_time_for_qiter) << " sesonds" << std::endl; | |
std::cout << "boost directory_iterator: " << loop_test(get_time_for_boost) << " sesonds" << std::endl; | |
std::cout << "c++17 directory_iterator: " << loop_test(get_time_for_ts) << " sesonds" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the test dir contains 1M files generated using the following script: