Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 16:15, Johan wrote: > On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: >> >> I am using compilers installed by Manjaro Linux's package system: >> >> ldc: LDC - the LLVM D compiler (1.28.0): >> based on DMD v2.098.0 and LLVM 13.0.0 >> >> gdc: dc (GCC) 11.1.0 >> >> dmd:

Re: gdc or ldc for faster programs?

2022-01-25 Thread Johan via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: I am using compilers installed by Manjaro Linux's package system: ldc: LDC - the LLVM D compiler (1.28.0): based on DMD v2.098.0 and LLVM 13.0.0 gdc: dc (GCC) 11.1.0 dmd: DMD64 D Compiler v2.098.1 What phobos version is

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 11:01:57PM +, forkit via Digitalmars-d-learn wrote: > On Tuesday, 25 January 2022 at 20:01:18 UTC, Johan wrote: > > > > Tough to say. Of course DMD is not a serious contender, but I > > believe the difference between GDC and LDC is very small and really > > in the

Re: gdc or ldc for faster programs?

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 20:01:18 UTC, Johan wrote: Tough to say. Of course DMD is not a serious contender, but I believe the difference between GDC and LDC is very small and really in the details, i.e. you'll have to look at assembly to find out the delta. Have you tried

Re: passing a variadic parameter to randomSample

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 10:48:26PM +, forkit via Digitalmars-d-learn wrote: [...] > ... but my main focus here, was learning about variadic template > functions. D has several flavors of variadics: 1) C-style variadics (not type-safe, not recommended): int func(int firstArgc, ...)

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 10:41:35PM +, Elronnd via Digitalmars-d-learn wrote: > On Tuesday, 25 January 2022 at 22:33:37 UTC, H. S. Teoh wrote: > > interesting because idivl is known to be one of the slower > > instructions, but gdc nevertheless considered it not worthwhile to > > replace it,

Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 14:33, H. S. Teoh wrote: > This is very interesting Fascinating code generation and investigation! :) Ali

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:35:29 UTC, forkit wrote: I should point out (to anyone looking at that code I posted), that it's easier, and makes more sense, to just write: writeln( ["typeA", "typeB", "typeC"].choice ); ... but my main focus here, was learning about variadic template

Re: gdc or ldc for faster programs?

2022-01-25 Thread Elronnd via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:33:37 UTC, H. S. Teoh wrote: interesting because idivl is known to be one of the slower instructions, but gdc nevertheless considered it not worthwhile to replace it, whereas ldc seems obsessed about avoid idivl at all costs. Interesting indeed. Two

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote: thanks. makes it even shorter and simpler :-) // -- module test; @safe: import std; auto RandomChoice(R...)(R r) { auto rnd = MinstdRand0(unpredictableSeed); return only(r).choice(rnd); } void main() { writeln(

Re: passing a variadic parameter to randomSample

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 02:07:43PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > auto RandomChoice(R)(R[] r...) > > > { > > auto rnd = MinstdRand0(unpredictableSeed); > > return only(r).randomSample(1, rnd).front; > > Which makes that simpler as well because being a slice,

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 01:30:59PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > I posted the program to have more eyes on the assembly. ;) [...] I tested the code locally, and observed, just like Ali did, that the LDC version is unambiguously slower than the gdc version by a small

Re: passing a variadic parameter to randomSample

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 13:55, forkit wrote: > auto RandomChoice(R...)(R r) Watch out though: The compiler will compile a different function per set of values. For example, there will be separate RandomChoice instances for ("hello") vs. ("world"). D has a simple variadic parameter syntax as well: auto

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 11:50:08 UTC, vit wrote: thanks. problem solved (providing all parameters are of the same type). // --- module test; import std; auto RandomChoice(R...)(R r) { auto rnd = MinstdRand0(unpredictableSeed); return only(r).randomSample(1, rnd).front; }

Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 12:42, H. S. Teoh wrote: >> For a test run for 2 million numbers: >> >> ldc: ~0.95 seconds >> gdc: ~0.79 seconds >> dmd: ~1.77 seconds > > For measurements under 1 second, I'm skeptical of the accuracy, because > there could be all kinds of background noise, CPU interrupts and stuff >

Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 12:59, Daniel N wrote: Maybe you can try --ffast-math on ldc. Did not make a difference. Ali

Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 12:01, Johan wrote: Have you tried `--enable-cross-module-inlining` with LDC? Tried now. Makes no difference that I can sense, likely because there is only one module anyway. :) (But I guess it works over Phobos modules too.) Ali

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 08:04:04PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: > > ldc: ~0.95 seconds > > gdc: ~0.79 seconds > > dmd: ~1.77 seconds > > Not surprising at all: gdc is excellent and underrated in the >

