On Fri, 23 Apr 2010 12:28:55 -0400, Joseph Wakeling
<joseph.wakel...@webdrake.net> wrote:
Steven Schveighoffer wrote:
As long as you discount the vast differences in allocation performance,
the code generated should be just as good as code generated by a C++
compiler. Your interpretation of performance did not focus on the right
part :) Your test application heavily used allocation and reallocation,
things that have nothing to do with how fast the code compiled by the
compiler is, but are based more on the algorithms behind the
allocation. An equivalent C++-based GC would probably show similar
performance (in fact, I think D's GC was based on a C++ GC).
This is all taken with a grain of salt of course, the perception is
often more important than the technical details. This thread being a
prime example of it.
I do see the point about allocation and reallocation -- what was
bothering me a bit was that even taking those aspects out of the code
and preallocating everything, I could write C++ code that _didn't_
preallocate and still ran (much) faster ... :-)
If you are comparing vector's push_back to D's array append after
pre-allocating, you are still not comparing apples to apples...
Array appending is working without context -- it has no idea who owns the
data or how big it is until it does a GC query. vector owns the data and
knows exactly how big it is, so no expensive lookup needed. The benefit
of D arrays is you can pass them, or slices of them, around without
copying or worrying about them being deallocated very cheaply.
D's standard library should have a construct that duplicates the
performance of vector, I'm not sure if there is anything right now. I
thought Appender would do it, but you have said in the past it is slow.
This needs to be remedied.
-Steve