]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/benchmarks/strings.cpp
added some Replace() benchmarks (#9802)
[wxWidgets.git] / tests / benchmarks / strings.cpp
index e86b629e96ba2a13876106d7d6f1742ea0ff4dfe..321a860f4aea51c3e26cc8497e50aae9b2eedfc9 100644 (file)
@@ -222,3 +222,37 @@ BENCHMARK_FUNC(ForStringRIter)
     return true;
 }
 
+// ----------------------------------------------------------------------------
+// wxString::Replace()
+// ----------------------------------------------------------------------------
+
+const size_t REPLACE_STR_LEN = 1000;
+
+BENCHMARK_FUNC(ReplaceLoop)
+{
+    wxString str('x', REPLACE_STR_LEN);
+    for ( size_t n = 0; n < REPLACE_STR_LEN; n++ )
+    {
+        if ( str[n] == 'a' )
+            str[n] = 'z';
+    }
+
+    return str.length() != 0;
+}
+
+BENCHMARK_FUNC(ReplaceMiss)
+{
+    wxString str('x', REPLACE_STR_LEN);
+    str.Replace("a", "z");
+
+    return str.length() != 0;
+}
+
+BENCHMARK_FUNC(ReplaceHit)
+{
+    wxString str('x', REPLACE_STR_LEN);
+    str.Replace("x", "y");
+
+    return str.length() != 0;
+}
+