Community
cancel
Showing results for 
Search instead for 
Did you mean: 
SergeyKostrov
Valued Contributor II
43 Views

Test results for CRT-function 'sqrt' for different Floating Point Models

Intel C++ compiler supports four Floating Point Models: Fast, Precise, Strict and Fast=2 and test results demonstrate how performance is affected when CRT-function sqrt is called ( results are in ASC order ): [ Fast=2 (/fp:fast=2) [Intel C++] ] 32-bit Windows platform CRT Sqrt - float - Calculating the Square Roots - 203 ticks Last Result: 134217728.000^0.5 = 11585.236 CRT Sqrt - double - Calculating the Square Roots - 750 ticks Last Result: 134217728.000^0.5 = 11585.237 [ Fast (/fp:fast) ] 32-bit Windows platform CRT Sqrt - float - Calculating the Square Roots - 219 ticks Last Result: 134217728.000^0.5 = 11585.236 CRT Sqrt - double - Calculating the Square Roots - 750 ticks Last Result: 134217728.000^0.5 = 11585.237 [ Precise (/fp:precise) ] 32-bit Windows platform CRT Sqrt - float - Calculating the Square Roots - 422 ticks Last Result: 134217728.000^0.5 = 11585.237 CRT Sqrt - double - Calculating the Square Roots - 750 ticks Last Result: 134217728.000^0.5 = 11585.237 [ Strict (/fp:strict) ] 32-bit Windows platform CRT Sqrt - float - Calculating the Square Roots - 875 ticks Last Result: 134217728.000^0.5 = 11585.237 CRT Sqrt - double - Calculating the Square Roots - 2969 ticks Last Result: 134217728.000^0.5 = 11585.237 As you can see Fast=2 is the fastest Floating Point Model, and Strict is the slowest ( slower in 875 / 203 = ~4.3x ).
0 Kudos
1 Reply
SergeyKostrov
Valued Contributor II
43 Views

Here are source codes of the test case: #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 #endif #include "stdio.h" #include "tchar.h" #include "float.h" #include "math.h" #include "windows.h" #ifdef _WIN32_PLATFORM #define _WIN_PLATFORM _T("32-bit Windows platform") #endif #ifdef _WIN64_PLATFORM #define _WIN_PLATFORM _T("64-bit Windows platform") #endif #define _USE_CRT_SQRT_FLOAT_ #define _USE_CRT_SQRT_DOUBLE_ int _tmain( void ) { _tprintf( _T("%s\n"), _WIN_PLATFORM ); // Initializations unsigned int uiTicksStart = 0U; unsigned int uiControlWordx87 = 0U; int iV = 0; int iNumberOfIterations = 134217728; // 2^27 int iDummy = -1; float fRes = 0.0f; double dRes = 0.0L; uiControlWordx87 = _control87( _PC_53, _MCW_PC ); // Sub-Test 1 - CRT sqrt - float { #ifdef _USE_CRT_SQRT_FLOAT_ _tprintf( _T("CRT Sqrt - float - Calculating the Square Roots") ); uiTicksStart = ::GetTickCount(); for( iV = 0; iV < iNumberOfIterations; iV++ ) { iDummy = -1; fRes = sqrt( ( float )iV ); } _tprintf( _T(" - %ld ticks\n"), ( int )( ::GetTickCount() - uiTicksStart ) ); _tprintf( _T("\tLast Result: %.3f^0.5 = %.3f\n"), ( float )iV, fRes ); #endif } // Sub-Test 2 - CRT sqrt - double { #ifdef _USE_CRT_SQRT_DOUBLE_ _tprintf( _T("CRT Sqrt - double - Calculating the Square Roots") ); uiTicksStart = ::GetTickCount(); for( iV = 0; iV < iNumberOfIterations; iV++ ) { iDummy = -1; dRes = sqrt( ( double )iV ); } _tprintf( _T(" - %ld ticks\n"), ( int )( ::GetTickCount() - uiTicksStart ) ); _tprintf( _T("\tLast Result: %.3f^0.5 = %.3f\n"), ( double )iV, dRes ); #endif } _tprintf( _T("Press ESC to Exit...\n") ); _gettch(); return ( int )0; }
Reply