Skip to content

Commit

Permalink
Macro PICOBENCH_NAMESPACE to define namespace. Closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB committed Feb 16, 2023
1 parent f523c7e commit 6fd5883
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
23 changes: 14 additions & 9 deletions include/picobench/picobench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// VERSION HISTORY
//
// 2.02 (2023-xx-xx) * Fixed same-func warning if user data is different
// * Macro PICOBENCH_NAMESPACE to change namespace
// * Changed marking of baseline in human-readable reports
// * Minor internal changes in strings
// 2.01 (2019-03-03) * Fixed android build when binding to a signle core
Expand Down Expand Up @@ -136,7 +137,11 @@
# define PICOBENCH_INLINE inline
#endif

namespace picobench
#if !defined(PICOBENCH_NAMESPACE)
# define PICOBENCH_NAMESPACE picobench
#endif

namespace PICOBENCH_NAMESPACE
{

#if defined(_MSC_VER) || defined(__MINGW32__) || defined(PICOBENCH_TEST)
Expand Down Expand Up @@ -326,11 +331,11 @@ class global_registry

#define PICOBENCH_SUITE(name) \
static int I_PICOBENCH_PP_CAT(picobench_suite, __LINE__) = \
picobench::global_registry::set_bench_suite(name)
PICOBENCH_NAMESPACE::global_registry::set_bench_suite(name)

#define PICOBENCH(func) \
static auto& I_PICOBENCH_PP_CAT(picobench, __LINE__) = \
picobench::global_registry::new_benchmark(#func, func)
PICOBENCH_NAMESPACE::global_registry::new_benchmark(#func, func)

#if defined(PICOBENCH_IMPLEMENT_WITH_MAIN)
# define PICOBENCH_IMPLEMENT
Expand Down Expand Up @@ -361,7 +366,7 @@ class global_registry
# endif
#endif

namespace picobench
namespace PICOBENCH_NAMESPACE
{

// namespace
Expand Down Expand Up @@ -845,13 +850,13 @@ class runner : public registry

switch (preferred_output_format())
{
case picobench::report_output_format::text:
case report_output_format::text:
report.to_text(*out);
break;
case picobench::report_output_format::concise_text:
case report_output_format::concise_text:
report.to_text_concise(*out);
break;
case picobench::report_output_format::csv:
case report_output_format::csv:
report.to_csv(*out);
break;
}
Expand Down Expand Up @@ -1425,7 +1430,7 @@ high_res_clock::time_point high_res_clock::now()
#if defined(PICOBENCH_IMPLEMENT_MAIN)
int main(int argc, char* argv[])
{
picobench::runner r;
PICOBENCH_NAMESPACE::runner r;
r.parse_cmd_line(argc, argv);
return r.run();
}
Expand All @@ -1434,7 +1439,7 @@ int main(int argc, char* argv[])
#if defined(PICOBENCH_TEST)

// fake time keeping functions for the tests
namespace picobench
namespace PICOBENCH_NAMESPACE
{
namespace test
{
Expand Down
4 changes: 2 additions & 2 deletions test/multi_cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace std;

std::map<int, int> g_num_samples;

const picobench::report::suite& find_suite(const char* s, const picobench::report& r)
const pb::report::suite& find_suite(const char* s, const pb::report& r)
{
auto suite = r.find_suite(s);
REQUIRE(suite);
Expand All @@ -20,7 +20,7 @@ const picobench::report::suite& find_suite(const char* s, const picobench::repor

TEST_CASE("[picobench] multi cpp test")
{
using namespace picobench;
using namespace pb;
runner r;

const vector<int> iters = { 100, 2000, 5000 };
Expand Down
1 change: 1 addition & 0 deletions test/multi_cpp/picobench_configured.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
#define PICOBENCH_DEBUG
#define PICOBENCH_TEST
#define PICOBENCH_STD_FUNCTION_BENCHMARKS
#define PICOBENCH_NAMESPACE pb
#include <picobench/picobench.hpp>
8 changes: 4 additions & 4 deletions test/multi_cpp/suite_a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

PICOBENCH_SUITE("suite a");

static void a_a(picobench::state& s)
static void a_a(pb::state& s)
{
for (auto _ : s)
{
picobench::test::this_thread_sleep_for_ns(10);
pb::test::this_thread_sleep_for_ns(10);
}
}
PICOBENCH(a_a);

static void a_b(picobench::state& s)
static void a_b(pb::state& s)
{
for (auto _ : s)
{
picobench::test::this_thread_sleep_for_ns(15);
pb::test::this_thread_sleep_for_ns(15);
}
}
PICOBENCH(a_b);
10 changes: 5 additions & 5 deletions test/multi_cpp/suite_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

PICOBENCH_SUITE("suite b");

static void a_a(picobench::state& s)
static void a_a(pb::state& s)
{
for (auto _ : s)
{
picobench::test::this_thread_sleep_for_ns(15);
pb::test::this_thread_sleep_for_ns(15);
}
}
PICOBENCH(a_a);

static void a_b(size_t stime, picobench::state& s)
static void a_b(size_t stime, pb::state& s)
{
s.start_timer();
picobench::test::this_thread_sleep_for_ns(s.iterations() * size_t(stime));
pb::test::this_thread_sleep_for_ns(s.iterations() * size_t(stime));
s.stop_timer();
}
PICOBENCH([](picobench::state& s) { a_b(30, s); }).label("a_b").baseline();
PICOBENCH([](pb::state& s) { a_b(30, s); }).label("a_b").baseline();
8 changes: 4 additions & 4 deletions test/multi_cpp/suite_b_cont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ extern std::map<int, int> g_num_samples;

PICOBENCH_SUITE("suite b");

static void b_a(picobench::state& s)
static void b_a(pb::state& s)
{
++g_num_samples[s.iterations()];
for (auto _ : s)
{
picobench::test::this_thread_sleep_for_ns(20);
pb::test::this_thread_sleep_for_ns(20);
}
}
PICOBENCH(b_a);

static void b_b(picobench::state& s)
static void b_b(pb::state& s)
{
s.start_timer();
picobench::test::this_thread_sleep_for_ns(s.iterations() * size_t(25));
pb::test::this_thread_sleep_for_ns(s.iterations() * size_t(25));
s.stop_timer();
}
PICOBENCH(b_b);

0 comments on commit 6fd5883

Please sign in to comment.