Help optimize D solution to phone encoding problem: extremely slow performace.
H. S. Teoh
hsteoh at qfbox.info
Wed Jan 17 15:57:02 UTC 2024
On Wed, Jan 17, 2024 at 07:19:39AM +0000, Renato via Digitalmars-d-learn wrote:
> On Tuesday, 16 January 2024 at 22:13:55 UTC, H. S. Teoh wrote:
> > used for the recursive calls. Getting rid of the .format ought to
> > speed it up a bit. Will try that now...
> >
>
> That will make no difference for the `count` option which is where
> your solution was very slow.
Of course it will. Passing the data directly to the callback that bumps
a counter is faster than allocating a new string, formatting the data,
and then passing it to the callback that bumps a counter. It may not
look like much, but avoiding unnecessary GC allocations means the GC
will have less work to do later when a collection is run, thus you save
time over the long term.
> To run the slow test manually use the `words_quarter.txt` dictionary
> (the phone numbers file doesn't matter much - it's all in the
> dictionary).
>
> But pls run the benchmarks yourself as I am not going to keep running
> it for you, and would be nice if you posted your solution on a Gist
> for example, pasting lots of code in the forum makes it difficult to
> follow.
I'll push the code to github.
T
--
"No, John. I want formats that are actually useful, rather than over-featured megaliths that address all questions by piling on ridiculous internal links in forms which are hideously over-complex." -- Simon St. Laurent on xml-dev
More information about the Digitalmars-d-learn
mailing list