X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8fad8b2e523579570274d9a8ee561a038dec5cab..32cdc45397d8c0a24735f84e1dcf83bba1980f2d:/tests/benchmarks/strings.cpp diff --git a/tests/benchmarks/strings.cpp b/tests/benchmarks/strings.cpp index 23a181d8c3..cc09a35418 100644 --- a/tests/benchmarks/strings.cpp +++ b/tests/benchmarks/strings.cpp @@ -40,6 +40,27 @@ static const char utf8str[] = "\xD0\xA6\xD0\xB5\xD0\xBB\xD0\xBE\xD0\xB5 \xD1\x87\xD0\xB8\xD1\x81\xD0\xBB\xD0\xBE 9" ; +namespace +{ + +const wxString& GetTestAsciiString() +{ + static wxString testString; + if ( testString.empty() ) + { + long num = Bench::GetNumericParameter(); + if ( !num ) + num = 1; + + for ( long n = 0; n < num; n++ ) + testString += wxString::FromAscii(asciistr); + } + + return testString; +} + +} // anonymous namespace + // this is just a baseline BENCHMARK_FUNC(Strlen) { @@ -187,7 +208,7 @@ BENCHMARK_FUNC(ForCString) BENCHMARK_FUNC(ForStringIndex) { - const wxString s = wxString::FromAscii(asciistr); + const wxString& s = GetTestAsciiString(); const size_t len = s.length(); for ( size_t n = 0; n < len; n++ ) { @@ -200,7 +221,7 @@ BENCHMARK_FUNC(ForStringIndex) BENCHMARK_FUNC(ForStringIter) { - const wxString s = wxString::FromAscii(asciistr); + const wxString& s = GetTestAsciiString(); const wxString::const_iterator end = s.end(); for ( wxString::const_iterator i = s.begin(); i != end; ++i ) { @@ -213,7 +234,7 @@ BENCHMARK_FUNC(ForStringIter) BENCHMARK_FUNC(ForStringRIter) { - const wxString s = wxString::FromAscii(asciistr); + const wxString& s = GetTestAsciiString(); const wxString::const_reverse_iterator rend = s.rend(); for ( wxString::const_reverse_iterator i = s.rbegin(); i != rend; ++i ) { @@ -260,6 +281,18 @@ BENCHMARK_FUNC(ReplaceAll) return str.Replace("x", "y") != 0; } +BENCHMARK_FUNC(ReplaceLonger) +{ + wxString str('x', ASCIISTR_LEN); + return str.Replace("x", "yy") != 0; +} + +BENCHMARK_FUNC(ReplaceShorter) +{ + wxString str('x', ASCIISTR_LEN); + return str.Replace("xx", "y") != 0; +} + // ---------------------------------------------------------------------------- // string buffers: wx[W]CharBuffer @@ -301,7 +334,11 @@ BENCHMARK_FUNC(ParseHTML) // this is going to make for some invalid HTML, of course, but it // doesn't really matter - for ( long n = 0; n < Bench::GetNumericParameter(); n++ ) + long num = Bench::GetNumericParameter(); + if ( !num ) + num = 1; + + for ( long n = 0; n < num; n++ ) html += html1; }