4 ms·
Interestingly, a trivial production program, http://pastebin.com/m6eb5ac73 http://pastebin.com/m6eb5ac73 became several times as slow with it. A simple affair t
by Erwin 17y ago
Interestingly, a trivial production program, http://pastebin.com/m6eb5ac73 http://pastebin.com/m6eb5ac73 became several times as slow with it. A simple affair that removes entries in file A that are in file B, by reading contents of B into a set then iterating over A, applied to file A being $(seq 1 7000000) and file B being $(seq 500 150000).
I guess that shows how well tuned Python's sets/dicts are -- gprof suggested most time was spent in Shedskin's sets, looking up keys/comparing keys; even using -O3 did not help.
I currently use Pyrex (Cython is a newer version of it), successfully to write 5% of the code in its Pythony C. It's rare in my case that I can find a spot which can be easily rewritten in C; it may be 5% of the code that's time-intensive but it's 5% using all sorts of complex data structures created by the other 95%.
- kingkilr 17y agoPython's set is ridiculously optimized (since it's based on the dictionary which is used bloody everywhere). A few months ago when the "hashtables in functional languages" benchmarks were going around I implemented the "stick the numbers 1 through a million in a hash table and then get 1 out" thing in both Python and C++. Python was faster with no -O provided, and a little slower with -O3, but massively faster if you added psyco to Python.