https://issues.dlang.org/show_bug.cgi?id=19712
Issue ID: 19712
Summary: std.math.sin and cos cast float to real before
evaluating.
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
import std.stdio;
import std.math;
import std.random;
import core.stdc.math;
import std.datetime;
void main()
{
auto r = benchmark!(
()=> std.math.sin(uniform(0.0f,1.0f))
,
()=> core.stdc.math.sinf(uniform(0.0f,1.0f))
)(1000000);
writefln("%s\n%s",r[0].usecs,r[1].usecs);
}
With gdc-8, this shows around a 4 times difference in speed between
std.math.sin and core.stdc.math.sinf.
Around 1.5 times difference with dmd via dlang.org web interface
This is because std.math.sin(float) casts the argument to real and then
evaluates it.
Apparently ldc does this better.
--