comparison of 2.95.2 and 3.2 optimizers on SPARC
Brad Spencer
spencer@infointeractive.com
Mon Jan 6 18:42:00 GMT 2003
On Thu, Jan 02, 2003 at 01:38:52PM -0600, Loren James Rittle wrote:
> Martin,
>
> Oops and, likewise, sorry I didn't see that issue. I can now confirm
> your report. Thank you (again) for taking the time to report it and
> the follow up.
>
> On FreeBSD/i386 with 2.95.X:
>
> S rittle@latour; time a.out 1000000 stdio >/dev/null
> 2r 1.6u 0.0s a.out 1000000 stdio
> S rittle@latour; time a.out 1000000 iostream >/dev/null
> 1r 0.9u 0.0s a.out 1000000 iostream
>
> On FreeBSD/i386 with mainline:
>
> S rittle@latour; time a.out 1000000 stdio >/dev/null
> 1r 1.6u 0.0s a.out 1000000 stdio
> S rittle@latour; time a.out 1000000 iostream >/dev/null
> 14r 14.4u 0.0s a.out 1000000 iostream
>
I posted a patch in October[1] that tried to avoid some unnecessary
work that is done every time a numeric is converted to a string. It
was against the 3.2 release, so it's a bit out of date now, but the
idea is still valid. I've attached a somewhat more modern version
for the gcc-3.3 series. Perhaps this addresses part of the slowdown?
References:
[1] http://gcc.gnu.org/ml/libstdc++/2002-10/msg00056.html
--
------------------------------------------------------------------
Brad Spencer - spencer@infointeractive.com - "It's quite nice..."
Systems Architect | InfoInterActive Corp. | A Canadian AOL Company
-------------- next part --------------
ChangeLog
2002-10-08 <spencer@infointeractive.com>
* include/bits/locale_facets.tcc (__convert_from_v): Avoid
expensive operations when C locale is already set.
*** ../../../../reference_gcc/gcc-3.2/libstdc++-v3/include/bits/locale_facets.tcc Tue Oct 8 17:48:11 2002
--- locale_facets.tcc Tue Oct 8 17:53:41 2002
*************** namespace std
*** 1977,1992 ****
{
int __ret;
char* __old = setlocale(LC_ALL, NULL);
! char* __sav = static_cast<char*>(malloc(strlen(__old) + 1));
! if (__sav)
! strcpy(__sav, __old);
! setlocale(LC_ALL, "C");
if (__prec >= 0)
__ret = snprintf(__out, __size, __fmt, __prec, __v);
else
__ret = snprintf(__out, __size, __fmt, __v);
! setlocale(LC_ALL, __sav);
! free(__sav);
return __ret;
}
#else
--- 1977,2007 ----
{
int __ret;
char* __old = setlocale(LC_ALL, NULL);
!
! // Only do all this expensive malloc/free, string copy and locale
! // setting if the locale is not already what we want.
! char* __sav;
! if (!(__old[0] == 'C' && __old[1] == '\0'))
! {
! __sav = static_cast<char*>(malloc(strlen(__old) + 1));
! if (__sav)
! strcpy(__sav, __old);
! setlocale(LC_ALL, "C");
! }
! else
! __sav = 0;
!
if (__prec >= 0)
__ret = snprintf(__out, __size, __fmt, __prec, __v);
else
__ret = snprintf(__out, __size, __fmt, __v);
!
! // Do we need to clean up?
! if(__sav)
! {
! setlocale(LC_ALL, __sav);
! free(__sav);
! }
return __ret;
}
#else
*************** namespace std
*** 1997,2012 ****
{
int __ret;
char* __old = setlocale(LC_ALL, NULL);
! char* __sav = static_cast<char*>(malloc(strlen(__old) + 1));
! if (__sav)
! strcpy(__sav, __old);
! setlocale(LC_ALL, "C");
if (__prec >= 0)
__ret = sprintf(__out, __fmt, __prec, __v);
else
__ret = sprintf(__out, __fmt, __v);
! setlocale(LC_ALL, __sav);
! free(__sav);
return __ret;
}
#endif
--- 2012,2042 ----
{
int __ret;
char* __old = setlocale(LC_ALL, NULL);
!
! // Only do all this expensive malloc/free, string copy and locale
! // setting if the locale is not already what we want.
! char* __sav;
! if (!(__old[0] == 'C' && __old[1] == '\0'))
! {
! __sav = static_cast<char*>(malloc(strlen(__old) + 1));
! if (__sav)
! strcpy(__sav, __old);
! setlocale(LC_ALL, "C");
! }
! else
! __sav = 0;
!
if (__prec >= 0)
__ret = sprintf(__out, __fmt, __prec, __v);
else
__ret = sprintf(__out, __fmt, __v);
!
! // Do we need to clean up?
! if(__sav)
! {
! setlocale(LC_ALL, __sav);
! free(__sav);
! }
return __ret;
}
#endif
More information about the Libstdc++
mailing list