Skip to content

Commit

Permalink
Initial testing for the memory cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Biscani authored and Francesco Biscani committed Aug 20, 2023
1 parent 361fd7b commit b2913e5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ ADD_HEYOKA_TESTCASE(model_fixed_centres)
ADD_HEYOKA_TESTCASE(model_rotating)
ADD_HEYOKA_TESTCASE(model_mascon)
ADD_HEYOKA_TESTCASE(step_callback)
ADD_HEYOKA_TESTCASE(llvm_state_mem_cache)

if(HEYOKA_WITH_MPPP AND mp++_WITH_MPFR)
ADD_HEYOKA_TESTCASE(event_detection_mp)
Expand Down
55 changes: 55 additions & 0 deletions test/llvm_state_mem_cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2020, 2021, 2022, 2023 Francesco Biscani ([email protected]), Dario Izzo ([email protected])
//
// This file is part of the heyoka library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <heyoka/llvm_state.hpp>
#include <heyoka/model/pendulum.hpp>
#include <heyoka/taylor.hpp>

#include "catch.hpp"

using namespace heyoka;

TEST_CASE("basic")
{
REQUIRE(llvm_state::get_memcache_size() == 0u);
REQUIRE(llvm_state::get_memcache_limit() > 0u);

auto ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}};

auto cache_size = llvm_state::get_memcache_size();
REQUIRE(cache_size > 0u);

ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}};

REQUIRE(llvm_state::get_memcache_size() == cache_size);

ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}, kw::opt_level = 2u};

REQUIRE(llvm_state::get_memcache_size() > cache_size);
cache_size = llvm_state::get_memcache_size();

ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}, kw::opt_level = 2u, kw::tol = 1e-12};
REQUIRE(llvm_state::get_memcache_size() > cache_size);

llvm_state::clear_memcache();
REQUIRE(llvm_state::get_memcache_size() == 0u);

ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}};
cache_size = llvm_state::get_memcache_size();

llvm_state::set_memcache_limit(cache_size);
ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}, kw::tol = 1e-12};

REQUIRE(llvm_state::get_memcache_size() < cache_size);

llvm_state::set_memcache_limit(0);

ta = taylor_adaptive<double>{model::pendulum(), {1., 0.}, kw::tol = 1e-11};

REQUIRE(llvm_state::get_memcache_size() == 0u);
}

0 comments on commit b2913e5

Please sign in to comment.