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 02:46:58 PST 2014


On Tuesday, 23 December 2014 at 10:39:13 UTC, Iov Gherman wrote:
>
>> These multi-threaded benchmarks can be very sensitive to their 
>> environment, you should try running it with nice -20 and do 
>> multiple passes to get a vague idea of the variability in the 
>> result. Also, it's important to minimise the number of other 
>> running processes.
>
> I did not use the nice parameter but I always ran them multiple 
> times and choose the average time. My system has very few 
> running processes, minimalist ArchLinux with Xfce4 so I don't 
> think the running processes are affecting in any way my tests.

And what about single threaded version?

Btw. One reason why DMD is faster is because it use fyl2x X87 
instruction

here is version for others compilers:

import std.math, std.stdio, std.datetime;

enum SIZE = 100_000_000;

version(GNU)
{
	real mylog(double x) pure nothrow
	{
		real result;
		double y = LN2;
		asm
		{
			"fldl   %2\n"
			"fldl   %1\n"
			"fyl2x"
			: "=t" (result) : "m" (x), "m" (y);
		}
		return result;
	}
}
else
{
	real mylog(double x) pure nothrow
	{
		return yl2x(x, LN2);
	}
}

void main() {
	
	auto t1 = Clock.currTime();
	auto logs = new double[SIZE];
	
	foreach (i; 0 .. SIZE)
	{
		logs[i] = mylog(i + 1.0);
	}

	auto t2 = Clock.currTime();

	writeln("time: ", (t2 - t1));
}

But it is faster only on all Intel CPU, but on one of my AMD it 
is slower than core.stdc.log


More information about the Digitalmars-d-learn mailing list