Beating C with Common Lisp
verisimilitudes.net
verisimilitudes.net
The blasé attitude toward adhering to POSIX/GNU wc behavior was a bit dissatisfying to me. Those additions are “trivial” and probably don’t change the shape of the program too much, but are nonetheless complicating and time-consuming factors. I would prefer that Lispers strive to complete 100% of the job, not the 80% cut that matters to them. :)
With all that said, I agree with the opinion of the article, being preferable to write Lisp over C, though I would be up-front about the meaning of “beating C”. C has been beat—in my and the author’s opinion—because Lisp strikes an unusually good balance between execution efficiency, speed of development, program safety, and expressiveness. But even better, Lisp lets you push in any of these directions, often with only modest sacrifices in the others.
However, the original spirit of the wc exercise was to make it fast, Benchmarks Game-style.
The reason I didn't strictly adhere to the POSIX behavior was because I don't know where this is documented and don't feel like scanning through the C to find out. On all of the files I've tested, which include a wide array of punctuation and other such things, the results were identical, but I'm merely not making any promises. I'd prefer to not be accused of being one of those Lispers who only complete part of the program; if you look at the libraries I've written, which actually concern me, then you'll find they're well-documented and rather comprehensive for their purposes.
[1] compiler https://github.com/rigetti/quilc
[2] simulator https://github.com/rigetti/qvm
I wrote it in reply to an earlier post, where someone "beat C" with Haskell.
That being said, even with all the extra stuff it's doing, I'd assume it to perform roughly as well as your single-threaded version (when you use a non-multibyte locale to keep the comparison even remotely fair).
alx@foo:~/Git$ time ./wc/threads 1 twc/big.txt
128457 1095695 6488666
real 0m0.022s
user 0m0.022s
sys 0m0.000s
alx@foo:~/Git$ time ./twc/twc twc/big.txt
128457 1095695 6488666 twc/big.txt
real 0m0.037s
user 0m0.025s
sys 0m0.012sOnce upon a time
https://salsa.debian.org/benchmarksgame-team/archive-alioth-...
https://web.archive.org/web/20010616231931/http://www.bagley...
Which I don't see what the point of the article is then. It's just some guy ranting about his preferences I guess. Which is fine, but like... lead with that.
> A criticism would be pointing out that the C program must initialize and parse arguments and other such things, and yet I believe this is more points for the Common Lisp than against, as it's entirely unreasonable to waste so many resources for such a trivial result.
The author should make up their mind whether they're comparing programming languages or more high-level design decisions (should functionality deserve its own executable, etc). In the current form, I can't see a strong point made regarding either of these questions.
Ok. Not the best article. I'm sure there was a better point to be made
They also compared a bare-bones wc program that only needs to care about the happy path versus one that needs to be fully featured and flexible (e.g. handling unicode with the -m flag, etc.)
But with this approach it's also trivial to beat C with, well, C. (Actually I cheated a bit and used C++, but same idea. Got roughly 10x speedup in WSL on windows with a naive approach).
> Lisp is still #1 for key algorithmic techniques such as recursion and condescension.
--Verity Stob
I am at this point entirely unsure if the author is knowingly self-deprecating or unknowingly proving Ms Stob correct.
Additionally that article should be updated in what matters Windows, as Microsoft has been moving everything into C++ since Vista.
https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...
https://docs.microsoft.com/en-us/cpp/build/reference/kernel-...
https://docs.microsoft.com/de-de/windows-hardware/drivers/ge...
https://devblogs.microsoft.com/cppblog/the-great-c-runtime-c...
> We have converted most of the CRT sources to compile as C++, enabling us to replace many ugly C idioms with simpler and more advanced C++ constructs. The publicly callable functions are still declared as C functions, of course (extern "C" in C++), so they can still be called from C. But internally we now take full advantage of the C++ language and its many useful features.
1. You didn't actually beat C, as shown by your own measurements.
2. You move the goalposts to support your article.
This is not a good article.
https://news.ycombinator.com/item?id=21490714 "It’s Not Enough to Be Right – You Also Have to Be Kind", 9 days ago.
The article on kindness was well worth reading, thank you. It ends
"If you can’t be kind, if you won’t empathize, then you’re not on the team. That team is Team Humanity, where we are all in this thing together. Where we are all flawed and imperfect. Where we treat other people’s point of view as charitably as we treat our own. Where we are civilized and respectful and, above all, kind to each other—particularly the less fortunate, the mistaken, and the afraid."
https://forge.medium.com/its-not-enough-to-be-right-you-also...
Of course Lisp is the opposite of new, but it has had more time than any other to get itself together.