Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment