Is python faster than rust?

find all excel files in dir then read every excel, process data , write to .txt
python is faster rust!!
why??

No. The Rust library for reading excel data is probably just bad.

7 Likes

All questions apply to both the Python and Rust version unless specified :

  1. How are you listing all files ?
  2. What algorithm is used to read the files ?
    • If using a library, which library ? What are the library's goals ? Performance or convenience ?
    • What are the median and average size of those files ? How many are there ?
  3. How is the processing done ? Is the algorithm the same ?
  4. How is the writing done ?
  5. Is the Rust version compiled in release mode ?
  6. How is the running time measured ?

There's bound to be more questions like these, but that's what I have in mind when reading this.

6 Likes

... or they are using cargo run to run the code in debug mode without any optimisations.

2 Likes

I would wager it is because when you do that in Python most of the work is being done by some Python excel file reader module and that module is written in C or C++ and hence pretty efficient.

So you are actually comparing one implementation of an excel reader written in C++ with a different implementation written in Rust. Perhaps the Rust crate you are using is not so efficiently written.

Also, remember to use:

cargo run --release

the default debug builds are much slower than release builds.

2 Likes

thanks
rust: calamine = "0.18.0"
python: openpyxl

thanks
cargo run --release

ok , so fast!!

thanks:

python dp_xhx.py
get_excels 0.31119999999995596
getData: 1.xlsx 61.711299999999916
process data: 1.xlsx 1.6498000000000346
write: 1.xlsx 2.5237000000000176
getData: 2.xlsx 33.27950000000002
process data: 2.xlsx 0.2242999999999551
write: 2.xlsx 5.414800000000053
getData: 3.xlsx 36.42480000000003
process data: 3.xlsx 0.21620000000011075
write: 3.xlsx 2.1648000000000778
getData: 4.xlsx 2541.3597
process data: 4.xlsx 1.0250000000002757
write: 4.xlsx 2.3287000000000724
getData: 5.xlsx 32.031299999999874
process data: 5.xlsx 1.0126999999999775
write: 5.xlsx 3.077900000000078
getData: 6.xlsx 34.804700000000025
process data: 6.xlsx 0.23980000000012325
write: 6.xlsx 1.7939999999998513
getData: 7.xlsx 24.989200000000267
process data: 7.xlsx 0.6591000000000236
write: 7.xlsx 6.084699999999721
getData: 8.xlsx 22.537800000000274
process data: 8.xlsx 0.4155999999997384
write: 8.xlsx 6.299000000000277
getData: 9.xlsx 18.28189999999985
process data: 9.xlsx 0.1294999999998936
write: 9.xlsx 2.395300000000322
end: 2850.7101000000002
///////////////////////////////////////////////////////////
cargo run --release
Running target\release\makefw.exe
get_excels: 4
get_data: "./1.xlsx" 7
process data: "./1.xlsx" 3
write: "./1.xlsx" 7
get_data: "./2.xlsx" 3
process data: "./2.xlsx" 0
write: "./2.xlsx" 2
get_data: "./3.xlsx" 1
process data: "./3.xlsx" 0
write: "./3.xlsx" 1
get_data: "./4.xlsx" 94
process data: "./4.xlsx" 0
write: "./4.xlsx" 3
get_data: "./5.xlsx" 1
process data: "./5.xlsx" 0
write: "./5.xlsx" 1
get_data: "./6.xlsx" 2
process data: "./6.xlsx" 0
write: "./6.xlsx" 2
get_data: "./7.xlsx" 3
process data: "./7.xlsx" 0
write: "./7.xlsx" 2
get_data: "./8.xlsx" 1
process data: "./8.xlsx" 0
write: "./8.xlsx" 2
get_data: "./9.xlsx" 1
process data: "./9.xlsx" 0
write: "./9.xlsx" 2
end: 167

--release so fast!

Amazing isn't it. :slight_smile:

3 Likes

Yeah, you was right. Gotta remember that one.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.