This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
While debugging recently, I noticed that every time __convert_from_v
is called, there are expensive calls to malloc, free, strlen, strcpy,
and two possibly unnecessary extra calls to setlocale. I've added a
cheap check to see if the locale is already "C" before we get out the
hammers. I haven't address the exception safety issues raised
earlier.
I used a simple test to see if it is actually faster:
#include <iostream>
using std::cout;
int
main()
{
const int x = 12345;
for(unsigned int i = 0; i < 1000000; ++i) {
cout << x;
}
return 0;
}
$ locale
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=
$ test-gcc/i686-pc-linux-gnu/bin/g++ -Wall -g -O6 -o loc main.cc
$ time ./loc >/dev/null
real 0m3.066s
user 0m3.070s
sys 0m0.000s
$ g++ -Wall -g -O6 -o loc-stock main.cc
$ time ./loc-stock >/dev/null
real 0m3.416s
user 0m3.410s
sys 0m0.000s
This seems to be harmless... Is it not? I couldn't seem to set my
locale (inside the application) no matter what I tried, so I haven't
tested opposite case to see how much it slows down (if it is at all
noticable).
I'm also curious as to whether the entire locale needs to be changed.
I take it that the character set is what is preventing just LC_NUMERIC
from being modified? Or am I just naive? :)
Patch attached.
--
------------------------------------------------------------------
Brad Spencer - spencer@infointeractive.com - "It's quite nice..."
Systems Architect | InfoInterActive Corp. | A Canadian AOL Company
Attachment:
gcc-3.2-libstdc++-v3-locale_facets-optimized.patch
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |