You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And it seems that this will create a new std::string for "/" each time this is called which will dominate the execution time of code that calls isabs() repeatedly. Would it be reasonable to declare some of these constants to amortize this cost?
It seems "/" and "\" is used several times in pystring as the arguments to startswith, endswith, strip, etc. which take references to std::string as arguments and this could be more optimal for the cases where these functions get called a lot?
The text was updated successfully, but these errors were encountered:
I did some measurements, and on 2 million isab_posix calls this is the difference:
Without const: 473 miliseconds
With const: 260 miliseconds
So while it is almost twice as fast with the const, it's still pretty fast without it.
Still - if you look at all the cases where we use "/", "." etc, it could improve performance on large datasets if changed it all to consts.
Let me go over all the code and see how many of these we can change to consts.
Functions like pystring::os::path::isabs_posix call pystring::startswith:
bool isabs_posix(const std::string & s) { return pystring::startswith(s, "/"); }
And it seems that this will create a new std::string for "/" each time this is called which will dominate the execution time of code that calls isabs() repeatedly. Would it be reasonable to declare some of these constants to amortize this cost?
bool isabs_posix(const std::string & s) { static const std::string slash("/"); return pystring::startswith(s, slash); }
It seems "/" and "\" is used several times in pystring as the arguments to startswith, endswith, strip, etc. which take references to std::string as arguments and this could be more optimal for the cases where these functions get called a lot?
The text was updated successfully, but these errors were encountered: