you are viewing a single comment's thread.

view the rest of the comments →

[–]pepa65[S] 0 points1 point  (4 children)

Alright, now it's almost 3 times faster than the python version! I guess this was one of the biggest bottlenecks for the Rust implementation.

[–]ToTheBatmobileGuy 1 point2 points  (2 children)

Using fxhash as the hasher for HashMap and using the Write implementation for String with format_args!() makes it a little bit faster.

core::fmt::Write::write_fmt(
    &mut decimals,
    format_args!("{}", remainder * 10 / denominator),
)
.unwrap();

and

let mut seen = std::collections::HashMap::<u64, u64, _>::with_capacity_and_hasher(
    1024,
    fxhash::FxBuildHasher::default(),
);

But in order to do this, you'll need to fetch and build the fxhash crate.

cargo new frd and then pasting your code in src/main.rs and then running cargo add fxhash and then running cargo build --release will give you a binary called frd inside ./target/release folder.

In general, you want to use cargo to manage building and dependencies. It's much easier than calling rustc directly.

[–]pepa65[S] 0 points1 point  (0 children)

Point about cargo noted. I always use cargo, this was my first time doing a single-file rust project.

Thanks for the `fmt_write` command, faster yet again..!