Why is this so much slower in C++?

后端 未结 9 2053
盖世英雄少女心
盖世英雄少女心 2020-12-31 11:49

I have converted this simple method from C# to C++. It reads a path table and populates a list of lists of ints (or a vector of vectors of ints).

A sample line from

9条回答
  •  自闭症患者
    2020-12-31 12:49

    I profiled the code with Very Sleepy (Visual C++ 2010, 32-bit Windows XP). I don't know how similar my input data was, but here are the results anyway:

    39% of the time was spent in basic_istream::operator>>

    12% basic_iostream::basic_iostream

    9% operator+

    8% _Mutex::Mutex

    5% getline

    5% basic_stringbuf::_Init

    4% locale::_Locimp::_Addfac

    4% vector::reserve

    4% basic_string::assign

    3% operator delete

    2% basic_Streambuf::basic_streambuf

    1% Wcsxfrm

    5% other functions

    Some of the stuff seems to be from inlined calls so it's a bit difficult to say where it actually comes from. But you can still get the idea. The only thing that should do I/O here is getline and that takes only 5%. The rest is overhead from stream and string operations. C++ streams are slow as hell.

提交回复
热议问题