-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use get_slicec
instead of get_slice
for single character splitters
#99321
base: master
Are you sure you want to change the base?
Conversation
e829348
to
9cb42b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me.
ee50098
to
8d2cbf7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
8d2cbf7
to
276d4bb
Compare
276d4bb
to
76d834f
Compare
I don't doubt that this is a performance improvement, as this is swapping to the function specialized for this input, but we should really make a habit of including metrics with performance PRs (and/or the metrics of the PR adding this function) |
These are difficult to measure in situ, as they are scattered over the codebase, we lack proper tools to perform such performance tests, and proper documentation for the process, so until that exists that's hard to request (the tools and documentation has been requested on multiple occasions but hasn't surfaced yet) If such existed and was provided it would be trivial to do so and would do so |
8dc5b1b
to
cac6b15
Compare
You could always show the general performance difference between |
For that the test is trivial and the test is trivial, and runs with a clear improvement:
Using MRP: PC specifications:
Tested with an editor build, will test with a release build as well For a release build (using
|
Well, this benchmark isn't entirely fair because you're calling from GDScript, i.e. |
This doesn't involve any string allocations, as it is a string literal in GDScript no string should be allocated on calling this (if it is that's a major bug in GDScript) |
Interesting, that changes things! // Setup
String s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
auto t0 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 100000; i ++) {
String s1 = s.get_slice(",", 0);
}
auto t1 = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() << "ms\n"; |
I don't have such a setup prepared at the time being so can't test it until I set something up that would be reasonably isolated |
We don't need to discuss your setup here - but I would be amiss not to mention that anywhere you can compile and run code is fine to benchmark on! Anyway, I'm happy to fill in - i ran this benchmark (debug build, Test Code String s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
// warmup
s.get_slice(",", 0);
{
auto t0 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 20000000; i ++) {
String s1 = s.get_slice(",", 0);
}
auto t1 = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() << "ms\n";
}
// warmup
s.get_slicec(',', 0);
{
auto t0 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 20000000; i ++) {
String s1 = s.get_slicec(',', 0);
}
auto t1 = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() << "ms\n";
} I got |
Thank you for testing! |
This method exists for this dedicated purpose and is faster for these kinds of input