Jump to page: 1 24  
Page
Thread overview
math.log() benchmark of first 1 billion int using std.parallelism
Dec 22, 2014
Iov Gherman
Dec 22, 2014
bachmeier
Dec 22, 2014
Daniel Kozak
Dec 22, 2014
Daniel Kozak
Dec 22, 2014
aldanor
Dec 22, 2014
aldanor
optimization / benchmark tips a good topic for wiki ?
Dec 22, 2014
Laeeth Isharc
Dec 22, 2014
Russel Winder
Dec 22, 2014
Iov Gherman
Dec 22, 2014
bachmeier
Dec 22, 2014
Iov Gherman
Dec 22, 2014
Iov Gherman
Dec 22, 2014
John Colvin
Dec 22, 2014
Iov Gherman
Dec 22, 2014
John Colvin
Dec 23, 2014
Daniel Kozak
Dec 23, 2014
John Colvin
Dec 23, 2014
Iov Gherman
Dec 23, 2014
John Colvin
Dec 23, 2014
Iov Gherman
Dec 23, 2014
Daniel Kozak
Dec 23, 2014
Iov Gherman
Dec 23, 2014
Daniel Kozak
Dec 23, 2014
Iov Gherman
Dec 23, 2014
Iov Gherman
Dec 23, 2014
Daniel Kozak
Dec 23, 2014
Casper Færgemand
Dec 22, 2014
aldanor
Dec 22, 2014
Iov Gherman
Dec 22, 2014
Marc Schütz
Dec 23, 2014
John Colvin
December 22, 2014
Hi everybody,

I am a java developer and used C/C++ only for some home projects so I never mastered native programming.

I am currently learning D and I find it fascinating. I was reading the documentation about std.parallelism and I wanted to experiment a bit with the example "Find the logarithm of every number from 1 to 10_000_000 in parallel".

So, first, I changed the limit to 1 billion and ran it. I was blown away by the performance, the program ran in: 4 secs, 670 ms and I used a workUnitSize of 200. I have an i7 4th generation processor with 8 cores.

Then I was curios to try the same test in Java just to see how much slower will that be (at least that was what I expected). I used Java's ExecutorService with a pool of 8 cores and created 5_000_000 tasks, each task was calculating log() for 200 numbers. The whole program ran in 3 secs, 315 ms.

Now, can anyone explain why this program ran faster in Java? I ran both programs multiple times and the results were always close to this execution times.

Can the implementation of log() function be the reason for a slower execution time in D?

I then decided to ran the same program in a single thread, a simple foreach/for loop. I tried it in C and Go also. This are the results:
- D: 24 secs, 32 ms.
- Java: 20 secs, 881 ms.
- C: 21 secs
- Go: 37 secs

I run Arch Linux on my PC. I compiled D programs using dmd-2.066 and used no compile arguments (dmd prog.d).
I used Oracle's Java 8 (tried 7 and 6, seems like with Java 6 the performance is a bit better then 7 and 8).
To compile the C program I used: gcc 4.9.2
For Go program I used go 1.4

I really really like the built in support in D for parallel processing and how easy is to schedule tasks taking advantage of workUnitSize.

Thanks,
Iov
December 22, 2014
On Monday, 22 December 2014 at 10:12:52 UTC, Iov Gherman wrote:
> Now, can anyone explain why this program ran faster in Java? I ran both programs multiple times and the results were always close to this execution times.
>
> Can the implementation of log() function be the reason for a slower execution time in D?
>
> I then decided to ran the same program in a single thread, a simple foreach/for loop. I tried it in C and Go also. This are the results:
> - D: 24 secs, 32 ms.
> - Java: 20 secs, 881 ms.
> - C: 21 secs
> - Go: 37 secs
>
> I run Arch Linux on my PC. I compiled D programs using dmd-2.066 and used no compile arguments (dmd prog.d).
> I used Oracle's Java 8 (tried 7 and 6, seems like with Java 6 the performance is a bit better then 7 and 8).
> To compile the C program I used: gcc 4.9.2
> For Go program I used go 1.4
>
> I really really like the built in support in D for parallel processing and how easy is to schedule tasks taking advantage of workUnitSize.
>
> Thanks,
> Iov

DMD is generally going to produce the slowest code. LDC and GDC will normally do better.
December 22, 2014
> I run Arch Linux on my PC. I compiled D programs using dmd-2.066 and used no compile arguments (dmd prog.d)

You should try use some arguments -O -release -inline -noboundscheck and maybe try use gdc or ldc should help with performance

can you post your code in all languages somewhere? I like to try it on my machine :)

December 22, 2014
On Monday, 22 December 2014 at 10:35:52 UTC, Daniel Kozak via Digitalmars-d-learn wrote:
>
>> I run Arch Linux on my PC. I compiled D programs using dmd-2.066 and used no compile arguments (dmd prog.d)
>
> You should try use some arguments -O -release -inline -noboundscheck
> and maybe try use gdc or ldc should help with performance
>
> can you post your code in all languages somewhere? I like to try it on
> my machine :)

Btw. try use C log function, maybe it would be faster:

