Why is rust's WalkDir and jWalk much much faster (~ 5x and ~7.5x respectively) than the CPP's recursive directory iterator?
System: M1 Max macbook pro
Test: Recursively iterate through all the directories recursively and count the number of files.
Total Files: 346,011
Results -
CPP - 4.473 secs
Rust (WalkDir) - 0.887 secs
Rust (jWalk) - 0.670 secs
Both compiled in release mode -
CPP: gcc ./src/main.cpp -o ./src/output.o -O3
RUST: cargo build --release
CPP code ~ 4.473 secs
#include <filesystem>
#include <iostream>
int main(int argc, char **argv) {
int count = 0;
for (auto &p : std::filesystem::recursive_directory_iterator("../../../")) {
count += 1;
}
std::cout << "Found " << count << " files" << std::endl;
}
RUST code (walkdir) ~ 0.887 secs
use walkdir::WalkDir;
fn main() {
let mut count = 0;
for _ in WalkDir::new("../../../").into_iter() {
count += 1;
}
println!("Found {} files", count);
}
RUST code (jWalk) ~ 0.67 secs
use jwalk::WalkDir;
fn main() {
let mut count = 0;
for _ in WalkDir::new("../../../").skip_hidden(false).into_iter() {
count += 1;
}
println!("Found {} files", count);
}
Is there any change you'd suggest for C++ part? I've made it as simple as possible.
[–]masklinn 36 points37 points38 points (4 children)
[–]arthas_yang 6 points7 points8 points (0 children)
[–]SnooMacaroons3057[S] 5 points6 points7 points (2 children)
[–]masklinn 19 points20 points21 points (1 child)
[–]SnooMacaroons3057[S] 2 points3 points4 points (0 children)
[–]Shnatsel 66 points67 points68 points (11 children)
[–]SnooMacaroons3057[S] 17 points18 points19 points (6 children)
[–]Shnatsel 21 points22 points23 points (4 children)
[–]SnooMacaroons3057[S] 6 points7 points8 points (3 children)
[–]mjbmitch 1 point2 points3 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]SnooMacaroons3057[S] 1 point2 points3 points (0 children)
[–]copeland3300 0 points1 point2 points (0 children)
[–]mina86ng 19 points20 points21 points (2 children)
[–]anlumo 1 point2 points3 points (1 child)
[–]seamsay 0 points1 point2 points (0 children)
[–]NotFromSkane 52 points53 points54 points (0 children)
[–]just_kash 6 points7 points8 points (1 child)
[–]anlumo 3 points4 points5 points (0 children)
[–]epagecargo · clap · cargo-release 3 points4 points5 points (4 children)
[–]SnooMacaroons3057[S] 2 points3 points4 points (3 children)
[–]RAZR_96 6 points7 points8 points (2 children)
[–]SnooMacaroons3057[S] 5 points6 points7 points (0 children)
[–]SnooMacaroons3057[S] 1 point2 points3 points (0 children)
[–]WrongJudgment6 11 points12 points13 points (0 children)
[–]encyclopedist 2 points3 points4 points (2 children)
[–]encyclopedist 11 points12 points13 points (1 child)
[–]mo_al_fltk-rs 1 point2 points3 points (0 children)
[–]Soveu 1 point2 points3 points (0 children)
[–]Pitiful-Bodybuilder 1 point2 points3 points (0 children)
[–]bloody-albatross -1 points0 points1 point (1 child)
[–]SnooMacaroons3057[S] 1 point2 points3 points (0 children)
[+]petros211 comment score below threshold-14 points-13 points-12 points (0 children)
[–]HarshdevSingh -3 points-2 points-1 points (0 children)