diff --git a/Makefile b/Makefile index 32bf5e0..9b79ffe 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CXX= clang++-10 -CXXFLAGS= --std=c++17 -O0 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -pedantic -Werror \ +CXXFLAGS= --std=c++17 -O3 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic -Werror \ -Wno-unknown-attributes -frtti \ -g -fprofile-instr-generate -fcoverage-mapping \ -fsanitize=address -fno-omit-frame-pointer diff --git a/include/gp/flat_tree.hpp b/include/gp/flat_tree.hpp index 2ddbc37..d5b5dd0 100644 --- a/include/gp/flat_tree.hpp +++ b/include/gp/flat_tree.hpp @@ -6,6 +6,6 @@ template class flat_tree { - gp::array data_; + gp::array data_; }; diff --git a/include/gp/ring_list.hpp b/include/gp/ring_list.hpp index 3c62204..f350061 100644 --- a/include/gp/ring_list.hpp +++ b/include/gp/ring_list.hpp @@ -131,8 +131,8 @@ namespace gp { } void remove(explorer& value) { - auto& v = *value; - if(v == explore()) { + auto v = value.pos; + if(v == any_node) { if(v->next == v) { any_node = nullptr; } else { @@ -142,10 +142,10 @@ namespace gp { stitch_around(value.pos); } allocator& used_allocator = alloc; - v.value->~T(); - gp_config::assertion(used_allocator.deallocate(v.value), "Bad free of value"); - value.pos->~node(); - gp_config::assertion(used_allocator.deallocate(value.pos), "Bad free of node"); + v->value->~T(); + gp_config::assertion(used_allocator.deallocate(v->value), "Bad free of value"); + v->~node(); + gp_config::assertion(used_allocator.deallocate(v), "Bad free of node"); } }; } diff --git a/tests/gp_test.cpp b/tests/gp_test.cpp index 0d8d71c..e949246 100644 --- a/tests/gp_test.cpp +++ b/tests/gp_test.cpp @@ -316,16 +316,17 @@ struct buddy_fuzz_test : public test_scaffold { } auto reference = std::chrono::steady_clock::now() - start; - - std::cout - << "Fuzzing timed at " - << std::chrono::duration_cast(duration).count() - << "µs for " - << FUZZ_STRENGTH - << " (reference: " - << std::chrono::duration_cast(reference).count() - << "µs)" - << std::endl; + if(do_bench){ + std::cout + << "Fuzzing timed at " + << std::chrono::duration_cast(duration).count() + << "µs for " + << FUZZ_STRENGTH + << " (reference: " + << std::chrono::duration_cast(reference).count() + << "µs)" + << std::endl; + } return res; } @@ -688,3 +689,63 @@ struct endian_test : public test_scaffold { }; append_test dummy_45zelotf5f5(new endian_test{}); + +struct alloc_bench_test : public test_scaffold { + alloc_bench_test() { + name = __FILE__ ":12"; + } + + virtual int run() { + int res = 0; + auto store = std::make_unique>(); + using buddy_loc = gp::buddy<>; + using arena_loc = gp::arena<>; + buddy_loc bud{&*store->begin(), store->size()}; + arena_loc are{&*store->begin(), store->size()}; + + + for(size_t divider = 2; divider < 32; ++divider) + { + gp::ring_list a{bud}; + gp::ring_list b{are}; + + std::cout << + "ARE | " << "INS | " << divider << " | " << + time_operation([&](){ + for(size_t i = 0; i < store->size()/sizeof(gp::ring_list::node)/divider; i++) { + b.insert(i); + } + }).count() << std::endl; + + std::cout << + "ARE | " << "DEL | " << divider << " | " << + time_operation([&](){ + for(size_t i = 0; i < store->size()/sizeof(gp::ring_list::node)/divider; i++) { + gp::ring_list::explorer e = b.explore(); + b.remove(e); + } + }).count() << std::endl; + + std::cout << + "BUD | " << "INS | " << divider << " | " << + time_operation([&](){ + for(size_t i = 0; i < store->size()/sizeof(gp::ring_list::node)/divider; i++) { + a.insert(i); + } + }).count() << std::endl; + + std::cout << + "BUD | " << "DEL | " << divider << " | " << + time_operation([&](){ + for(size_t i = 0; i < store->size()/sizeof(gp::ring_list::node)/divider; i++) { + gp::ring_list::explorer e = a.explore(); + a.remove(e); + } + }).count() << std::endl; + } + + return res; + } +}; + +append_test dummy_jhgspo5d5(new alloc_bench_test{}); \ No newline at end of file diff --git a/tests/math.cpp b/tests/math.cpp index b6c1a09..ab3175d 100644 --- a/tests/math.cpp +++ b/tests/math.cpp @@ -28,6 +28,11 @@ struct sin_test : public test_scaffold { float ref = cos(i); res += 0.3 < gp::abs(ref - v)*100.0/(gp::abs(ref+0.00000001)); } + for(float i = 0; i < 100; i += 0.1) { + float v = gp::cos(i)*gp::cos(i) + gp::sin(i)*gp::sin(i); + res += 1 + gp_config::rendering::epsilon < v; + res += 1 - gp_config::rendering::epsilon > v; + } return res; } diff --git a/tests/test_scaffold.h b/tests/test_scaffold.h index db8a64e..1fc68ef 100644 --- a/tests/test_scaffold.h +++ b/tests/test_scaffold.h @@ -2,6 +2,21 @@ #include #include #include +#include + +#ifndef NO_BENCH +#define NO_BENCH 1 +#endif + +constexpr bool do_bench = 1 - NO_BENCH; + +template +std::chrono::microseconds time_operation(fn op) { + auto start = std::chrono::high_resolution_clock::now(); + op(); + auto time = std::chrono::high_resolution_clock::now() - start; + return std::chrono::duration_cast(time); +} struct test_scaffold{ std::string name;