This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
A stupid benchmark for a trivial idea
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Pétur Runólfsson <peturr02 at ru dot is>, Jerry Quinn <jlquinn at optonline dot net>
- Date: Sat, 29 Nov 2003 21:40:37 +0100
- Subject: A stupid benchmark for a trivial idea
Hi all,
so, before going out for a movie, I did this very stupid test:
////////////////////////
#include <cwchar>
#include <locale>
struct CtypeS: std::ctype<wchar_t>
{
char
do_narrow(wchar_t __wc, char __dfault) const
{
int __c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
};
struct CtypeF: std::ctype<wchar_t>
{
int cached[128];
char
do_narrow(wchar_t __wc, char __dfault) const
{
int __c;
if (__wc < 128)
__c = cached[__wc];
else
__c = wctob(__wc);
return (__c == EOF ? __dfault : static_cast<char>(__c));
}
};
int main()
{
using namespace std;
CtypeS cty; // CtypeF
for (long i = 0; i < 100000000; ++i)
cty.narrow(i % 128, '*');
}
//////////////////////
These are the numbers (-O2, P4-2400):
CtypeS
------
9.540u 0.000s 0:09.57 99.6% 0+0k 0+0io 191pf+0w
CtypeF
------
0.940u 0.000s 0:00.95 98.9% 0+0k 0+0io 191pf+0w
Yes, it's like it seems, 10x faster!
So... guys, let's converge to something *really* nice for the cute
caching mechanism inside narrow (widen) or otherwise... ;-)
Paolo.