The worst Phobos template (in binderoo)
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Wed Sep 14 14:06:10 PDT 2016
On 09/14/2016 04:52 PM, Stefan Koch wrote:
> On Wednesday, 14 September 2016 at 20:24:13 UTC, Stefan Koch wrote:
>> It takes a whooping 500 milliseconds
> Ahm... I misread my performance graph
> it's 138ms for the first instanciation.
> and around 5ms for every following one.
> the total time spent on it was 500ms
(Disclaimer: I didn't run any speed tests.) By looking at the definition
of fullyQualifiedName it seems to me we can go a long way with
traditional optimization techniques. For example consider:
string result = join(
map!(a => format("%s%s", a[0], a[1]))(
zip([staticMap!(storageClassesString, parameterStC)],
[staticMap!(fullyQualifiedName, parameters)])),
This is neat, and it's neat squared because it works during compilation,
but at some point if the resulting code runs slowly, there's no shame in
applying old school optimization. Instead of join/map a simple loop
should suffice; no need to use format with "%s%s" over simple
concatenation; array zipping may be done with simple loops too.
Same a few lines below - just replace return format("%s%s%s%s%s%s%s%s",
...) with simple concatenation. Same goes with format("shared(%s)",
...), format("%s(%s)", ...) etc. In casual runtime code such code is
totally fine, but in library code we'd do good to eliminate the use of
format (which is a mini-interpreter) if speed considerations tell us to.
The unittests seem excessive too. Yes, there is such a thing as too much
of a good thing. And use a lot of format during compilation as well :o).
In unittests, a bunch of static asserts may be replaced with regular
asserts.
Andrei
More information about the Digitalmars-d
mailing list