On Thu, 17 Mar 2011 11:06:34 -0400, bearophile <bearophileh...@lycos.com> wrote:

About the versions:

This benchmark (test1/Test1) comes from a reduction of some code of mine, it converts integer numbers to string and builds a single very long string with them. I have seen the Java code significantly faster than the D one.

The successive benchmarks are experiments to better understand where the low performance comes from:

test2a/Test2a just build the string, without integer conversions.

test2b/Test2b just convert ints to strings.

test3 is a try to perform a faster int to string conversion using the C library.

test4 is my faster D solution, it shows that there are ways to write a D program faster than the Java code, but they aren't handy.

Hi bearophile,
Since I've been working on this problem recently, here's an analysis of what's happening: Both Appender and your test cases work by growing an array in a 'smart' manner. The issue with this approach is that once the arrays get big the conservative GC starts pinning them due to false pointers. This slows down the GC a lot (due to some naivety in the GC, which is being patched) and creates excessive memory usage. And I would hazard that Java's StringBuilder isn't giving you O(1) access to the underlying array like Appender is, which would allow it to drastically reduce memory churn.

In the future, you should also include program ram usages in these kind of benchmarks.

Reply via email to