import core.stdc.math;
December 22, 2014
On Mon, 2014-12-22 at 10:12 +0000, Iov Gherman via Digitalmars-d-learn wrote:
> […]
> - D: 24 secs, 32 ms.
> - Java: 20 secs, 881 ms.
> - C: 21 secs
> - Go: 37 secs
> 
Without the source codes and the commands used to create and run, it is impossible to offer constructive criticism of the results. However a priori the above does not surprise me. I'll wager ldc2 or gdc will beat dmd for CPU-bound code, so as others have said for benchmarking use ldc2 or gdc with all optimization on (-O3). If you used gc for Go then switch to gccgo (again with -O3) and see a huge performance improvement on CPU-bound code.

Java beating C and C++ is fairly normal these days due to the tricks you can play with JIT over AOT optimization. Once Java has proper support for GPGPU, it will be hard for native code languages to get any new converts from JVM.

Put the source up and I and others will try things out.
-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

December 22, 2014
On Monday, 22 December 2014 at 10:40:45 UTC, Daniel Kozak wrote:
> On Monday, 22 December 2014 at 10:35:52 UTC, Daniel Kozak via Digitalmars-d-learn wrote:
>>
>>> I run Arch Linux on my PC. I compiled D programs using dmd-2.066 and used no compile arguments (dmd prog.d)
>>
>> You should try use some arguments -O -release -inline -noboundscheck
>> and maybe try use gdc or ldc should help with performance
>>
>> can you post your code in all languages somewhere? I like to try it on
>> my machine :)
>
> Btw. try use C log function, maybe it would be faster:
>
> import core.stdc.math;

Just tried it out myself (E5 Xeon / Linux):

D version: 19.64 sec (avg 3 runs)

    import core.stdc.math;

    void main() {
        double s = 0;
        foreach (i; 1 .. 1_000_000_000)
            s += log(i);
    }

    // build flags: -O -release

C version: 19.80 sec (avg 3 runs)

    #include <math.h>

    int main() {
        double s = 0;
        long i;
        for (i = 1; i < 1000000000; i++)
            s += log(i);
        return 0;
    }

    // build flags: -O3 -lm
December 22, 2014
On Monday, 22 December 2014 at 11:11:07 UTC, aldanor wrote:
>
> Just tried it out myself (E5 Xeon / Linux):
>
> D version: 19.64 sec (avg 3 runs)
>
>     import core.stdc.math;
>
>     void main() {
>         double s = 0;
>         foreach (i; 1 .. 1_000_000_000)
>             s += log(i);
>     }
>
>     // build flags: -O -release
>
> C version: 19.80 sec (avg 3 runs)
>
>     #include <math.h>
>
>     int main() {
>         double s = 0;
>         long i;
>         for (i = 1; i < 1000000000; i++)
>             s += log(i);
>         return 0;
>     }
>
>     // build flags: -O3 -lm

Replacing "import core.stdc.math" with "import std.math" in the D example increases the avg runtime from 19.64 to 23.87 seconds (~20% slower) which is consistent with OP's statement.
December 22, 2014
> Replacing "import core.stdc.math" with "import std.math" in the D example increases the avg runtime from 19.64 to 23.87 seconds (~20% slower) which is consistent with OP's statement.

+ GDC/LDC vs DMD
+ nobounds, release

Do you think we should start a topic on D wiki front page for benchmarking/performance tips to organize peoples' experience of what works?

I took a quick look and couldn't see anything already.  And it seems to be a topic that comes up quite frequently (less on forum than people doing their own benchmarks and it getting picked up on reddit etc).

I am not so experienced in this area otherwise I would write a first draft myself.

Laeeth
December 22, 2014
Hi Guys,

First of all, thank you all for responding so quick, it is so nice to see D having such an active community.

As I said in my first post, I used no other parameters to dmd when compiling because I don't know too much about dmd compilation flags. I can't wait to try the flags Daniel suggested with dmd (-O -release -inline -noboundscheck) and the other two compilers (ldc2 and gdc). Thank you guys for your suggestions.

Meanwhile, I created a git repository on github and I put there all my code. If you find any errors please let me know. Because I am keeping the results in a big array the programs take approximately 8Gb of RAM. If you don't have enough RAM feel free to decrease the size of the array. For java code you will also need to change 'compile-run.bsh' and use the right memory parameters.


Thank you all for helping,
Iov
December 22, 2014
On Monday, 22 December 2014 at 17:05:19 UTC, Iov Gherman wrote:
> Hi Guys,
>
> First of all, thank you all for responding so quick, it is so nice to see D having such an active community.
>
> As I said in my first post, I used no other parameters to dmd when compiling because I don't know too much about dmd compilation flags. I can't wait to try the flags Daniel suggested with dmd (-O -release -inline -noboundscheck) and the other two compilers (ldc2 and gdc). Thank you guys for your suggestions.
>
> Meanwhile, I created a git repository on github and I put there all my code. If you find any errors please let me know. Because I am keeping the results in a big array the programs take approximately 8Gb of RAM. If you don't have enough RAM feel free to decrease the size of the array. For java code you will also need to change 'compile-run.bsh' and use the right memory parameters.
>
>
> Thank you all for helping,
> Iov

Link to your repo?
« First   ‹ Prev
1 2 3 4