Re: gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/22 11:52, Ali Çehreli wrote: > a program I wrote about spelling-out parts of a number Here is the program as a single module: module spellout.spellout; // This program was written as a code kata to spell out // certain parts of integers as in "1 million 2 thousand // 42". Note that

Re: gdc or ldc for faster programs?

2022-01-25 Thread Daniel N via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 20:04:04 UTC, Adam D Ruppe wrote: On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: ldc: ~0.95 seconds gdc: ~0.79 seconds dmd: ~1.77 seconds Maybe you can try --ffast-math on ldc.

Re: gdc or ldc for faster programs?

2022-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 25, 2022 at 11:52:17AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > Sorry for being vague and not giving the code here but a program I > wrote about spelling-out parts of a number (in Turkish) as in "1 > milyon 42" runs much faster with gdc. > > The program integer-divides the

Re: gdc or ldc for faster programs?

2022-01-25 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: ldc: ~0.95 seconds gdc: ~0.79 seconds dmd: ~1.77 seconds Not surprising at all: gdc is excellent and underrated in the community.

Re: gdc or ldc for faster programs?

2022-01-25 Thread Johan via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 19:52:17 UTC, Ali Çehreli wrote: I am not experienced with dub but I used --build=release-nobounds and verified that -O3 is used for both compilers. (I also tried building manually with GNU 'make' with e.g. -O5 and the results were similar.) `-O5` does not do

gdc or ldc for faster programs?

2022-01-25 Thread Ali Çehreli via Digitalmars-d-learn
Sorry for being vague and not giving the code here but a program I wrote about spelling-out parts of a number (in Turkish) as in "1 milyon 42" runs much faster with gdc. The program integer-divides the number in a loop to find quotients and adds the word next to it. One obvious optimization

Re: How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread JG via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 12:27:16 UTC, Dennis wrote: On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote: Any ideas how one can achieve what is written in the subject line? ```D void f(T...)(auto ref T args, string file = __FILE__, int line = __LINE__) { writeln(file, ":", line,

Re: passing a variadic parameter to randomSample

2022-01-25 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote: so I'm trying to write (or rather learn how to write) a 'variadic template function', that returns just one of its variadic parameter, randomly chosen. But can't get my head around the problem here :-( .. Error: template

Re: How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 12:27:16 UTC, Dennis wrote: On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote: Any ideas how one can achieve what is written in the subject line? ```D void f(T...)(auto ref T args, string file = __FILE__, int line = __LINE__) { writeln(file, ":", line,

Re: passing a variadic parameter to randomSample

2022-01-25 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote: so I'm trying to write (or rather learn how to write) a 'variadic template function', that returns just one of its variadic parameter, randomly chosen. But can't get my head around the problem here :-( .. Error: template

Re: How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread Dennis via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote: Any ideas how one can achieve what is written in the subject line? ```D void f(T...)(auto ref T args, string file = __FILE__, int line = __LINE__) { writeln(file, ":", line, ": ", args); } ```

How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread JG via Digitalmars-d-learn
Any ideas how one can achieve what is written in the subject line? f below does achieve this but I one would expect that it produces significant template bloat. g achieves the aim but isn't very elegant. import std; void f(string file=__FILE__,size_t line=__LINE__,R...)(R r) {

Re: passing a variadic parameter to randomSample

2022-01-25 Thread vit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 09:48:25 UTC, forkit wrote: so I'm trying to write (or rather learn how to write) a 'variadic template function', that returns just one of its variadic parameter, randomly chosen. But can't get my head around the problem here :-( .. Error: template

passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
so I'm trying to write (or rather learn how to write) a 'variadic template function', that returns just one of its variadic parameter, randomly chosen. But can't get my head around the problem here :-( .. Error: template `std.random.randomSample` cannot deduce function from argument types `