August 23, 2020
On Sunday, 23 August 2020 at 00:18:44 UTC, Per Nordlöw wrote:
> Builds are 10x slower than D.

And the slowdown of Ada compared to D gets larger with function size.
August 23, 2020
On 2020-08-23 02:20, Per Nordlöw via Digitalmars-d wrote:
> On Sunday, 23 August 2020 at 00:18:44 UTC, Per Nordlöw wrote:
>> Builds are 10x slower than D.
> 
> And the slowdown of Ada compared to D gets larger with function size.

It might get even slower if you apply:

-        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}));
+        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}_sum));

Currently, we're seeing:

main.adb:9049:32: invalid use of subtype mark in expression or call
gnatmake: "generated/ada/main.adb" compilation error
August 23, 2020
On Sunday, 23 August 2020 at 07:36:19 UTC, oddp wrote:
> It might get even slower if you apply:
>
> -        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}));
> +        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}_sum));
>
> Currently, we're seeing:
>
> main.adb:9049:32: invalid use of subtype mark in expression or call
> gnatmake: "generated/ada/main.adb" compilation error

Fixed. Thanks!
August 23, 2020
On Sunday, 23 August 2020 at 07:36:19 UTC, oddp wrote:
> It might get even slower if you apply:
>
> -        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}));
> +        f.write(Tm('''   GNAT.OS_Lib.OS_Exit(Integer(${T}_sum));
>
> Currently, we're seeing:
>
> main.adb:9049:32: invalid use of subtype mark in expression or call
> gnatmake: "generated/ada/main.adb" compilation error

Indeed, it does! :)

./benchmark --languages=D,Ada --function-count=20 --function-depth=450 --run-count=1

gives

| Lang-uage | Oper-ation | Temp-lated | Time [s/fn] | Slowdown vs [Best] | Version | Exec |
| :---: | :---: | --- | :---: | :---: | :---: | :---: |
| D | Build | No | 0.170 | 1.0 [D] | v2.093.1-541-ge54c041a4 | `dmd` |
| Ada | Build | No | 9.065 | 53.3 [D] | 10.2.0 | `gnat-10` |

!
August 26, 2020
On Thursday, 20 August 2020 at 20:50:25 UTC, Per Nordlöw wrote:
> After having evaluated the compilation speed of D compared to other languages at
>
>     https://github.com/nordlow/compiler-benchmark
>
> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?
>
> If so it most likely needs to use a backend other than LLVM.
>
> I believe Jai is supposed to do that but it hasn't been released yet.

V8 JavaScript compiles faster:

$ d8 --always-opt --trace-opt --single-threaded --no-compilation-cache mandelbrot.js | ts -s "%.s"
0.000025 [compiling method 0x3fc50821068d <JSFunction (sfi = 0x3fc508210165)> using TurboFan]
0.001651 [optimizing 0x3fc50821068d <JSFunction (sfi = 0x3fc508210165)> - took 4.455, 41.945, 0.052 ms]
0.001707 [optimizing 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> because --always-opt]
0.001736 [compiling method 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> using TurboFan]
0.001763 [optimizing 0x3fc508085b65 <JSFunction Complex (sfi = 0x3fc508210261)> - took 0.125, 0.284, 0.019 ms]
0.001789 [optimizing 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> because --always-opt]
0.001817 [compiling method 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> using TurboFan]
0.001842 [optimizing 0x3fc508211665 <JSFunction iterate_mandelbrot (sfi = 0x3fc508210229)> - took 0.167, 1.197, 0.022 ms]
0.001868 [optimizing 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> because --always-opt]
0.001892 [compiling method 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> using TurboFan]
0.001916 [optimizing 0x3fc508085b85 <JSFunction abs (sfi = 0x3fc508210299)> - took 0.125, 0.421, 0.025 ms]
0.002093 [optimizing 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> because --always-opt]
0.002337 [compiling method 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> using TurboFan]
0.002365 [optimizing 0x3fc508085bbd <JSFunction mul (sfi = 0x3fc508210309)> - took 0.134, 0.550, 0.023 ms]
0.002389 [optimizing 0x3fc508085ba1 <JSFunction add (sfi = 0x3fc5082102d1)> because --always-opt]
0.002498 [compiling method 0x3fc508085ba1 <JSFunction add (sfi = 0x3fc5082102d1)> using TurboFan]


--single-threaded disables compilation background tasks
--always-opt makes V8 immediately compile the function without profiling

Timestamps thanks to "ts" from moreutils.

$ time dmd -c mandelbrot.d

real	0m0.507s
user	0m0.416s
sys	0m0.094s

V8 compiles 202x faster.

-c to omit linking, which can be slow.

That's using the struct/double version. (I also ran it with timestamps on the verbose version, writing to disk accounted for a negligible amount of time.)

Obviously, take these results with a grain of salt, since --always-opt makes the compiled program very slow. But still, even with it off, V8 can compile very fast.

---

LDC2 takes 1.695 seconds to compile with no flags, and 2.126 seconds with O2.
QuickJS takes around 0.36 seconds to compile, but the program output is unbearably slow.

However, I suspect by the time the fastest and most balanced D compiler finishes compiling the program and executing it, V8 will already have finished executing it.
August 26, 2020
On Wednesday, 26 August 2020 at 01:13:47 UTC, James Lu wrote:
> However, I suspect by the time the fastest and most balanced D compiler finishes compiling the program and executing it, V8 will already have finished executing it.

DMD -O doesn't make a significant difference over DMD, clocking in at 12 seconds total.

LDC2 -O/-O2 has the best compilation-execution total, clocking in at 5.4 seconds. Subtracting the link time gets 5.0 seconds.

Its code generation phase (measured by measuring the time between -v's "code" and the link command) takes 2.6 seconds.

In contrast, compilation+execution for V8 JavaScript 2.0 seconds. V8's --trace-opt says it compiles each function once, and compilation (SSA creation, optimization, and code generation) takes a grand total of 0.027 seconds.

LDC's code generation is over 100 times slower. Surely there's opportunities for profiling and optimization here. (dmd's code generation is too bad to count.)
August 26, 2020
On Wednesday, 26 August 2020 at 01:31:01 UTC, James Lu wrote:
> LDC's code generation is over 100 times slower. Surely there's

Sorry, approximately 100 times slower, not over 100 times slower.
August 26, 2020
On Wednesday, 26 August 2020 at 01:31:01 UTC, James Lu wrote:
> On Wednesday, 26 August 2020 at 01:13:47 UTC, James Lu wrote:
>> However, I suspect by the time the fastest and most balanced D compiler finishes compiling the program and executing it, V8 will already have finished executing it.
>
> DMD -O doesn't make a significant difference over DMD, clocking in at 12 seconds total.
>
> LDC2 -O/-O2 has the best compilation-execution total, clocking in at 5.4 seconds. Subtracting the link time gets 5.0 seconds.
>
> Its code generation phase (measured by measuring the time between -v's "code" and the link command) takes 2.6 seconds.
>
> In contrast, compilation+execution for V8 JavaScript 2.0 seconds. V8's --trace-opt says it compiles each function once, and compilation (SSA creation, optimization, and code generation) takes a grand total of 0.027 seconds.
>
> LDC's code generation is over 100 times slower. Surely there's opportunities for profiling and optimization here. (dmd's code generation is too bad to count.)

I wonder if anyone in the D community has the expertise to change modify or rewrite DMD's backend to be up to be at most 1.5-2x slower at normal, non-SIMD tasks, up to a poor version of LuaJIT or V8 while retaining the speed.
August 26, 2020
On Thursday, 20 August 2020 at 23:16:40 UTC, Stefan Koch wrote:
> On Thursday, 20 August 2020 at 22:20:19 UTC, Andrei Alexandrescu wrote:
>> On 8/20/20 4:50 PM, Per Nordlöw wrote:
>>> After having evaluated the compilation speed of D compared to other languages at
>>> 
>>>      https://github.com/nordlow/compiler-benchmark
>>> 
>>> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?
>>> 
>>> If so it most likely needs to use a backend other than LLVM.
>>> 
>>> I believe Jai is supposed to do that but it hasn't been released yet.
>>
>> I tried Python a while ago, the build-run cycle for a simple program was about the same. For Perl it was faster.
>
> Neither perl nor python compile their code by default.

Yes, they do. Just not to x86.
August 26, 2020
On Thursday, 20 August 2020 at 20:50:25 UTC, Per Nordlöw wrote:
> After having evaluated the compilation speed of D compared to other languages at
>
>     https://github.com/nordlow/compiler-benchmark
>
> I wonder; is there any language that compiles to native code anywhere nearly as fast or faster than D, except C?

You could add Crystal [1] as well for completeness. It uses LLVM as its backend, so it might not be fast.

BTW, I see that you download DMD from dlang.org. The binaries at dlang.org are compiled with DMD itself. You should compile DMD yourself using LDC, with the appropriate flags. It will give you a boost, perhaps 30%.

[1] https://crystal-lang.org

--
/Jacob Carlborg