Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Throughput of rectangle overlap calculator
(version: 0)
Comparing performance of:
overlap vs clip vs intersect_2d
Created:
8 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var max = Math.max.bind(Math); var min = Math.min.bind(Math); function between(a, x, b) { return a <= x && x <= b; } function intersect_1d(start1, end1, start2, end2) { var c1 = between(start1, start2, end1) ? 1 : 0; var c2 = between(start1, end2, end1) ? 2 : 0; var c3 = between(start2, start1, end2) ? 4 : 0; var c4 = between(start2, end1, end2) ? 8 : 0; var _case = c1 | c2 | c3 | c4; switch (_case) { case 0: return [NaN, NaN]; case 1: return [start2, start2]; case 2: return [end2, end2]; case 3: return [start2, end2]; case 4: return [start1, start1]; case 5: return [min(start1, start2), max(start1, start2)]; case 6: return [min(start1, end2), max(start1, end2)]; case 7: return [min(start1, start2), max(start1, end2)]; case 8: return [end1, end1]; case 9: return [min(end1, start2), max(end1, start2)]; case 10: return [min(end1, end2), max(end1, end2)]; case 11: return [min(end1, start2), max(end1, end2)]; case 12: return [start1, end1]; case 13: return [min(start1, start2), max(end1, start2)]; case 14: return [min(start1, end2), max(end1, end2)]; case 15: return [start1, end2]; default: return [NaN, NaN]; } } function intersect_2d(A, B) { var _a = intersect_1d(A.top, A.bottom, B.top, B.bottom), top = _a[0], bottom = _a[1]; var _b = intersect_1d(A.left, A.right, B.left, B.right), left = _b[0], right = _b[1]; if (isNaN(top) || isNaN(bottom) || isNaN(left) || isNaN(right) || (top === bottom) || (left === right)) { return null; } return { left: left, top: top, right: right, bottom: bottom }; } function clip(A, B) { var rectangles = []; if (A.top < B.top) { rectangles.push({ left: A.left, top: A.top, right: A.right, bottom: B.top }); } if (A.left < B.left) { rectangles.push({ left: A.left, top: max(A.top, B.top), right: B.left, bottom: min(A.bottom, B.bottom) }); } if (A.right > B.right) { rectangles.push({ left: B.right, top: max(A.top, B.top), right: A.right, bottom: min(A.bottom, B.bottom) }); } if (A.bottom > B.bottom) { rectangles.push({ left: A.left, top: B.bottom, right: A.right, bottom: A.bottom }); } return rectangles; } function sign(owner) { return function (rect) { return ({ rect: rect, owner: owner }); }; } var sign1 = sign(1); var sign2 = sign(2); var sign3 = sign(3); function overlap(A, B) { var AB = intersect_2d(A, B); if (AB === null) { return []; } var rA = clip(A, AB).map(sign1); var rB = clip(B, AB).map(sign2); var rAB = sign3(AB); return rA.concat(rB).concat(rAB); } function randomRect() { var top = Math.random(); var left = Math.random(); var bottom = top + Math.random(); var right = left + Math.random(); return rect(top, left, bottom, right); } function rect(top, left, bottom, right) { return { left: left, top: top, right: right, bottom: bottom }; }
Tests:
overlap
overlap(randomRect(), randomRect())
clip
clip(randomRect(), randomRect())
intersect_2d
intersect_2d(randomRect(), randomRect())
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
overlap
clip
intersect_2d
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is being tested in the provided benchmark. **Benchmark Definition** The benchmark consists of three test cases: 1. `overlap(randomRect(), randomRect())`: This test case creates two random rectangles and measures the time it takes to find their overlap using the `overlap` function. 2. `clip(randomRect(), randomRect())`: This test case creates two random rectangles and measures the time it takes to clip one rectangle against another using the `clip` function. 3. `intersect_2d(randomRect(), randomRect())`: This test case creates two random rectangles and measures the time it takes to find their intersection using the `intersect_2d` function. **Options Compared** Each of these functions uses a different approach to achieve its goal: * `overlap` function: + Uses the `clip` function to create a new set of rectangles that represent the overlap between the two input rectangles. + Maps over this new set of rectangles using the `sign1`, `sign2`, and `sign3` functions, which likely perform some sort of operation on each rectangle (e.g., calculating its size or position). * `clip` function: + Uses the `intersect_2d` function to find the intersection between two input rectangles. + Clips one rectangle against another by creating a new set of rectangles that represent the area where the two original rectangles overlap. * `intersect_2d` function: + Directly calculates the intersection between two input rectangles using some sort of algorithm (likely a geometric algorithm). **Browser and Device Results** The latest benchmark results show three different browsers executing each test case at varying rates. This suggests that there may be differences in performance across different browsers or devices. * `clip` function: Chrome 64 on Mac OS X 10.12.6 executes the `clip` function approximately 245,939 times per second. * `intersect_2d` function: Chrome 64 on Mac OS X 10.12.6 executes the `intersect_2d` function approximately 197,690 times per second. * `overlap` function: Chrome 64 on Mac OS X 10.12.6 executes the `overlap` function approximately 408,781 times per second. **Conclusion** In summary, this benchmark is measuring the performance of three different functions (`clip`, `intersect_2d`, and `overlap`) that operate on random rectangles. The results suggest that there may be differences in performance across different browsers or devices. Further analysis would be needed to determine the specific reasons for these differences.
Related benchmarks:
Javascript Sorting Algorithms
Math.max/min vs if vs ternary vs bitwise & ~~ - 4 numbers
Math.max/min vs if vs ternary vs bitwise & ~~ & lodash - 5 numbers
min and max
Random Integer Generator (favors numbers closer to 0)
Comments
Confirm delete:
Do you really want to delete benchmark?