Test code:
#include
#include
const int N = 4096;
const float PI = 3.1415926535897932384626;
float cosine[N][N];
float sine[N][
I did some measurements using clang with -O3 optimization, running on an Intel Core i7. I found that:
std::sin on float has the same cost as sinfstd::sin on double has the same cost as sindouble are 2.5x slower than on float (again, running on an Intel Core i7).Here is the full code to reproduce it:
#include
#include
#include
template
struct Timer
{
using rep = typename Clock::rep;
using time_point = typename Clock::time_point;
using resolution = typename Clock::duration;
Timer(rep& duration) :
duration(&duration) {
startTime = Clock::now();
}
~Timer() {
using namespace std::chrono;
*duration = duration_cast(Clock::now() - startTime).count();
}
private:
time_point startTime;
rep* duration;
};
template
void testSin(F sin_func) {
using namespace std;
using namespace std::chrono;
high_resolution_clock::rep duration = 0;
T sum {};
{
Timer t(duration);
for(int i=0; i<100000000; ++i) {
sum += sin_func(static_cast(i));
}
}
cout << duration << endl;
cout << " " << sum << endl;
}
int main() {
testSin ([] (float v) { return std::sin(v); });
testSin ([] (float v) { return sinf(v); });
testSin([] (double v) { return std::sin(v); });
testSin([] (double v) { return sin(v); });
return 0;
}
I'd be interested if people could report, in the comments on the results on their architectures, especially regarding float vs. double time.