Re: Code speed and C++

2010-04-20 Thread Joseph Wakeling
bearophile wrote: Joseph Wakeling: I took a little time last night and wrote up a C++ version that I'll take a look at this, I was away for few days. Thank you very much! No rush or even necessity -- I'm just curious if it sheds any light on D-related issues. :-)

Re: Code speed and C++

2010-04-19 Thread bearophile
Joseph Wakeling: I took a little time last night and wrote up a C++ version that I'll take a look at this, I was away for few days. Bye, bearophile

Re: Code speed and C++

2010-04-17 Thread Joseph Wakeling
bearophile wrote: This is the middle parts (the two loops) of Yzlm.objectReputationUpdate compiled with ldc, this is one of the two main hot spots of the program, the you can compared this asm with the asm of the same part from the C++ version: To find why the C++ code is faster you can

Re: Code speed

2010-04-16 Thread Don
Ary Borenszweig wrote: Don wrote: Ary Borenszweig wrote: Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway,

Re: Code speed (and back to the memory leaks...)

2010-04-16 Thread Joseph Wakeling
bearophile wrote: You are right, sorry. No need to apologise! You helped me significantly improve my code, helped me understand D a lot better and left me feeling generally very positive about developing further in D. I'd call that a result. :-) So I think it's probably just compiler

Re: Code speed

2010-04-16 Thread Ary Borenszweig
bearophile wrote: Ary Borenszweig: My point is, if you are going to pow, you will need std.math, so it'll always be a burden to import it by hand when using it. ^^ Can the automatic import happen only iff a module uses the ^^fp? Bye, bearophile That's what I'm asking for.

Re: Code speed (and back to the memory leaks...)

2010-04-15 Thread Joseph Wakeling
Hi Bearophile, Thanks ever so much for the amount of effort you put into this -- it is extremely kind and generous. :-) I'm not seeing the significant gains that you see with DMD, but for me too LDC doubles the speed. My guess for the difference is that you ran less than the full 100 iterations

Tango2 and Phobos2 [was: Re: Code speed]

2010-04-15 Thread Joseph Wakeling
bearophile wrote: Robert Clipsham Wrote: this way if/when tango is ported to D2 it doesn't have to hack around this to allow it to allow users to use ^^. I hope Tango2 will be designed to be installed beside Phobos2, and not in place of it. I thought that was the aim ... ? At least

Re: Code speed (and back to the memory leaks...)

2010-04-15 Thread Steven Schveighoffer
On Wed, 14 Apr 2010 17:19:53 -0400, Joseph Wakeling joseph.wakel...@webdrake.net wrote: / version(Tango) { import tango.stdc.stdio: printf; } else { import std.stdio: printf; } void main() { double[] x;

Re: Code speed (and back to the memory leaks...)

2010-04-15 Thread bearophile
Joseph Wakeling: My guess for the difference is that you ran less than the full 100 iterations of the main for loop. You are right, sorry. So I think it's probably just compiler difference that's to blame for speed differences This can be true, but such differences are not magic, they can

Re: Code speed

2010-04-15 Thread Ary Borenszweig
Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a bug. It's intentional. x ^^

Re: Code speed (and back to the memory leaks...)

2010-04-15 Thread bearophile
This is the middle parts (the two loops) of Yzlm.objectReputationUpdate compiled with ldc, this is one of the two main hot spots of the program, the you can compared this asm with the asm of the same part from the C++ version: To find why the C++ code is faster you can show me the equivalent

Re: Code speed

2010-04-15 Thread Don
Ary Borenszweig wrote: Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a

Re: Code speed

2010-04-15 Thread Ary Borenszweig
Don wrote: Ary Borenszweig wrote: Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug).

Re: Code speed

2010-04-15 Thread bearophile
Ary Borenszweig: My point is, if you are going to pow, you will need std.math, so it'll always be a burden to import it by hand when using it. ^^ Can the automatic import happen only iff a module uses the ^^fp? Bye, bearophile

Re: Code speed

2010-04-14 Thread Don
bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a bug. It's intentional. x ^^ y will probably always require import std.math,

Re: Code speed

2010-04-14 Thread Lars T. Kyllingstad
Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a bug. It's intentional. x ^^ y will probably always require import

Re: Code speed

2010-04-14 Thread Don
Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a bug. It's intentional. x ^^ y will

Re: Code speed

2010-04-14 Thread bearophile
Don: That's not a bug. It's intentional. x ^^ y will probably always require import std.math, if y is a floating point number. What's the rationale behind this decision? I have filed it as a bug many days ago, because I think it's a wrong intention:

^^ implementation [Was: Re: Code speed]

2010-04-14 Thread bearophile
Don: Thank you for your answer and comments. Because pow() for floating point, when implemented properly, is a HUGE function, that ends up dragging almost all of std.math into the executable. And I think it's deceptive to do that silently. To make it completely built-in, basically all of

Re: ^^ implementation [Was: Re: Code speed]

2010-04-14 Thread Don
bearophile wrote: Don: Thank you for your answer and comments. Because pow() for floating point, when implemented properly, is a HUGE function, that ends up dragging almost all of std.math into the executable. And I think it's deceptive to do that silently. To make it completely built-in,

Re: Code speed

2010-04-14 Thread Lars T. Kyllingstad
Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a bug. It's intentional. x ^^

Re: Code speed

2010-04-14 Thread Lars T. Kyllingstad
Lars T. Kyllingstad wrote: Don wrote: Lars T. Kyllingstad wrote: Don wrote: bearophile wrote: So far I've just given a light reading of the code. Notes: - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but you have to import std.math anyway, because of a bug). That's not a

Re: Code speed

2010-04-14 Thread bearophile
- the two nested loops in the main are more efficient as ref double, this is something dmd will need to fix; A test shows that on ldc the two nested loops are a little faster without the ref. I'd like the compiler to use a const ref with the foreach iterates on array items bigger than a word.

Re: Code speed

2010-04-14 Thread Robert Clipsham
On 14/04/10 20:54, Don wrote: I have a vague recollection that correctly-rounded pow() will require bigint (can't quite remember, though). I'm also concerned about build tools -- I don't want them to have to know about the dependency. As a bare minimum, the error message will need to improve

Code speed [was: Re: Memory leak with dynamic array]

2010-04-13 Thread Joseph Wakeling
Don wrote: The D code compiles directly to a memset and memcpy, which are intrinsics. There's no way C++ could beat it. OK. I'm just bemused about why -- having solved the memory leak -- my D code is running significantly slower than equivalent C++ code. For now I'm just playing with D by

Re: Code speed

2010-04-13 Thread bearophile
This is a single module, and on my PC is more than two times faster than the original code. Now I think there are no naive ways left to speed it up. Compile it with: dmd -O -release -inline The low performance was caused by: - virtual methods that don't need to be virtual; - ^^0.5 and pow(x,2)

Re: Code speed

2010-04-13 Thread bearophile
This compiles for D1. With LDC it runs about two times faster still, about 4.5-5 times faster than the original version. We can compare this to the C++ version of yours. ldc -O5 -release -inline -enable-unsafe-fp-math -unroll-allow-partial test.d I have also tried the faster rnd generator