On Thursday, 23 May 2019 at 19:17:40 UTC, Ola Fosheim Grøstad wrote:
On Wednesday, 22 May 2019 at 00:22:09 UTC, JS wrote:
        xxx = 0;
        sw.reset();
        sw.start();
        for(double i = 0; i < 10000000; i++) xxx += sin(PI*i);
        t = sw.peek().msecs;
        writeln(t);
        sw.stop();
}

What you are doing wrong is that xxx is never used... So DMD removes it altogether?

If you add writeln(xxx) after the second loop as well, then maybe the measurements make more sense?

Ola.

maybe, I thought I put in the writeln(xxx) in there to do that... yeah, looking at my code it's there, so that is not the problem.

This is the code I had,

        import std.datetime;
        double xxx = 0;
        StopWatch sw;
    sw.start();
        for(double i = 0; i < 10000000; i++) xxx += sinTab(i);
        auto t = sw.peek().msecs;
        writeln(t);
        sw.stop();
        writeln(xxx);
        
        xxx = 0;
        sw.reset();
        sw.start();
        for(double i = 0; i < 10000000; i++) xxx += sin(PI*i);
        t = sw.peek().msecs;
        writeln(t);
        sw.stop();
        writeln(xxx);

Either I modified it later or deleted one of those lines or the editor screwed up when I pasted it... I don't recall touching the code afterwards.

Either way, sin it's still twice as fast. Also, in the code the sinTab version is missing the writeln so it would have been faster.. so it is not being optimized out.

Reply via email to