Optimize getting intersection points by doing integer arithmetic only #663
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NB: I'm not really requesting to merge the code in this PR right now. Instead this is, at least for the time being, more of a side note with code related to the performance issue mentioned in #657.
While looking into #657 and performance, started to ask myself: if we anyway truncate the result (instead of rounding), is floating-point arithmetic even needed here?
At least on my machine, the integer-only arithmetic of this PR appears to speed up the benchmark code quite a bit (more than 2x, I think?).
It does change the results a little bit, though. In fact in some cases it's more accurate. Why? For example, in floating-point arithmetic 45.0 / 66.0 * 22.0 = 14.999999999999998 (which truncates to 14), but in plain integer arithmetic 22 * 45 / 66 = 15.
In fact, similar to this comment, it seems to me that it's not about avoiding floating-point arithmetic as such (the difference shouldn't be that remarkable, although that depends on the CPU of course), but more about how exactly the updated results end up being processed downstream. But I do still think that there may be something wrong with my profiler (or the way I'm using it).
In addition, there is of course the question of integer overflow. Does Clipper really handle 64-bit input coordinates? If yes, then the code in this PR won't work. But in that case there should also be a test case, I think. :)