[Rosettacode] Growable slices
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 16 08:32:49 PDT 2014
On Friday, 16 May 2014 at 15:20:04 UTC, bearophile wrote:
> Artur Skawina:
>
>> Ugh. So how does it perform wrt the D version that I wrote for
>> you last time? [1]
>
> I have done a benchmark with the various version (the first 3
> are the ones on the Rosettacode site, and the #4 is yours):
>
> lzw1: 0.39
> lzw2: 0.17
> lzw3: 0.21
> lzw4: 0.17
>
> I think your comment was about an older version of the first
> entry, that is non meant to be fast, just short and simple.
>
> I think the second version is enough. Do you agree?
>
> The third version should be more efficient but for such small
> files it's slower than the second.
>
> Bye,
> bearophile
Arguably, your code allocates a lot.
To speed it up, arguably, you could store a global immutable
string containing characters 0 to char.max + 1.
This way, when you build your dictionary (each time you enter
compress), you at least don't have to allocate the string, but
rather, slice your global immutable. Ditto for the lines "w =
[ch];", which allocates, you could instead do "w = gAllChars[ch
.. ch + 1]". (or "dict[b] = [b]" etc...)
Well, just a quick idea...
I'll give it a shot (next week).
More information about the Digitalmars-d-learn
mailing list