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.
> With gdc-8, this shows around a 4 times difference in speed between std.math.sin and core.stdc.math.sinf. FYI: GDC has a separate bug tracker https://bugzilla.gdcproject.org/describecomponents.cgi > Apparently ldc does this better. Not apparently, it's has the same speed as the C runtime: https://run.dlang.io/is/4AweFj
I put the bug here because it is caused by phobos. Ldc has added a version(ldc) section that removes the casts to real and implements sin and cos differently depending on precision. if I can get around it by calling a different sin function in phobos, then I think it is a phobos bug, but there is some interaction with the compilers
Duplicate of 18559 *** This issue has been marked as a duplicate of issue 18559 ***