本文整理汇总了C++中StopWatch::GetSeconds方法的典型用法代码示例。如果您正苦于以下问题:C++ StopWatch::GetSeconds方法的具体用法?C++ StopWatch::GetSeconds怎么用?C++ StopWatch::GetSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StopWatch
的用法示例。
在下文中一共展示了StopWatch::GetSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestPerformance
// test code
void TestPerformance(const No2StringBuilder<wchar_t> &tested, const std::vector<std::wstring> &tested2) {
const int loops = 4001; // Odd number to keep 1 result at the end.
////////////////
// Test std::accumulate()
////////////////
std::wstring accumulate_result;
size_t accumulate_len = 0;
StopWatch swAccumulate;
for (int i = 0; i < loops; ++i) {
std::wstring accumulator;
accumulate_result = std::accumulate(tested2.begin(), tested2.end(), accumulator);
accumulate_len ^= accumulate_result.size();
}
swAccumulate.Stop();
using std::cout;
using std::endl;
cout << "\tstd::accumulate: " << swAccumulate.GetSeconds() << ": size " << accumulate_len << endl;
////////////////
// Test ToString()
////////////////
std::wstring toString_result;
size_t toString_len = 0;
StopWatch swToString;
for (int i = 0; i < loops; ++i) {
toString_result = tested.toString();
toString_len ^= toString_result.size();
}
swToString.Stop();
cout << "\tToString: " << swToString.GetSeconds() << ": size " << toString_len << endl;
////////////////
// Test join()
////////////////
std::wstring join_result;
size_t join_len = 0;
StopWatch swJoin;
for (int i = 0; i < loops; ++i) {
join_result = tested.join(L",");
join_len ^= join_result.size();
}
swJoin.Stop();
cout << "\tJoin: " << swJoin.GetSeconds() << ": size " << join_len << endl;
////////////////
// basic_ostringstream<wchar_t>
// First test: only getting the string, not filling the stream.
////////////////
typedef std::basic_ostringstream<wchar_t> wostringstream;
wostringstream woss;
for(size_t j = 0; j < tested2.size(); ++j)
woss << tested2[j];
std::wstring stringStream_result;
size_t stringStream_len = 0;
StopWatch swStringStream;
for (int i = 0; i < loops; ++i) {
stringStream_result = woss.str();
stringStream_len ^= stringStream_result.size();
}
swStringStream.Stop();
cout << "\tostringstream: " << swStringStream.GetSeconds() << ": size " << stringStream_len << endl;
////////////////
// Test lambda
////////////////
std::wstring strAccumulator;
size_t lambdaResult_len = 0;
StopWatch swLambda;
for (int i = 0; i < loops; ++i) {
std::wstring strtmp;
std::for_each(tested2.begin(), tested2.end(), [&](const std::wstring &s){ strtmp += s; });
if (0 == i) {
strAccumulator = strtmp;
}
lambdaResult_len ^= strtmp.size();
}
swLambda.Stop();
cout << "\tLambda: " << swLambda.GetSeconds() << ": size " << lambdaResult_len << endl;
////////////////
// Show results so far.
////////////////
cout << "* Performance test:" << endl
<< " Accumulate took " << swAccumulate.GetSeconds() << " seconds, and ToString() took " << swToString.GetSeconds() << " seconds." << endl
<< " The relative speed improvement was " << ((swAccumulate.GetSeconds() / swToString.GetSeconds()) - 1) * 100 << "%" << endl
<< " std::ostringstream took " << swStringStream.GetSeconds() << " with a relative speed improvement of " << ((swAccumulate.GetSeconds() / swStringStream.GetSeconds()) - 1) * 100 << "% (winning, you say?)" << endl
<< " lambda took " << swLambda.GetSeconds() << " with a relative speed improvement of " << ((swAccumulate.GetSeconds() / swLambda.GetSeconds()) - 1) * 100 << "% (winning, you say?)" << endl
<< " Join took " << swJoin.GetSeconds() << " seconds."
<< endl;
////////////////
// basic_ostringstream<wchar_t> and tostring: fill and execute.
////////////////
if (true) {
size_t tmp = 0;
typedef std::basic_ostringstream<wchar_t> wostringstream;
StopWatch swStringStream2;
for (int i = 0; i < loops; ++i) {
wostringstream woss;
//.........这里部分代码省略.........