-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lots of assertions (e.g. in loops) are slow #556
Comments
Hmm...this makes me wonder... What if Catch used type erasure to store the lhs and rhs without converting it to a string? Then it can convert it if it actually needs to, not at every test case. |
For very long loops, give a single boolean expression to CATCH, instead of an
The extra set of parentheses will make |
Thanks for making these changes; the following has some timing figures that hopefully make sense. Here's a simple example:
I've reduced the number of iterations 64 times from the original example to make the timing more feasible. Building with:
With the unmodified Catch:
With the modified Catch:
By adding extra parentheses to assertion with unmodified Catch:
If the assertion in the loop is removed entirely:
Given that I'd like to do 64 times the number of comparisons, these timing numbers are too large for either a normal
This gives (note that I'm now building without optimisation and I increased the iterations back to the original
This is a reasonably viable figure, though it does show that performing this many comparisons is bound to be slow anyway. Of course, it's a lot faster if I re-enable optimisation:
|
Do you really need to check all |
Yeah, I think this is the best solution. |
@SCross99 This ticket seems to be about a performance issue. How about renaming this ticket "Lots of assertions (e.g. in loops) are slow" |
@kirbyfan64 you got my attention with the claimed performance increase. Lazy stringifying makes sense to me. Travis CI seems to be failing on the current PR. What are your plans for the patch? I'd be interested in helping you test and improve it if you plan to keep working on it. Lazy stringifying aside, I noticed a couple of potential perf issues with the current master:
|
I just haven't gotten a chance to fix the failures yet. I'll hopefully do it today or tomorrow. |
The patch by @kirbyfan64 takes the approach of moving a lot of string conversion into one place, and then avoiding generating strings unless needed. An alternative approach is to improve string handling. There are numerous opportunities to improve string handling performance in Catch. For example, static file names don't need to be Here is a rough-cut of some improvements: I get roughly 50% of the performance improvement given by @kirbyfan64's patch. Combining the patches is possible, but since @kirbyfan64's disables most string generation, it disables most of the optimizations in my patch, so there is no aggregate benefit unless some strings will be generated. I likely won't submit this as a PR until Phil merges some of the smaller dependent changes. In my view, much of this improvement should be done irrespective of the status of the lazily stringify patch. |
If I have a test like the following:
The problem is the
CHECK
asserts in the loops are very slow, which appears to be because the values are being converted into strings each time.It seems like the above is not the best practice with Catch (?), so could you suggest how a test like this should be written?
The text was updated successfully, but these errors were encountered: