27#include <jau/test/catch2_ext.hpp>
35TEST_CASE(
"Int Math Bench 01a",
"[abs][benchmark][arithmetic][math]" ) {
36 BENCHMARK(
"jau::abs Benchmark") {
39 REQUIRE( 1_i64 ==
jau::abs( 1_i64) );
40 REQUIRE( 1_i64 ==
jau::abs(-1_i64) );
41 REQUIRE( std::numeric_limits<int64_t>::max() ==
jau::abs( std::numeric_limits<int64_t>::max() ) );
42 REQUIRE( INT32_MAX ==
jau::abs( INT32_MAX ) );
45TEST_CASE(
"Int Math Bench 01b",
"[ct_abs][benchmark][arithmetic][math]" ) {
46 BENCHMARK(
"jau::ct_abs Benchmark") {
51 REQUIRE( std::numeric_limits<int64_t>::max() ==
jau::ct_abs( std::numeric_limits<int64_t>::max() ) );
57TEST_CASE(
"Int Math Bench 01c",
"[abs][benchmark][arithmetic][math]" ) {
58 BENCHMARK(
"std::abs Benchmark") {
59 REQUIRE( 1 == std::abs( 1) );
60 REQUIRE( 1 == std::abs(-1) );
61 REQUIRE( 1_i64 == std::abs( 1_i64) );
62 REQUIRE( 1_i64 == std::abs(-1_i64) );
63 REQUIRE( std::numeric_limits<int64_t>::max() == std::abs( std::numeric_limits<int64_t>::max() ) );
64 REQUIRE( INT32_MAX == std::abs( INT32_MAX ) );
68TEST_CASE(
"Int Math Bench 02a",
"[min][max][benchmark][arithmetic][math]" ) {
69 BENCHMARK(
"MinMax Benchmark") {
70 REQUIRE( 0 ==
jau::min( 0, INT32_MAX ) );
71 REQUIRE( INT32_MAX ==
jau::max( 0, INT32_MAX ) );
72 REQUIRE( INT32_MAX-1==
jau::min( INT32_MAX-1, INT32_MAX ) );
73 REQUIRE( INT32_MAX ==
jau::max( INT32_MAX-1, INT32_MAX ) );
74 REQUIRE( INT32_MIN ==
jau::min( 0, INT32_MIN ) );
75 REQUIRE( 0 ==
jau::max( 0, INT32_MIN ) );
76 REQUIRE( INT32_MIN ==
jau::min( INT32_MIN+1, INT32_MIN ) );
77 REQUIRE( INT32_MIN+1==
jau::max( INT32_MIN+1, INT32_MIN ) );
80TEST_CASE(
"Int Math Bench 03a",
"[ct_min][ct_max][benchmark][arithmetic][math]" ) {
81 BENCHMARK(
"Min2Max2 Benchmark") {
83 REQUIRE( INT32_MAX ==
jau::ct_max( 0, INT32_MAX ) );
84 REQUIRE( INT32_MAX-1==
jau::ct_min( INT32_MAX-1, INT32_MAX ) );
85 REQUIRE( INT32_MAX ==
jau::ct_max( INT32_MAX-1, INT32_MAX ) );
86 REQUIRE( INT32_MIN+1 ==
jau::ct_min( 0, INT32_MIN+1 ) );
88 REQUIRE( INT32_MIN ==
jau::ct_min( INT32_MIN+1, INT32_MIN ) );
89 REQUIRE( INT32_MIN+1==
jau::ct_max( INT32_MIN+1, INT32_MIN ) );
98 bool __attribute__ ((noinline))
101 return hi.x >= o.lo.x &&
106 bool __attribute__ ((noinline))
109 return !(
hi.x < o.lo.x ||
114 bool __attribute__ ((noinline))
119 return lo_.
x <= hi_.
x && lo_.
y <= hi_.
y;
124 return hi.x >= o.
lo.
x &&
131 return !(
hi.x < o.
lo.
x ||
140 return lo_.
x <= hi_.
x && lo_.
y <= hi_.
y;
145 return out <<
"aabb[bl " << v.lo <<
", tr " << v.hi <<
"]";
150TEST_CASE(
"Int Math Bench 04a",
"[intersect][benchmark][arithmetic][math]" ) {
154 std::uniform_int_distribution<int32_t> rint(0,50);
156 const int loops = catch_auto_run ? 1000 : 1000000;
157 size_t isect_count=0;
158 std::vector<AABBox> va, vb;
159 for(
int i=0; i<
loops; ++i) {
160 Point2i lo(rint(rng), rint(rng));
161 Point2i hi(lo.
x+rint(rng), lo.
y+rint(rng));
163 lo =
Point2i(rint(rng), rint(rng));
164 hi =
Point2i(lo.
x+rint(rng), lo.
y+rint(rng));
168 bool i1a = a.intersects1a(b);
169 bool i1b = a.intersects1b(b);
170 bool i1c = a.intersects1c(b);
177 REQUIRE( i1a == i1b );
178 REQUIRE( i1a == i1c );
180 bool i2a = a.intersects2a(b);
181 bool i2b = a.intersects2b(b);
182 bool i2c = a.intersects2c(b);
183 REQUIRE( i1a == i2a );
184 REQUIRE( i2a == i2b );
185 REQUIRE( i2a == i2c );
187 std::cout <<
"isect_count " << isect_count <<
"/" << va.size() <<
", " << 100.0f*( (float)isect_count / (float)va.size() ) <<
"%" << std::endl;
189 BENCHMARK(
"Intersect1a Benchmark") {
191 for(
size_t i = 0; i < va.size(); ++i) {
198 BENCHMARK(
"Intersect1b Benchmark") {
200 for(
size_t i = 0; i < va.size(); ++i) {
207 BENCHMARK(
"Intersect1c Benchmark") {
209 for(
size_t i = 0; i < va.size(); ++i) {
216 BENCHMARK(
"Intersect2a Benchmark") {
218 for(
size_t i = 0; i < va.size(); ++i) {
225 BENCHMARK(
"Intersect2b Benchmark") {
227 for(
size_t i = 0; i < va.size(); ++i) {
234 BENCHMARK(
"Intersect2c Benchmark") {
236 for(
size_t i = 0; i < va.size(); ++i) {
constexpr T ct_abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/o branching) in O(1) and constant time (CT),...
constexpr T ct_max(const T x, const T y) noexcept
Returns the maximum of two integrals for MIN <= x - y <= MAX (w/o branching) in O(1) and constant tim...
constexpr T ct_min(const T x, const T y) noexcept
Returns the minimum of two integrals for MIN <= x - y <= MAX (w/o branching) in O(1) and constant tim...
std::ostream & operator<<(std::ostream &out, const cow_darray< Value_type, Size_type, Alloc_type > &c)
constexpr T min(const T x, const T y) noexcept
Returns the minimum of two integrals (w/ branching) in O(1)
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
constexpr T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
bool intersects1b(const AABBox &o) const
bool intersects2c(const AABBox &o) const
bool intersects1c(const AABBox &o) const
bool intersects2b(const AABBox &o) const
bool intersects1a(const AABBox &o) const
bool intersects2a(const AABBox &o) const
TEST_CASE("Int Math Bench 01a", "[abs][benchmark][arithmetic][math]")