Am I do something wrong
Eric Suen
eric.suen.tech at gmail.com
Thu Sep 13 09:31:26 PDT 2007
D not even a dynamic language, why const will affect runtime
performance? besides, isn't all the LALR parser will using
giant const arrays? for examples: seatd(http://seatd.mainia.de/)
has a huge file called parser.d...
"Christopher Wright"
> Eric Suen wrote:
>> Hi,
>>
>> I write a very simple program, two version,
>> one is write in D, and others is using C, the D version
>> is extreme slow, the D version using 450 ms, but C version
>> using 0 ms, can anybody tell me is there anything wrong
>> in the code?
>>
>> Here is the code:
>> http://files-upload.com/files/499789/test.zip
>
> The compile time is also insanely long.
>
> If you just remove 'const' from those giant arrays (you'll have to assign
> base_action in your static constructor), you get a giant speed boost, both in
> compilation and in run time.
>
> Looking at the assembly, constant expansion means that your tAction function
> maps to 28000 lines of assembly if you have const arrays, or about fifteen if
> you have non-const arrays. Constant expansion of arrays is an optimization for
> small arrays, but this is slightly ridiculous.
>
> But the speed improvement from omitting 'const' puts the D version on par with
> the C. And if you want to get both the speed and the constness, I think you
> can have the giant array literals be private and mutable, and then expose some
> public const arrays that your static constructor sets as references to the
> private ones. (You can certainly do it in D2. Not sure about D1.)
More information about the Digitalmars-d-learn
mailing list