5 ms·
This doesn't seem to be comparing anything like the same thing. Does the Haskell version really do the same thing as the C version? Does it handle all of the sa
by notacoward 7y ago
This doesn't seem to be comparing anything like the same thing. Does the Haskell version really do the same thing as the C version? Does it handle all of the same error cases, providing the same quality of error messages if they occur? Does it handle localization? If not, that makes the comparison very skewed, as unhammer already pointed out. Sure, if you strip out all of the things that the people who wrote wc actually spent all that time on then you can go faster, but failing to note the differences is simply dishonest.
- phonebucket 7y ago> This doesn't seem to be comparing anything like the same thing. This is a fair point, and I believe this whole series of 'Beating C with foo' posts could have been better named. But I'm of the opinion that the whole series is about showcasing various language's strengths and weaknesses, while using GNU wc as a benchmark. From this perspective, I've learnt a bit about several languages I knew nothing about, so I rather like these articles, despite the fact that their titles might be a bit misleading.
- thanatropism 7y agoIt's all about tone. Everyone remembers being a brash know-nothing teenager, so just by the headline "DESTROYING C" you get that vibe. I remember having a blog about Haskell circa 2002 where I would smugly enumerate the ways in which Guido van Rossum was wrong. "GUIDO IS WRONG! PART 4" my post titles would say.
- deleted 7y ago[deleted]
- dddbbb 7y agoThey explicitly say in the introduction that this is a toy version, and then in the conclusion that a future post will look at a more complete substitute.
- acl777 7y agoGood point. I was thinking the same thing too. I will wait for what the next article presents, as the end of this article states: > Stay tuned for a second part, where we will investigate shaping all this into an actual wc substitute, where different statistics can be turned on or off, all while not computing what the user hasn’t requested.
- jacobush 7y agoDoes it handle multiple files, and stdin? Anyway, destroying Haskell with 100 lines of C :-) https://raw.githubusercontent.com/gdevic/minix1/master/commands/wc.c https://raw.githubusercontent.com/gdevic/minix1/master/comma...
- jstimpfle 7y agoDo you get a speed-up if you use getc_unlocked() instead of getc()? And if you write your own isspace()? As far as I know, isspace() is locale sensitive.
- sauerbraten 7y agoisspace is defined as a macro at the top of the file, and it's definitely not locale sensitive ;)
- hrgiger 7y agoI see and raise, to one line: https://www.ioccc.org/2019/burton/prog.c https://www.ioccc.org/2019/burton/prog.c It is the Burton entry from The International Obfuscated C Code Contest, but seems like only handling ascii https://www.ioccc.org/years-spoiler.html https://www.ioccc.org/years-spoiler.html Limits: "Requires the C locale and ASCII character set. Input should be less than ten million octets to avoid this problem." https://www.ioccc.org/2019/burton/hint.html https://www.ioccc.org/2019/burton/hint.html
- ulucs 7y agoIsn't 100 lines too much for a simple utility like wc? I get that it has many edge cases to cover, but edge cases usually require some different handling when you run into them anyway. I'd rather use my one-liner (including calculation in a single pass, and even parallel processing!): wc:{sum (({1};ceiling 0.5*sum differ " "=;{1+count x})@\:) peach read0 x}
- shawnz 7y ago> failing to note the differences is simply dishonest. Like yourself, I think any reader could understand that this is meant to be a toy implementation. The author even says so in the very first paragraph and at several points in the article thereafter. How is that dishonest?
- ckastner 7y agoBecause that makes the programs sufficiently different that the conclusion about "smashing" seems dishonest. Apples smash Oranges, etc.
- 0xd34df00d 7y agoSup, author here. > Does the Haskell version really do the same thing as the C version? It counts bytes, words and lines and, modulo intended Unicode space handling and unintended bugs, does the same thing. Indeed, it does not count things like max line length or char count, but those can be plugged in without significant performance overhead (and that's what the second part is gonna be about). > Does it handle all of the same error cases, providing the same quality of error messages if they occur? There are no error messages at this point. Although I don't really see how this should affect performance. > Does it handle localization? If you mean counting multi-byte characters, then not yet. Although I'm pretty convinced it does not require doing something much more complicated — but maybe I'm wrong, we'll see in the next part. Also, thanks for the feedback, those are important questions! Something to keep in mind when writing subsequent posts.
- ColinWright 7y agoReproducing what your code does in the most simple, naive C program possible, I can beat the existing wc utility, taking only around 40% of the time that wc takes. So until you put in locale handling, alternate line endings, option handling, and error handling, I don't see that your post is at all convincing. Quite the opposite. So I look forward to a Haskell version that supports everything the wc has so we can get a fair comparison.
- 0xd34df00d 7y ago> So until you put in locale handling, alternate line endings, option handling, and error handling, I don't see that your post is at all convincing. That's precisely what the second part would be about. And, if I succeed, IMO, that's where Haskell would really shine (because composability and local reasoning), and where I would be able to claim to achieve something — the stuff in the post we're discussing is indeed trivial (I didn't want to say that in the post itself though as I think it'll look like I'm belittling the guy who did the original post), while modularizing this is _fun_.
- ColinWright 7y ago
- noxToken 7y agoOff-topic but tangentially related. There was Reddit post[0] about a clothes dryer's eco mode being a scam since it consumes more power than a regular drying cycle. Here[1] is a single comment thread noting that the user was measuring power output of the entire house. The user quickly changed their tune when this was highlighted. [0]: https://old.reddit.com/r/dataisbeautiful/comments/eyevca/my_clothes_dryers_eco_mode_is_a_dirty_liar_oc/fggrc27/ https://old.reddit.com/r/dataisbeautiful/comments/eyevca/my_... [1]: https://old.reddit.com/r/dataisbeautiful/comments/eyevca/my_clothes_dryers_eco_mode_is_a_dirty_liar_oc/fghn1ae/?context=2 https://old.reddit.com/r/dataisbeautiful/comments/eyevca/my_...
- hnlmorg 7y agoHe's not handling unicode and it's been well demonstrated in the past that unicode handling adds a lot to computation time in tests like these (it often comes up in grep benchmarks too). I'd be interested to see the same tests but with a non-unicode local set, IIRC: LC_ALL=C I'd wager the C version would perform much better in that test.
- jstimpfle 7y agoDon't forget to export the variable, or run like "LC_ALL=C wc ...", or otherwise the locale won't apply.