There is an array (1-10 elements) consisting of long (up to 10,000 characters) immutable strings. There is also one (the same long) line that is actively changing. Strings from an array are very actively compared to a variable string.
Added inline to functions, added register to the variable line, the program still runs slowly. The array of strings is implemented as string *, the other string is just string.
Tell me please, how can I speed up the execution of the program? Will string.erase work faster with string.substr? Or is it generally better to use classic char strings instead of string strings?
Thanks in advance!
UPD: added some code
the min-str string does not change (just stores the value for sub-str) (the '_' is not inserted into the message)
sub_str = min_str.substr(j, i);
After the sub-str gets the value, the function is checked.
if (is_inside(sub_str, str, amount))
And this is, in fact, the function itself, which checks whether the substring is included in all the strings of a given array.
inline bool is_inside(string sub_str, string *str, int n) { int m = 0; for (int i = 0; i < n; i++) { if ( str[i].find(sub_str) != -1 ) { m++ ;} } if (m == n) { return true; } else { return false; } }
I just realized that the program should work faster if I pass the values to the function by reference (or pointer). Any more suggestions?