Re: Detecting performance pitfall in array access

2020-05-18 Thread Adnan via Digitalmars-d-learn
On Sunday, 17 May 2020 at 09:41:55 UTC, Johan wrote: On Sunday, 17 May 2020 at 03:30:57 UTC, Adnan wrote: Hello, I am trying to examine what causes my similar D solution to lag behind performance. In the link, they don't have ldc or gdc but according to my machine, the dmd generated code

Re: Detecting performance pitfall in array access

2020-05-18 Thread Adnan via Digitalmars-d-learn
On Sunday, 17 May 2020 at 11:39:30 UTC, kinke wrote: As a side note, using jagged arrays for multiple dimensions should probably be avoided whenever you can. By jagged array, do you mean vector of vectors? What would be an alternative?

Re: Detecting performance pitfall in array access

2020-05-17 Thread kinke via Digitalmars-d-learn
On Sunday, 17 May 2020 at 11:39:30 UTC, kinke wrote: DMD v2.091: * dmd -m64 -O -release -boundscheck=off -run ..\speed.d aa bbc: ~11 μs I forgot `-inline` for DMD; that reduces the speed, yielding ~16 μs.

Re: Detecting performance pitfall in array access

2020-05-17 Thread kinke via Digitalmars-d-learn
On Sunday, 17 May 2020 at 03:30:57 UTC, Adnan wrote: In my machine, if you feed "aa" and "bbc" to the function, ldc generated code takes around 400 microseconds. I don't have an access to gdc in my machine. https://imgshare.io/image/NN8Xmp Full code: D : https://run.dlang.io/is/vLj7BC

Re: Detecting performance pitfall in array access

2020-05-17 Thread Johan via Digitalmars-d-learn
On Sunday, 17 May 2020 at 03:30:57 UTC, Adnan wrote: Hello, I am trying to examine what causes my similar D solution to lag behind performance. In the link, they don't have ldc or gdc but according to my machine, the dmd generated code isn't really far behind ldc generated code.

Detecting performance pitfall in array access

2020-05-16 Thread Adnan via Digitalmars-d-learn
Hello, I am trying to examine what causes my similar D solution to lag behind performance. In the link, they don't have ldc or gdc but according to my machine, the dmd generated code isn't really far behind ldc generated code. So here is the actual code: ulong levenshteinEditDistance(T)(in

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 09:30:16AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 3/13/20 5:24 AM, H. S. Teoh wrote: > > Note that `arg ~ arg` may allocate, but it also may not if the > > current buffer for `arg` is big enough to accomodate both. > > That always allocates. Only

Re: Associative Array potential performance pitfall?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 5:24 AM, H. S. Teoh wrote: Note that `arg ~ arg` may allocate, but it also may not if the current buffer for `arg` is big enough to accomodate both. That always allocates. Only appending may avoid allocation: arg ~= arg; But, I would instead use ranges if possible to avoid all

Re: Associative Array potential performance pitfall?

2020-03-13 Thread dayllenger via Digitalmars-d-learn
On Friday, 13 March 2020 at 03:40:11 UTC, Adnan wrote: Where am I losing performance? It is nonsensical to say without measuring. Humans are notoriously bad at predicting performance issues. Wrap all your hardworking code into a loop with like 100 iterations, compile and run: $ perf

Re: Associative Array potential performance pitfall?

2020-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 13, 2020 at 03:40:11AM +, Adnan via Digitalmars-d-learn wrote: > In my machine the following D code compiled with release flag and LDC > performs over 230ms while the similar Go code performs under 120ms. > > string smallestRepr(const string arg) { > import std.format :

Associative Array potential performance pitfall?

2020-03-12 Thread Adnan via Digitalmars-d-learn
In my machine the following D code compiled with release flag and LDC performs over 230ms while the similar Go code performs under 120ms. string smallestRepr(const string arg) { import std.format : format; const repeated = format!"%s%s"(arg, arg); string result;

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread dom via Digitalmars-d-learn
On Monday, 5 September 2016 at 12:32:49 UTC, Lodovico Giaretta wrote: On Monday, 5 September 2016 at 12:15:35 UTC, dom wrote: [...] You misunderstood the error message and the lambda syntax (it also happened to me the first time). The grammar says that you can use one of these syntaxes:

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread dom via Digitalmars-d-learn
On Monday, 5 September 2016 at 12:30:37 UTC, Daniel Kozak wrote: Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): ... but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow.

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Lodovico Giaretta via Digitalmars-d-learn
On Monday, 5 September 2016 at 12:15:35 UTC, dom wrote: [...] You misunderstood the error message and the lambda syntax (it also happened to me the first time). The grammar says that you can use one of these syntaxes: 1) `(arguments) {block of code}` 2) `(arguments) => expression`, which

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 14:30 Daniel Kozak napsal(a): Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): ... but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow. Yes, R

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
Dne 5.9.2016 v 14:15 dom via Digitalmars-d-learn napsal(a): ... but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow. Yes, RTFM :)

