4 ms·
>I feel like in the case of some it's just parroting someone elses argument. It usually is. The reality is that like most memes like this, there's a grain of
by imanaccount247 12y ago
>I feel like in the case of some it's just parroting someone elses argument.
It usually is. The reality is that like most memes like this, there's a grain of truth at the center, but most of the people repeating it don't know where the truth ends and the exaggeration begins.
Regex-dna is using low level ByteString operations to squeeze out a bit of extra performance. This makes it quite a bit longer and would rarely be done in practice since the gain is small.
Fasta again does some low level ByteString operations, but not nearly as significant as regex-dna. Not that bad.
Others like fannkuch-redux are just using "unsafe" vector functions. All that is doing is leaving out bounds checks. That makes an miniscule difference in performance most of the time, but the way the shootout works there's only incentive to completely optimize for speed, so you get 1% optimizations you wouldn't normally see. I'd hardly call it unidiomatic though, you just normally use "read" instead of "unsafeRead", etc. In some cases I would say the unsafe calls are idiomatic. If you are going to be doing an operation repeatedly in a loop, doing the bounds checking once before looping and using the non-bounds checked calls in the loop is pretty standard.
Pidigits is normal haskell (although you could argue the lack of spacing isn't idiomatic, but that hardly matters).
I stopped there since the rest are getting enough slower than rust, but looking them over there's still nothing outrageous, just more low level ByteString usage. Overall none of them are that far from idiomatic, none of them do anything particularly crazy, and I think the speed gains from doing most of the optimizations they are doing are fairly small. I find it particularly odd that people act like the ability to write lower level code that is faster is a problem with haskell. Especially given that the "low level" haskell versions are often still shorter and no harder to read than the "idiomatic" rust versions.
- bjz_ 12y agoOk, so perhaps I grant you the fact that unsafe indexing is idiomatic. The Rust code is still safer and more robust against buffer overflows in the long term. Also, isn't regex-dna using libpcre? That's a C library, no? Rust's regex library is pure Rust, with no unsafe code. I love Haskell, but I still don't think it occupies the same space as Rust.
- codygman 12y ago> I love Haskell, but I still don't think it occupies the same space as Rust. My opinion is that Haskell can overlap, but something that occupies the same space as rust would be Ivory[0] or ATS[1]. 0: http://hackage.haskell.org/package/ivory http://hackage.haskell.org/package/ivory 1: http://www.ats-lang.org/ http://www.ats-lang.org/
- imanaccount247 12y ago>Also, isn't regex-dna using libpcre? It is in virtually every language on the shootout. That's one of the reasons the shootout is so terrible. A regex benchmark doesn't tell you much of anything unless the task itself is to write the regex engine. >I love Haskell, but I still don't think it occupies the same space as Rust. Neither do I. I am simply correcting this weird meme that "haskell is really slow and the shootout shows you have to write insane code to be fast" when the whole point of the shootout is to write the fastest code you can, the haskell code is pretty ordinary and still significantly better than most other languages, and an "idiomatic" version is not 10 times slower, it is 10% slower.
- igouy 12y ago> A regex benchmark doesn't tell you much of anything… And yet, the programs don't all perform the same. One regex task doesn't tell you much of anything because so much can be different with a different task. Then again, people are usually surprised by V8 and Irregexp. The GHC version has been updated so many times since the last programs were contributed, that I hope the code would look better if it was written to use the latest greatest Haskell.
- imanaccount247 12y ago>And yet, the programs don't all perform the same. Because they don't all use pcre. Duh? >The GHC version has been updated so many times since the last programs were contributed, that I hope the code would look better if it was written to use the latest greatest Haskell. Why on earth would the code change because of a new compiler release? Do people rewrite the C one every time a new GCC is released? And the code looks fine, what "better" do you want?
- coldtea 12y ago>I'd hardly call it unidiomatic though, you just normally use "read" instead of "unsafeRead", etc. Isn't "idiomatic" defined by what you "normally" use?
- imanaccount247 12y agoDoes using a less commonly used function for its intended purpose make the code unidiomatic?
- coldtea 12y agoIf the goal of using the less commonly used functions is performance, then it probably does. I mean: it's not like the specific problem domain needed a "less commonly used function" (e.g. you need a function to do X, where X is something that you rarely need to perform). Rather it's: "we need to code A, but we will use less commonly used functions instead of what we'd normally use for A, just to get more performance". Plus, it's not like you merely exchange function f with g, while all other factors stay the same. The choice of those "less commonly used functions" also affects other aspects of the program's design (e.g. making it into a more imperative style, going for unsafe, opting for mutability, etc). So the interesting question to call it idiomatic or not, for me, is: "If ultimate performance wasn't a factor, would a Haskell programmer write this program in the same way?"
- imanaccount247 12y ago>Plus, it's not like you merely exchange function f with g, while all other factors stay the same Yes, it is exactly like that. That was the point. It is literally changing out the name of a function. It has absolutely no effect on the rest of the code. Which is why the code is idiomatic by any reasonable definition.
- Edman274 12y agoIf the only differences between the functions are the names and the performance characteristics, then why even bother having the slower versions? There has to be some difference somewhere, right?