Profiling calls to small functions

2017-01-21 Thread albert-j via Digitalmars-d-learn
Let's say I want to create an array of random numbers and do some operations on them: void main() { import std.random; //Generate array of random numbers int arrSize = 1; double[] arr = new double[](arrSize); foreach (i; 0..arrSize) arr[i] = uniform01();

Re: Profiling calls to small functions

2017-01-21 Thread pineapple via Digitalmars-d-learn
On Saturday, 21 January 2017 at 12:33:57 UTC, albert-j wrote: Now I dmd -profile it and look at the performance of funcA with d-profile-viewer. Inside funcA, only 20% of time is spend in funcB, but the rest 80% is self-time of funcA. How is it possible, when funcB has three times the

Re: @nogc and opengl errors check

2017-01-21 Thread Xavier Bigand via Digitalmars-d-learn
Le 21/01/2017 à 13:24, Jerry a écrit : On Friday, 20 January 2017 at 22:47:17 UTC, Xavier Bigand wrote: Hi, I am writing some code with opengl commands that I want to check in debug, so I am using the function checkgl (from glamour lib). The issue is that checkgl throw exception and can't be

Re: cannot alias array ;/

2017-01-21 Thread Dukc via Digitalmars-d-learn
On Thursday, 19 January 2017 at 08:06:04 UTC, ketmar wrote: alias is not a macro, it is alias to *symbol*. only symbol, not any arbitrary expression. In fact, it can nowadays be. You just have to mark it so, with a lambda: void main() { import std.stdio; auto myArray = [2, 3, 5, 6];

Re: @nogc and opengl errors check

2017-01-21 Thread Jerry via Digitalmars-d-learn
On Friday, 20 January 2017 at 22:47:17 UTC, Xavier Bigand wrote: Hi, I am writing some code with opengl commands that I want to check in debug, so I am using the function checkgl (from glamour lib). The issue is that checkgl throw exception and can't be @nogc, I had try to use

Re: Profiling calls to small functions

2017-01-21 Thread albert-j via Digitalmars-d-learn
I'm not sure if it's what happening in this case but, in code as simple as this, function calls can sometimes be the bottleneck. You should see how compiling with/without -O affects performance, and adding `pragma(inline)` to funcB. When compiled with -inline, the profiler does not report the

Compile to C?

2017-01-21 Thread Nestor via Digitalmars-d-learn
Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability.

Re: iterating through members of bitfields

2017-01-21 Thread Nestor via Digitalmars-d-learn
Thank you both!

Re: Compile to C?

2017-01-21 Thread Joakim via Digitalmars-d-learn
On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability. The wiki says there was a dmd fork that attempted this 5 years ago, don't know how far he got:

Re: Compile to C?

2017-01-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: That would be cool for greater portability. The hard part in porting to a new platform is rarely the code generation - gdc and ldc have diverse backends already (indeed, they tend to work for D as well as C there). But you still

Re: Compile to C?

2017-01-21 Thread Jack Stouffer via Digitalmars-d-learn
On Saturday, 21 January 2017 at 18:38:22 UTC, Nestor wrote: Hi friends, Is there a way to "compile" d code to C, similar to what nim does? That would be cool for greater portability. No, and this is actually a terrible idea. See

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
Simplified: import std.stdio; struct Widget { private int[] array; this(uint length) { array = new int[length]; writefln("ctor called : %s", array.ptr); } this(this) { writef( "this(this) called: %s", array.ptr ); array = array.dup;

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 03:19 PM, Ali Çehreli wrote: this(this) { TIL! Change the signature and it works without copies: this(const(this)) { // ... } How did I miss this for so long? Ali

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what is it? Ali

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 01/21/2017 07:22 PM, Basile B. wrote: On Sunday, 22 January 2017 at 00:31:38 UTC, Ali Çehreli wrote: On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Basile B. via Digitalmars-d-learn
On Sunday, 22 January 2017 at 03:42:21 UTC, Ali Çehreli wrote: On 01/21/2017 07:22 PM, Basile B. wrote: [...] Wow! Thanks. I know about 'alias this' but this (pun!) is new to me. TIL indeed and WAT (four exclamation marks is right in this case. :o) ) import std.stdio; struct S {

Re: Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Basile B. via Digitalmars-d-learn
On Sunday, 22 January 2017 at 00:31:38 UTC, Ali Çehreli wrote: On 01/21/2017 03:36 PM, Ali Çehreli wrote: > Change the signature and it works without copies: > > this(const(this)) { > // ... > } Ugh... :( It's not a post-blit. Then what is it? Ali This is a __ctor that takes

Calls `this(this)` extra with delegate stuff in the code

2017-01-21 Thread Joel via Digitalmars-d-learn
Compile this and see, (it's crazy!): import std.stdio; struct Widget { private int[] array; this(uint length) { array = new int[length]; } this(this) { writeln( "this(this) called" ); array = array.dup; }