Earlier quoted context omitted.
It's a single implementation, I wouldn't put too much on it. I can definitely write a C++ implementation that's slower and less optimised than most of those results, particularly if I was using Boost. iPhone and Mac apps run pretty well in my experience, and Swift is definitely faster (in general) than Python at least. There were some serious considerations to port over ML libraries to Swift due to its ease of use, s…
> There were some serious considerations to port over ML libraries to Swift due to its ease of use, similar to Python, while providing much better execution speed. Google abandoned that Swift work (if that's what you're referring to)
Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
141–150 of 234 posts
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#142Earlier quoted context omitted.
Is what a compiled language? For Knuth's program in the Programming Pearls article? He wrote it in Pascal, so not a scripting language.
I thought he wrote it in his own language, WEB.
WEAVE takes a WEB source file and generates proper TeX out of it. TANGLE takes a WEB source file and generates proper Pascal.
The code written in WEB (and variants) is not necessarily in proper order for compilation, and can contain references to other blogs which are included as text-inclusions. I've never used WEB proper, but in org-mode there is org-babel. Its syntax is something like this (from memory, I use shortcuts so I don't have to memorize all the details and type them out):
To handle user input, the program will read from a file.
#+NAME: open-file (a better name would be used in a real program)
#+BEGIN_SRC lisp :noweb yes
(with-open-file (f filepath)
>)
#+END_SRC
elsewhere The actual parsing will look like:
#+NAME: parsing
#+BEGIN_SRC lisp :noweb yes
...
#+END_SRC
And the order of these can be reversed, the correct output will be produced with a few other settings and options. With org-babel, when you tangle the org file it will generate one or more source files based on the options and settings you've used throughout the org file itself. Instead of WEAVE, you would just use the standard org export settings.Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#143This is a rather meaningless comparison, since the differences are going to be dominated by: 1) The choice of libraries/datatypes used for strings and word->count map 2) How the source file is split into words - probably library function again, although in C/C++ one could choose to implement a super-optimized low level version that would blow the others away IMO a performance comparison between languages is only mean…
I think even if it's dominated by libs and data types I think it has value as it might reflect what actually happens out there in the wild rather than a purely academic exercise.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#144The code:
SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, count() AS c FROM file('kjvbible.txt', LineAsString) WHERE notEmpty(word) GROUP BY word ORDER BY c DESC FORMAT Null
or:
clickhouse-local --query "SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, count() AS c FROM file('kjvbible.txt', LineAsString) WHERE notEmpty(word) GROUP BY word ORDER BY c DESC" > /dev/null
It is using only a single thread.
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#145I've checked with ClickHouse and the result is better than I expect... it runs in 0.043 sec. on my machine, which is faster than any other result. The code: SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, count() AS c FROM file('kjvbible.txt', LineAsString) WHERE notEmpty(word) GROUP BY word ORDER BY c DESC FORMAT Null or: clickhouse-local --query "SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, cou…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#146I've checked with ClickHouse and the result is better than I expect... it runs in 0.043 sec. on my machine, which is faster than any other result. The code: SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, count() AS c FROM file('kjvbible.txt', LineAsString) WHERE notEmpty(word) GROUP BY word ORDER BY c DESC FORMAT Null or: clickhouse-local --query "SELECT arrayJoin(splitByChar(' ', lower(line))) AS word, cou…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#147Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#148Re: the Rust optimized implementation, I was able to get ~20-25% better performance by rewriting the for loops as iterators, using Rust's byte range pattern matching, and a buffered writer, which seems crazy, but it's true. I chalked it up to some crazy ILP/SIMD tricks the compiler is doing. I even submitted a PR[0], but Ben decided he was tired of maintaining and decided to archive the project (which fair enough!).…
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#149I had a 1 minute look at the "optimized" C code - it's calling malloc for every word.
Doesn't malloc return a pointer? Sounds unsafe
Re: Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
#150Or maybe the difference is just noise? It's hard to tell without more details on how the benchmarks were run.