Help optimize D solution to phone encoding problem: extremely slow performace.
Jordan Wilson
wilsonjord at gmail.com
Sun Jan 14 10:02:58 UTC 2024
On Saturday, 13 January 2024 at 11:03:42 UTC, Renato wrote:
> I like to use a phone encoding problem to determine the
> strenghtness and weaknesses of programming languages because
> this problem is easy enough I can write solutions in any
> language in a few hours, but complex enough to exercise lots of
> interesting parts of the language.
>
> [...]
Hello Renato,
This seems to be quite a lot of calls:
```
======== Timer frequency unknown, Times are in Megaticks ========
Num Tree Func Per
Calls Time Time Call
19204964 3761 3756 0 pure nothrow ref
@trusted immutable(char)[][]
core.internal.array.appending._d_arrayappendcTX!(immutable(char)[][], immutable(char)[])._d_arrayappendcTX(scope return ref immutable(char)[][], ulong)
19204924 8957 3474 0 @safe void
dencoder.printTranslations(immutable(char)[][][dencoder.Key],
dencoder.ISolutionHandler, immutable(char)[], immutable(char)[],
immutable(char)[][])
```
This is when using the `words-quarter.txt` input (the
`dictionary.txt` input seems to finish much faster, although
still slower than `java`/`rust`).
I also used only 100 phone numbers as input.
My final observation is that `words-quarter.txt` contains some
1-letter inputs, (for example, `i` or `m`)...this may result in a
large number of encoding permutations, which may explain the high
number of recursion calls?
Jordan
More information about the Digitalmars-d-learn
mailing list