Re: delegates, lambdas and functions pitfall

2016-09-05 Thread Daniel Kozak via Digitalmars-d-learn
new AsyncHttpGet("www.dprogramming.com", 80, "/index.php", (string content) { dummy = 1; // this is of type delegate }); but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow.

delegates, lambdas and functions pitfall

2016-09-05 Thread dom via Digitalmars-d-learn
index.php", (string content) { dummy = 1; // this is of type delegate }); but what is the difference between a lambda (=>) and a functions/delegates? i think this is a major pitfall for newcomers, and should be adressed somehow.

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-07 Thread David Nadlinger
On Saturday, 7 July 2012 at 03:02:07 UTC, akaz wrote: On Friday, 6 July 2012 at 21:10:56 UTC, Simon wrote: On 06/07/2012 16:39, Alex Rønne Petersen wrote: Never mind what D says, even in C/C++ just doing the p += 10 is invalid. Creating a pointer that points at invalid memory is just as

Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread akaz
Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ... collector may run here ... p-=10; *p = 10;// can we be sure that the int is still

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Denis Shelomovskij
06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ... collector may run here ... p-=10; *p = 10;// can we be sure that

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread akaz
If you are interested in D read this first: http://dlang.org/garbage.html You can find there e.g.: Do not add or subtract an offset to a pointer such that the result points outside of the bounds of the garbage collected object originally allocated. So `p+=10;` is already undefined behavior.

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Alex Rønne Petersen
On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ... collector may run here ... p-=10; *p = 10; // can we be

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Timon Gehr
On 07/06/2012 05:39 PM, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ...

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread akaz
On Friday, 6 July 2012 at 15:39:40 UTC, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: I'll just add: Handling this case is basically impossible to do sanely. You can't really know

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Alex Rønne Petersen
On 06-07-2012 22:07, akaz wrote: On Friday, 6 July 2012 at 15:39:40 UTC, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: I'll just add: Handling this case is basically impossible to

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Simon
On 06/07/2012 16:39, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Hi, Reading about the C++11, I stumbled upon this: http://www2.research.att.com/~bs/C++0xFAQ.html#gc-abi Specifically (quote): int* p = new int; p+=10; // ...

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread akaz
On Friday, 6 July 2012 at 21:10:56 UTC, Simon wrote: On 06/07/2012 16:39, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Never mind what D says, even in C/C++ just doing the p += 10 is invalid. Creating a pointer that points at

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread akaz
Won't some functions doing just what addRange() and removeRange() do solve that kind of problem (if necessary)? That means, forbidding the GC to scan some memory area for some time? Like their C++11 counterparts: void declare_reachable(void* p); // the region of memory starting at p

Re: Garbage Collection Pitfall in C++ but not in D?

2012-07-06 Thread Alex Rønne Petersen
On 07-07-2012 05:02, akaz wrote: On Friday, 6 July 2012 at 21:10:56 UTC, Simon wrote: On 06/07/2012 16:39, Alex Rønne Petersen wrote: On 06-07-2012 16:07, Denis Shelomovskij wrote: 06.07.2012 17:43, akaz пишет: Never mind what D says, even in C/C++ just doing the p += 10 is invalid.

Pitfall

2012-02-06 Thread Manfred Nowak
Today I got the nice message Error: undefined identifier missing from DMD2.057/win and was baffled for several minutes until I recognized the meaning. -manfred

Re: Pitfall

2012-02-06 Thread Timon Gehr
On 02/06/2012 08:20 PM, Manfred Nowak wrote: Today I got the nice message Error: undefined identifier missing from DMD2.057/win and was baffled for several minutes until I recognized the meaning. -manfred Single quotes would indeed be helpful.