Same algorithm (less than 10 LOC) in Rust is >10 times faster. How come? #1790
Replies: 3 comments
-
but when i print one word on a line the times are 0.820 and 0.211 respectively |
Beta Was this translation helpful? Give feedback.
-
From my testing it looks like print calls in mojo aren't quite on the level rust's are. When I change the for loop to append to a DynamicVector it completes in 0.029 seconds. Probably Modular needs to improve the print functions |
Beta Was this translation helpful? Give feedback.
-
Print calls and string operations in Mojo are still quite unoptimized, also the split line operation in Mojo as I remember from my experimentation was quite expensive. fn main() raises:
with open("nouns.txt", "r") as f:
let lines = f.read_bytes() #Faster than f.read(), returns Tensor[Dtype.int8] and write a custom function that loops over input looking for line seperator. |
Beta Was this translation helpful? Give feedback.
-
mojo:
$ mojo build main.🔥 $ time ./main ... real 0.845 mem 9KB
rust:
$ cargo build --release $ time ./target/release/main ... real 0.072 mem 5KB
nouns.txt:
nouns.txt
arch linux
latest stable mojo (0.7.0 (af002202))
latest stable rust (1.76.0 (07dca489a 2024-02-04))
kitty terminal emulator
Beta Was this translation helpful? Give feedback.
All reactions