This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug libstdc++/14078] Manipulators are slow


------- Additional Comments From peturr02 at ru dot is  2004-02-09 09:44 -------
Created an attachment (id=5706)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5706&action=view)
Test case

Results for 3.4:

time ./manipspeed manip 100000000
14.13user 0.00system 0:14.13elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (61major+11minor)pagefaults 0swaps
time ./manipspeed setf 100000000
0.76user 0.00system 0:00.75elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (61major+11minor)pagefaults 0swaps
time ./manipspeed direct 100000000
0.75user 0.00system 0:00.74elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (61major+11minor)pagefaults 0swaps
time ./manipspeed call 100000000
5.87user 0.00system 0:05.87elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (61major+11minor)pagefaults 0swaps

Results for 3.3.2:

time ./manipspeed manip 100000000
43.55user 0.21system 0:44.39elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (72major+12minor)pagefaults 0swaps
time ./manipspeed setf 100000000
1.32user 0.03system 0:01.37elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (71major+13minor)pagefaults 0swaps
time ./manipspeed direct 100000000
1.24user 0.01system 0:01.28elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (71major+13minor)pagefaults 0swaps
time ./manipspeed call 100000000
6.97user 0.01system 0:07.08elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (71major+13minor)pagefaults 0swaps

In both cases, the first number is the result of using manipulators:
os << foo;
the second from using setf:
os.setf(ios_base::foo);
the third from a direct call to the manipulator
foo(os);
and the fourth from calling the manipulator indirectly through an inline
function
call(os, foo);
where call is exactly like operator<< for manipulators, except inline:
template<typename C, typename T>
inline std::basic_ostream<C, T>&
call(std::basic_ostream<C, T>& os, std::ios_base&(*pf)(std::ios_base&))
{
	pf(os);
	return os;
}

So it seems manipulators can be made a lot faster just by inlining the
relevant versions of operators << and >>.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14078


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