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]

[Patch] Speedup somewhat do_get_time and do_get_date


Hi,

this is a straightforward improvement: the result can be definitely
obtained by calling _M_extract_via_format only /once/, with the correct
format string corresponding to 'x'/'X' (as mandated by 22.2.5.1.2),
and avoiding completely the widen-ing.

Some numbers on P4-2400 for this small benchmark (-O2):

 for (int i = 0; i < 3000000; ++i)
   {
     iss.str("04/04/71 ");
     iterator_type is_it02(iss);
     errorstate = good;
     tim_get.get_date(is_it02, end, iss, errorstate, &time02);
   }

(no codesize changes)

3.3.3
-----
12.740u 0.010s 0:12.77 99.8%    0+0k 0+0io 207pf+0w

3.4
---
3.420u 0.000s 0:03.42 100.0%    0+0k 0+0io 196pf+0w

patched 3.4
-----------
2.890u 0.000s 0:02.89 100.0%    0+0k 0+0io 195pf+0w

mainline
--------
4.700u 0.000s 0:04.71 99.7%     0+0k 0+0io 199pf+0w

patched mainline
----------------
3.820u 0.000s 0:03.82 100.0%    0+0k 0+0io 199pf+0w

Icc8.0
------
2.830u 0.000s 0:02.84 99.6%     0+0k 0+0io 196pf+0w

And on x86-64-2GHz:

mainline
--------
2.346u 0.000s 0:02.34 100.0%    0+0k 0+0io 0pf+0w

mainline patched
----------------
2.250u 0.000s 0:02.25 100.0%    0+0k 0+0io 0pf+0w


Regtested x86-linux.


Paolo.

P.S. Perhaps eventually case 'x' and case 'X' could be removed from
the switch in _M_extract_via_format...

/////////////////
2004-06-12  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (time_get<>::do_get_time,
	time_get<>::do_get_date): Use only once _M_extract_via_format,
	instead of going through "%X"/"%x" and calling it two times.
diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2004-05-22 11:02:54.000000000 +0200
+++ libstdc++-v3/include/bits/locale_facets.tcc	2004-06-12 20:57:12.000000000 +0200
@@ -2056,12 +2056,12 @@
     do_get_time(iter_type __beg, iter_type __end, ios_base& __io,
 		ios_base::iostate& __err, tm* __tm) const
     {
-      _CharT __wcs[3];
-      const char* __cs = "%X";
       const locale& __loc = __io._M_getloc();
-      ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
-      __ctype.widen(__cs, __cs + 3, __wcs);
-      __beg = _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
+      const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
+      const char_type* __times[2];
+      __tp._M_time_formats(__times);
+      __beg = _M_extract_via_format(__beg, __end, __io, __err, 
+				    __tm, __times[0]);
       if (__beg == __end)
 	__err |= ios_base::eofbit;
       return __beg;
@@ -2073,12 +2073,12 @@
     do_get_date(iter_type __beg, iter_type __end, ios_base& __io,
 		ios_base::iostate& __err, tm* __tm) const
     {
-      _CharT __wcs[3];
-      const char* __cs = "%x";
       const locale& __loc = __io._M_getloc();
-      ctype<_CharT> const& __ctype = use_facet<ctype<_CharT> >(__loc);
-      __ctype.widen(__cs, __cs + 3, __wcs);
-      __beg = _M_extract_via_format(__beg, __end, __io, __err, __tm, __wcs);
+      const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
+      const char_type* __dates[2];
+      __tp._M_date_formats(__dates);
+      __beg = _M_extract_via_format(__beg, __end, __io, __err,
+				    __tm, __dates[0]);
       if (__beg == __end)
 	__err |= ios_base::eofbit;
       return __beg;
@@ -2094,7 +2094,7 @@
       const locale& __loc = __io._M_getloc();
       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-      const char_type*  __days[7];
+      const char_type* __days[7];
       __tp._M_days_abbreviated(__days);
       int __tmpwday;
       __beg = _M_extract_name(__beg, __end, __tmpwday, __days, 7, __io, __err);
@@ -2138,7 +2138,7 @@
       const locale& __loc = __io._M_getloc();
       const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc);
       const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc);
-      const char_type*  __months[12];
+      const char_type* __months[12];
       __tp._M_months_abbreviated(__months);
       int __tmpmon;
       __beg = _M_extract_name(__beg, __end, __tmpmon, __months, 12, 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]