Getting the names of all the top-level functions in module

Stefan Koch uplink.coder at googlemail.com
Tue Sep 21 22:53:26 UTC 2021


On Tuesday, 21 September 2021 at 17:15:23 UTC, Stefan Koch wrote:
> On Tuesday, 21 September 2021 at 15:18:01 UTC, Stefan Koch 
> wrote:
>> On Tuesday, 21 September 2021 at 15:07:35 UTC, Adam D Ruppe 
>> wrote:
>>> Here's one with param names:
>>>
>>> ----
>>>
>
> I've done a little benchmark the core.reflect version vs the 
> template version.
>
Scratch that.
It turns out I should have tested the output.

nodeFromName will return an Import node in this case, so the 
dynamic cast to module fails and CTFE it never ran to from the 
datastructure.

Hence the previous number are garbage.
Here is an updated version.
We can see that the CTFE overhead is clearly dominating here.

| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| -version=arsd #64 | 40.9 ± 2.2 | 35.9 | 45.9 | 1.24 ± 0.10 |
| #64 | 33.0 ± 2.2 | 28.0 | 38.0 | 1.00 |
| -version=arsd #192 | 71.3 ± 2.7 | 66.2 | 78.7 | 2.16 ± 0.16 |
| #192 | 44.9 ± 2.1 | 39.0 | 48.9 | 1.36 ± 0.11 |
| -version=arsd #320 | 94.3 ± 3.1 | 88.2 | 101.7 | 2.86 ± 0.21 |
| #320 | 57.9 ± 2.3 | 52.2 | 62.6 | 1.75 ± 0.13 |
| -version=arsd #448 | 128.3 ± 4.6 | 120.4 | 138.6 | 3.88 ± 0.29 |
| #448 | 72.4 ± 3.6 | 65.9 | 82.1 | 2.19 ± 0.18 |
| -version=arsd #576 | 162.9 ± 4.8 | 157.6 | 174.5 | 4.93 ± 0.36 |
| #576 | 87.7 ± 2.9 | 82.5 | 94.5 | 2.66 ± 0.20 |
| -version=arsd #704 | 198.7 ± 6.5 | 189.7 | 209.9 | 6.02 ± 0.44 |
| #704 | 103.3 ± 3.9 | 97.1 | 112.5 | 3.13 ± 0.24 |
| -version=arsd #832 | 235.2 ± 7.1 | 228.4 | 246.1 | 7.12 ± 0.52 |
| #832 | 121.9 ± 3.6 | 117.0 | 132.2 | 3.69 ± 0.27 |
| -version=arsd #960 | 275.2 ± 10.7 | 265.9 | 294.8 | 8.33 ± 0.64 
|
| #960 | 139.6 ± 3.0 | 134.6 | 147.9 | 4.23 ± 0.29 |
| -version=arsd #1088 | 311.1 ± 8.2 | 305.2 | 331.6 | 9.42 ± 0.67 
|
| #1088 | 162.0 ± 3.7 | 155.8 | 168.2 | 4.91 ± 0.34 |
| -version=arsd #1216 | 354.7 ± 13.6 | 342.3 | 381.1 | 10.74 ± 
0.82 |
| #1216 | 187.3 ± 6.2 | 180.2 | 206.4 | 5.67 ± 0.42 |
| -version=arsd #1344 | 400.7 ± 16.8 | 386.1 | 428.0 | 12.14 ± 
0.95 |
| #1344 | 210.6 ± 3.5 | 206.1 | 216.9 | 6.38 ± 0.43 |
| -version=arsd #1472 | 444.4 ± 15.7 | 430.5 | 470.7 | 13.46 ± 
1.01 |
| #1472 | 234.3 ± 3.8 | 230.2 | 241.3 | 7.10 ± 0.48 |
| -version=arsd #1600 | 504.6 ± 21.4 | 477.9 | 529.8 | 15.28 ± 
1.20 |
| #1600 | 261.9 ± 3.4 | 258.8 | 268.3 | 7.93 ± 0.53 |
| -version=arsd #1728 | 536.7 ± 18.8 | 523.3 | 572.7 | 16.25 ± 
1.21 |
| #1728 | 284.0 ± 2.2 | 281.3 | 288.3 | 8.60 ± 0.57 |
| -version=arsd #1856 | 586.4 ± 17.6 | 570.5 | 625.1 | 17.76 ± 
1.29 |
| #1856 | 319.4 ± 13.6 | 309.4 | 352.2 | 9.67 ± 0.76 |
| -version=arsd #1984 | 630.5 ± 18.9 | 619.1 | 683.6 | 19.09 ± 
1.38 |
| #1984 | 344.8 ± 10.5 | 329.6 | 360.8 | 10.44 ± 0.76 |

So those are the proper numbers.
And instead of a 10x change we have what almost seems to be a 
constant difference.
The simple truth of this is that the CTFE concatenation is the 
weak link here.

![plot](https://i.ibb.co/KWpd4vS/real-diff.png")

blue is the template
red is core reflect.



More information about the Digitalmars-d mailing list