> Incidentally, this problem set the scene for a wizard duel between two computer scientists several decades ago. In 1986, Jon Bentley asked Donald Knuth to show off “literate programming” with a solution to this problem, and he came up with an exquisite, ten-page Knuthian masterpiece. Then Doug McIlroy (the inventor of Unix pipelines) replied with a one-liner Unix shell version using tr, sort, and uniq. Since this w…
Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
11–20 of 234 posts
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#12Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#13When I've been asked this in programming interviews, I've almost always been expected to produce something like the code in the article (and do), but usually I'd point to something like the NLTK library as a better approach. It's polished and highly capable, and handles probably just about every edge case there is.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#14Wow. Swift, touted as "safe by design and (...) runs lightning-fast"[1] is more of a screw-up than I thought. Almost twice as slow as Lua and behind even Pascal and Forth. [1] https://developer.apple.com/swift/
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#15> Incidentally, this problem set the scene for a wizard duel between two computer scientists several decades ago. In 1986, Jon Bentley asked Donald Knuth to show off “literate programming” with a solution to this problem, and he came up with an exquisite, ten-page Knuthian masterpiece. Then Doug McIlroy (the inventor of Unix pipelines) replied with a one-liner Unix shell version using tr, sort, and uniq. Since this w…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#16Wow. Swift, touted as "safe by design and (...) runs lightning-fast"[1] is more of a screw-up than I thought. Almost twice as slow as Lua and behind even Pascal and Forth. [1] https://developer.apple.com/swift/
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#17Wow. Swift, touted as "safe by design and (...) runs lightning-fast"[1] is more of a screw-up than I thought. Almost twice as slow as Lua and behind even Pascal and Forth. [1] https://developer.apple.com/swift/
"Lightning fast" can mean a lot of things, and it might not mean "executables start quickly."
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#18 CALL runtime.mapaccess2_fast64(SB)
whereas the 'raw' version uses CALL runtime.mapassign_fast64(SB)
When reading the Go solution this bit stood out to me> To reduce the allocations, we’ll use a map[string]*int instead of map[string]int so we only have to allocate once per unique word, instead of for every increment
I just tried benchmarking this with a simple setup and I get zero allocations for both approaches, although the "pointer" approach is slightly faster
package main
import (
"testing"
)
func BenchmarkIncrementMapRawInt(b *testing.B) {
var data = make(map[int]int)
b.ResetTimer()
for i := 0; i Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#19EDIT: I think the use of the term "allocation" might be overloaded here from the original article, after thinking about this a bit more I think the author is referring to a different way of accessing the map. If you look in godbolt https://godbolt.org/z/Yf64rodW6 you can see that the pointer version uses CALL runtime.mapaccess2_fast64(SB) whereas the 'raw' version uses CALL runtime.mapassign_fast64(SB) When reading t…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#20I even submitted a PR[0], but Ben decided he was tired of maintaining and decided to archive the project (which fair enough!).