Created attachment 7394 [details] demo code The cosine function, cos, can be exceedingly slow for a few number of values. From my measurement on my PC using the attached C++ program I find that cos almost always takes in the order of 2e-8 seconds, but occasionally it will take around 1.5e-4 seconds, 0.15ms. It always takes around this time for particular values, e.g. 1.27730245420149213 (radians). (This difference, 4 order of magnitude, is quite a problem for us as we have to repeatedly perform a large number of calculations within 1ms.) GCC versions 4.6.3 and 4.7.2, GLIBC version 2.15, 2.18, i7 PCs, Ubuntu 12.04, Yocto
That is known issue, see bug 5997. It is caused by wanting cos error to be at most ulp. *** This bug has been marked as a duplicate of bug 5997 ***
I don't think this is a duplicate of bug 5997 which concerns large multiples of PI. It looks more like a potential duplicate of bug 5781 although this seems specific to AMD64 whilst this reported problem is on Intel i7s. Please note this is a critical problem for those implementing high performance real-time systems. A time of 0.15 ms is a massive amount of time for a modern processor. There are very few numbers for which cos takes this time but they are fatal for any guarantee of real-time performance.
On Wed, 5 Feb 2014, john.wilkinson at spirent dot com wrote: > I don't think this is a duplicate of bug 5997 which concerns large multiples of > PI. It looks more like a potential duplicate of bug 5781 although this seems > specific to AMD64 whilst this reported problem is on Intel i7s. The AMD64 mention there is simply because that was the system the submitter used for testing. This is a duplicate of 5781, which is not architecture-specific at all.
OK, I'll close this as duplicate of 5781. *** This bug has been marked as a duplicate of bug 5781 ***