On Fri, 01 Mar 2013 19:19:35 -0500, cvk012c <[email protected]> wrote:

On Friday, 1 March 2013 at 21:52:13 UTC, bearophile wrote:
cvk012c:

I think that similar Perl and Java scripts will outperform D easily.
Thanks Andrei and simendsjo for a quick response though.

Why don't you write a Java version? It takes only few minutes, and you will have one more data point.


You are right. Why not. But instead of using Java split() method I used combination of indexOf() and substring() methods to do the same job. The reason: Java split method implemented as a regular expression which will be unfair to compare to D splitter. Again, I created a similar D version of the script, compiled it with all suggested options: -release -O -inline -noboundscheck and this time D version is more then twice slower than Java: 8.4 seconds vs 4. D experts, please, take a look at my code and tell me what is wrong with it.

Try my hand-written version (elsewhere in thread). I think it can be done better too (use pointers instead of arrays).

The issue is a combination of the fact that:
1. splitter is designed for any range, not just strings. Not an excuse really, but a string-specific version could be written that does better (clearly). 2. dmd is not always the best optimizer. I saw one other person who said using a different d compiler resulted in a quicker time. 3. Any time you are looping 10 million times, small insignificant differences will be magnified.

Note one other thing -- Be VERY wary of test cases that are fully-visible at compile time. Very smart compilers are known to reduce your code to something that isn't realistic. I remember seeing a similar comparison not too long ago where one wondered why g++ was so much faster (0.09 seconds or something) than D (4 or more seconds). Turns out, the g++ compiler optimized out his ENTIRE program :).

You may want to read in the "message" string at runtime to avoid such issues.

-Steve

Reply via email to