Skip to content

Commit

Permalink
rename bsearch_adaptor to BSearchAdaptor; add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
luk036 committed Apr 28, 2023
1 parent 4ac7e74 commit 1344049
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option(INSTALL_ONLY "Enable for installation only" OFF)
# Note: update this to your new project's name and version
project(
EllAlgo
VERSION 1.4.2
VERSION 1.4.3
LANGUAGES CXX
)

Expand Down Expand Up @@ -87,7 +87,7 @@ packageProject(

if(NOT INSTALL_ONLY)
add_subdirectory(test)
# add_subdirectory(bench)
add_subdirectory(bench)
add_subdirectory(standalone)
add_subdirectory(documentation)
endif()
File renamed without changes.
62 changes: 62 additions & 0 deletions bench/BM_stable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Distributed under the MIT License (See accompanying file /LICENSE )
*/
#include "benchmark/benchmark.h" // for BENCHMARK, State, BENCHMARK_...

#include <ellalgo/cutting_plane.hpp> // for cutting_plane_optim, cutti...
#include <ellalgo/ell.hpp> // for Ell
#include <ellalgo/ell_config.hpp> // for CInfo
#include <ellalgo/ell_stable.hpp> // for EllStable
#include <ellalgo/oracles/profit_oracle.hpp> // for ProfitOracle, profit_r...

#include <cmath> // for log
#include <tuple> // for get
#include <type_traits> // for move, remove_reference<...

static void bm_ell_normal(benchmark::State &state) {
// using Arr = xt::xarray<double, xt::layout_type::row_major>;
using Vec = std::valarray<double>;

const auto p = 20.0;
const auto A = 40.0;
const auto k = 30.5;
const auto a = Vec{0.1, 0.4};
const auto v = Vec{10.0, 35.0};

// Code inside this loop is measured repeatedly
for (auto _ : state) {
Ell<Vec> ellip{100.0, Vec{0.0, 0.0}};
ProfitOracle omega{p, A, k, a, v};

auto result = cutting_plane_optim(std::move(omega), std::move(ellip), 0.0);
// CHECK_EQ(num_iters, 36);
benchmark::DoNotOptimize(result);
}
}
// Register the function as a benchmark
BENCHMARK(bm_ell_normal);

static void bm_ell_stable(benchmark::State &state) {
// using Arr = xt::xarray<double, xt::layout_type::row_major>;
using Vec = std::valarray<double>;

const auto p = 20.0;
const auto A = 40.0;
const auto k = 30.5;
const auto a = Vec{0.1, 0.4};
const auto v = Vec{10.0, 35.0};

// Code inside this loop is measured repeatedly
for (auto _ : state) {
EllStable<Vec> ellip{100.0, Vec{0.0, 0.0}};
ProfitOracle omega{p, A, k, a, v};

auto result = cutting_plane_optim(std::move(omega), std::move(ellip), 0.0);
// CHECK_EQ(num_iters, 41);
benchmark::DoNotOptimize(result);
}
}
// Register the function as a benchmark
BENCHMARK(bm_ell_stable);

BENCHMARK_MAIN();
8 changes: 4 additions & 4 deletions include/ellalgo/cutting_plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ inline auto bsearch(Oracle &&omega, const std::pair<T, T> &intvl,
* @tparam Space
*/
template <typename Oracle, typename Space> //
class bsearch_adaptor {
class BSearchAdaptor {
using ArrayType = typename Space::ArrayType;

private:
Expand All @@ -212,8 +212,8 @@ class bsearch_adaptor {
* @param[in,out] omega perform assessment on x0
* @param[in,out] space search Space containing x*
*/
bsearch_adaptor(Oracle &omega, Space &space)
: bsearch_adaptor{omega, space, Options()} {}
BSearchAdaptor(Oracle &omega, Space &space)
: BSearchAdaptor{omega, space, Options()} {}

/**
* @brief Construct a new bsearch adaptor object
Expand All @@ -222,7 +222,7 @@ class bsearch_adaptor {
* @param[in,out] space search space containing x*
* @param[in] options maximum iteration and error tolerance etc.
*/
bsearch_adaptor(Oracle &omega, Space &space, const Options &options)
BSearchAdaptor(Oracle &omega, Space &space, const Options &options)
: _omega{omega}, _space{space}, _options{options} {}

/**
Expand Down
8 changes: 8 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_rules("mode.debug", "mode.release", "mode.coverage")
add_requires("fmt", {alias = "fmt"})
add_requires("doctest", {alias = "doctest"})
add_requires("benchmark", {alias = "benchmark"})
-- add_requires("microsoft-gsl 3.1", {alias = "ms-gsl"})
-- add_requires("range-v3", {alias = "range-v3"})
-- add_requires("conan::range-v3/0.11.0", {alias = "range-v3"})
Expand Down Expand Up @@ -32,6 +33,13 @@ target("test_ellalgo")
add_files("test/source/*.cpp")
add_packages("fmt", "doctest", "range-v3")

target("test_stable")
set_kind("binary")
add_deps("EllAlgo")
add_includedirs("include", {public = true})
add_files("bench/*.cpp")
add_packages("benchmark")

--
-- If you want to known more usage about xmake, please see https://xmake.io
--
Expand Down

0 comments on commit 1344049

Please sign in to comment.