Re: Need for speed

2021-04-02 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 9:01 PM, H. S. Teoh wrote: > 6) (Not described in the thread, but applied later) Reduce GC load even > further by reusing an array that was being allocated per iteration in > an inner loop before. For those who prefer a video description with some accent :) here is how to appl

Re: Need for speed

2021-04-02 Thread Nestor via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:38:39 UTC, H. S. Teoh wrote: On Thu, Apr 01, 2021 at 04:52:17PM +, Nestor via Digitalmars-d-learn wrote: [...] [...] Since the length of the array is already known beforehand, you could get significant speedups by preallocating the array: [...] Firs

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 02:36:21AM +, Jon Degenhardt via Digitalmars-d-learn wrote: > On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote: [...] > > It's interesting that whenever a question about D's performance pops > > up in the forums, people tend to reach for optimization flags.

Re: Need for speed

2021-04-01 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote: On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via Digitalmars-d-learn wrote: [...] Since this is a "Learn" part of the Foruam, be careful with "-boundscheck=off". I mean for this little snippet is OK, but for a other projects th

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 09:16:09PM +, Imperatorn via Digitalmars-d-learn wrote: > On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote: [...] > > Thanks for the very interesting information; so it looks like most > > of the time spent is actually in copying array elements than > > anyth

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote: On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] [...] [...] Right, but in a typical program it's unpredictable whether there will be unused pages after the array. [...] [...] Thanks

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/1/21 12:55 PM, H. S. Teoh wrote: > > > - Constructing large arrays by appending 1 element at a time with > > `~`. Obviously, this requires many array reallocations and the > > associated copying > > And

Re: Need for speed

2021-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 12:55 PM, H. S. Teoh wrote: > - Constructing large arrays by appending 1 element at a time with `~`. >Obviously, this requires many array reallocations and the associated >copying And that may not be a contributing factor. :) The following program sees just 15 allocations and

Re: Need for speed

2021-04-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.04.21 21:53, Steven Schveighoffer wrote: Maybe, but I wasn't responding to that, just your statement not to recommend -boundscheck=off. In any case, it wouldn't hurt, right? Right.

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via Digitalmars-d-learn wrote: [...] > Since this is a "Learn" part of the Foruam, be careful with > "-boundscheck=off". > > I mean for this little snippet is OK, but for a other projects this my > be wrong, and as it says here: > https://dlang.org

Re: Need for speed

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 3:44 PM, ag0aep6g wrote: On 01.04.21 21:36, Steven Schveighoffer wrote: On 4/1/21 3:27 PM, ag0aep6g wrote: On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` [...] Yes, but you can recommend

Re: Need for speed

2021-04-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.04.21 21:36, Steven Schveighoffer wrote: On 4/1/21 3:27 PM, ag0aep6g wrote: On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` [...] Yes, but you can recommend `-boundscheck=safeonly`, which leave

Re: Need for speed

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 3:27 PM, ag0aep6g wrote: On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` Please don't recommend `-boundscheck=off` to newbies. It's not just an optimization. It breaks @safe. If you want t

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 04:52:17PM +, Nestor via Digitalmars-d-learn wrote: [...] > ``` > import std.stdio; > import std.random; > import std.datetime.stopwatch : benchmark, StopWatch, AutoStart; > import std.algorithm; > > void main() > { > auto sw = StopWatch(AutoStart.no); > sw.star

Re: Need for speed

2021-04-01 Thread matheus via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:00:08 UTC, Berni44 wrote: Try using ldc2 instead of dmd: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` should produce much better results. Since this is a "Learn" part of the Foruam, be careful wit

Re: Need for speed

2021-04-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.04.21 21:00, Berni44 wrote: ``` ldc2 -O3 -release -boundscheck=off -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d ``` Please don't recommend `-boundscheck=off` to newbies. It's not just an optimization. It breaks @safe. If you want to do welding without eye protection

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 19:00:08 UTC, Berni44 wrote: On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values betw

Re: Need for speed

2021-04-01 Thread Berni44 via Digitalmars-d-learn
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values between 350-380 ms, and 81ms in Python. Try using ldc2 inste

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote: On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote: On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values

Re: Need for speed

2021-04-01 Thread Chris Piker via Digitalmars-d-learn
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values between 350-380 ms, and 81ms in Python. Nice test. I'm new

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I am a python programmer and I am enjoying Dlang and learning some programming insights on the way, thank everyone. I have no formal education and also program JS and PHP. Watching a video where a guy programs some simple code in Python

Re: Need for speed

2021-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 10:15 AM, ag0aep6g wrote: > Move `auto rnd = ...;` out of the loop, and you will get better times. Doing that reduces the time about 15 fold. Using Appender reduces it further a tiny bit: import std.array; // ... Appender!(int[]) mylist; // ... mylist.data.sort(); Ali

Re: Need for speed

2021-04-01 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I was hoping to beat my dear Python and get similar results to Go, but that is not the case neither using rdmd nor running the executable generated by dmd. I am getting values between 350-380 ms, and 81ms in Python. [...] ``` for (i

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I am a python programmer and I am enjoying Dlang and learning some programming insights on the way, thank everyone. [...] Could you also post the python code for comparison?

Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 1 April 2021 at 17:16:06 UTC, Imperatorn wrote: On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote: I am a python programmer and I am enjoying Dlang and learning some programming insights on the way, thank everyone. [...] Could you also post the python code for comparison?

Need for speed

2021-04-01 Thread Nestor via Digitalmars-d-learn
I am a python programmer and I am enjoying Dlang and learning some programming insights on the way, thank everyone. I have no formal education and also program JS and PHP. Watching a video where a guy programs some simple code in Python and the same code in Go and compares speed I thought that