That's only vis-a-vis the Main.java Java implementation, which has a different algorithm, not implementation. The author is not referring to the CL implementation (note that the author explicitly calls out Main2.java, CL, and the Rust versions as being the most similar and worthy of being benchmarked). The Main.java one is more of a curio than anything else, which the author threw in because it was the first implementation they wrote (the article acknowledges it has a different algo and is therefore not directly comparable to the other two). This is not what the author is referring to when they say "well-optimised" (note that the article explicitly excludes Main.java from a lot of its valid comparisons, e.g. "Because the Rust code implements a similar algorihm to Java’s Main2, NOT Main, we should not conclude that Java can beat Rust in speed!")
The main comparison of the article is Main2.java, main.rs, and main.lisp, as the author both calls out in the article and the attached GitHub repo (as is apparent in the author's choice of optimizations; if it was a comparison of algos, then the CL and Rust versions would be rewritten to use tries as well).
The point is the author did not explicitly call out this current Rust iteration as explicitly suboptimal RE CL. The closest the article comes to calling the Rust iteration suboptimal is
> However, the Java and Rust implementations were, as CL’s, written without much thought given to performance, after all the description of the original study which introduced the problem asked participants to focus on correctness and readability, not performance.
which is referring to the previous iteration of the code, not the current one.
(It's also evident from Cryptonic and chrismorgan's comments they are talking about implementation-level concerns, not algo-level ones such as Main2.java vs the other implementations)
There are two or three branches with different versions of the Rust code, and the author is using the fastest one. What you believe will make the Rust code faster won't, trust me.
If you think I'm wrong, could you please submit a PR and link here?
@Cryptonic 's suggestions are laughable. Try using arrays as HashMap keys in Rust :D nope, won't even compile let alone be fast. There was a way smarter attempt here to do something *based on* arrays: https://github.com/renatoathaydes/prechelt-phone-number-enco...
The DigitBytes struct is needed because just using arrays (I guess they mean slices, as arrays are obviously wrong) is incredibly slow - it would need to consider the whole array every time instead of just the relevant bytes - far slower than `Vec`. This is indeed fast, but slower than Vec.
The other suggestion: print everything at the end?? Do we even know what the objective is here? It's not to finish first, but to show to the user the results as soon as possible. It's like people don't even read the problem proposition and still think it's ok to criticize... also, Rust is using buffered IO... ALSO, the benchmark only prints a single line at the end for the two last runs, essentially doing "print it all at the end".
I think you're missing the point of my comments. I know neither enough of CL nor Rust to make a comment on the performance (I have less than ~1000 lines of experience in either and have only built the smallest of toy projects in either language).
mst stated that the author explicitly called out the Rust code as suboptimal. That is a misreading of the original text, which was referring to a previous iteration. The author (and you) clearly does not think the current Rust code is suboptimal.
> The author (and you) clearly does not think the current Rust code is suboptimal.
Sorry if it looked like I was being harsh on you particularly, I was not... I was being harsh on people making comments like "this Rust code is very slow" without showing their faster code, making suggestions that would almost certainly be slower or not even compile and other similar things I observed in this thread.
Never believe anyone saying "this could be much faster" without showing their code so people can actually check it.
I will believe the OP's code is slow when I see a faster implementation, which I haven't.
Fair enough. I stand by that so far as I can tell he incorporated every implementation optimisation he got as feedback, but you're dead right that I didn't represent his wording correctly.
The main comparison of the article is Main2.java, main.rs, and main.lisp, as the author both calls out in the article and the attached GitHub repo (as is apparent in the author's choice of optimizations; if it was a comparison of algos, then the CL and Rust versions would be rewritten to use tries as well).
The point is the author did not explicitly call out this current Rust iteration as explicitly suboptimal RE CL. The closest the article comes to calling the Rust iteration suboptimal is
> However, the Java and Rust implementations were, as CL’s, written without much thought given to performance, after all the description of the original study which introduced the problem asked participants to focus on correctness and readability, not performance.
which is referring to the previous iteration of the code, not the current one.
(It's also evident from Cryptonic and chrismorgan's comments they are talking about implementation-level concerns, not algo-level ones such as Main2.java vs the other implementations)