Hacker News new | ask | show | jobs
by Chilinot 479 days ago
I like Rust as much as the next guy, but statements like this makes me roll my eyes:

> hk is written in rust, pre-commit is written in python. hk will be much faster.

I have no idea how fast hk or pre-commit is, i have never used them. What matters to speed is the algorithms used and their complexities. If you implement a shitty algorithm with exponential complexity in Rust it's going to be slower than a linear complexity algorithm in python.

1 comments

This isn't true when it comes to CLI tools, where fixed costs and warm-up time can easily dominate over algorithmic complexity, especially comparing a scripting language to an ahead-of-time language. Without careful construction, a tool written in python with whatever O(log(n)) time complexity may still be booting up by the time a Rust tool finishes the job in O(n^2) time: frequently n is actually pretty small outside whole-repo builds, and the cost of interpreter is high especially with accompanying tooling -- python3 itself will run `print("hello")` on my machine in 40ms, but when wrapped in pyenv (which I think is typical?) it takes 400ms. The same goes for node/npx and ruby/bundle. Compare to an ahead-of-time compiled binary from go, which can boot and print hello in 3ms on my machine -- it has between 10x to 100x the wallclock budget the python program just spends booting up.
These days I'd say tools pipx (and now also uv) are far more common than pyenv for tool management