|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2001-10-23 12:26:50
I have carried out a few simplistic test of the function template
// Based on a post by Michael Kenniston:
http://groups.yahoo.com/group/boost/message/14867
as suggested by Ed below (with his suggested removal of the redundant
constructor).
It is not as easy as might appear because the compiler tends to optimise
everything away!
To avoid this I have used two naive methods, cout << pi << endl;
and global double dummy = p;
This suggests that the code produced is indeed quite efficient,
though no FP registers are used in this example.
Do the speed freaks who made much about the importance of the interface
satisfied?
Paul
Dr Paul A Bristow, hetp Chromatography
Prizet Farmhouse
Kendal, Cumbria
LA8 8AB UK
+44 1539 561830
Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]
_constpi DQ 0400921fb54442d18r ; 3.14159 <<<<< pi in hex
; 52 : double ccp = constpi; // assignment to a local or global const
double
; 53 : cout << ccp << endl; // prevent optimisation.
00000 a1 04 00 00 00 mov eax, DWORD PTR _constpi+4
00005 8b 0d 00 00 00
00 mov ecx, DWORD PTR _constpi
0000b 56 push esi
0000c 50 push eax
0000d 51 push ecx
0000e b9 00 00 00 00 mov ecx, OFFSET
FLAT:?cout_at_std@@3V?$basic_ostream_at_DU?$char_traits_at_D@std@@@1_at_A
00013 e8 00 00 00 00 call
??6?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV01_at_N@Z ;
std::basic_ostream<char,std::char_traits<char> >::operator<<
00018 8b f0 mov esi, eax
0001a 6a 0a push 10 ; 0000000aH
0001c 8b ce mov ecx, esi
0001e e8 00 00 00 00 call
?put@?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV12_at_D@Z ;
std::basic_ostream<char,std::char_traits<char> >::put
00023 8b ce mov ecx, esi
00025 e8 00 00 00 00 call
?flush@?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV12_at_XZ ;
std::basic_ostream<char,std::char_traits<char> >::flush
; 54 : double pd = 3.141592653589793238462643383279502884197;
; 55 : double p = pi; // assignment using templated function constant pi
; 56 : cout << p << endl; // prevent optimisation.
0002a 68 fb 21 09 40 push 1074340347 ; 400921fbH <<<<< pi in hex
0002f 68 18 2d 44 54 push 1413754136 ; 54442d18H <<<<< pi in hex
00034 b9 00 00 00 00 mov ecx, OFFSET
FLAT:?cout_at_std@@3V?$basic_ostream_at_DU?$char_traits_at_D@std@@@1_at_A
00039 e8 00 00 00 00 call
??6?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV01_at_N@Z ;
std::basic_ostream<char,std::char_traits<char> >::operator<<
0003e 8b f0 mov esi, eax
00040 6a 0a push 10 ; 0000000aH
00042 8b ce mov ecx, esi
00044 e8 00 00 00 00 call
?put@?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV12_at_D@Z ;
std::basic_ostream<char,std::char_traits<char> >::put
00049 8b ce mov ecx, esi
0004b e8 00 00 00 00 call
?flush@?$basic_ostream_at_DU?$char_traits_at_D@std@@@std@@QAEAAV12_at_XZ ;
std::basic_ostream<char,std::char_traits<char> >::flush
; 60 : double p = pi; // assignment using function.
; 61 : dummy = p; // prevent optimisation - dummy is global.
00000 c7 05 00 00 00
00 18 2d 44 54 mov DWORD PTR ?dummy@@3NA, 1413754136 ; 54442d18H <<<<< pi
in hex
0000a c7 05 04 00 00
00 fb 21 09 40 mov DWORD PTR ?dummy@@3NA+4, 1074340347 ; 400921fbH <<<<<
pi in hex
> -----Original Message-----
> From: Ed Brey [mailto:edbrey_at_[hidden]]
> Sent: Tuesday, October 23, 2001 1:56 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Math constants for naive and gurus? - which
> constants do you want?
The testing I did was rather simplistic. Rather than share my
> results, I'd rather have you independently generate your own
> results from your own tests, now that you know how get to the
> release mode assembly. I'm certain you'll be able to think of
> more real-world test cases than I could.
>
> Assuming that inspection of the assembly output yields positive
> results, the next test I would recommend is taking some
> signficant piece of math-intenstive code, and compiling it twice,
> once with plain old constants definitions, and once with the
> template definitions. There would be too much output to wade
> through by hand, be one should be able to do comparisons of the
> resulting assembly, object, and executable files. I expect that
> they will be byte-for-byte identical.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk