math.log() benchmark of first 1 billion int using std.parallelism
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 23 05:26:24 PST 2014
On Tuesday, 23 December 2014 at 12:31:47 UTC, Iov Gherman wrote:
>
>> Btw. I just noticed small issue with D vs. java, you start
>> messure in D before allocation, but in case of Java after
>> allocation
>
> Here is the java result for parallel processing after moving
> the start time as the first line in main. Still best result:
>
> 4 secs, 50 ms average
Java:
Exec time: 6 secs, 421 ms
LDC (-O3 -release -mcpu=native -singleobj -inline
-boundscheck=off)
time: 5 secs, 321 ms, 877 μs, and 2 hnsecs
GDC(-O3 -frelease -march=native -finline -fno-bounds-check)
time: 5 secs, 237 ms, 453 μs, and 7 hnsecs
DMD(-O -release -inline -noboundscheck)
time: 5 secs, 107 ms, 931 μs, and 3 hnsecs
So all d compilers beat Java in my case:
but I have made some change in D version:
import std.parallelism, std.math, std.stdio, std.datetime;
import core.memory;
enum XMS = 3*1024*1024*1024; //3GB
version(GNU)
{
real mylog(double x) pure nothrow
{
double result;
double y = LN2;
asm
{
"fldl %2\n"
"fldl %1\n"
"fyl2x\n"
: "=t" (result) : "m" (x), "m" (y);
}
return result;
}
}
else
{
real mylog(double x) pure nothrow
{
return yl2x(x, LN2);
}
}
void main() {
GC.reserve(XMS);
auto t1 = Clock.currTime();
auto logs = new double[1_000_000_000];
foreach(i, ref elem; taskPool.parallel(logs, 200)) {
elem = mylog(i + 1.0);
}
auto t2 = Clock.currTime();
writeln("time: ", (t2 - t1));
}
More information about the Digitalmars-d-learn
mailing list