Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/include/nanobench.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@
// See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58265
#define ANKERL_NANOBENCH_PRIVATE_NOEXCEPT_STRING_MOVE() std::is_nothrow_move_assignable<std::string>::value

#if __cpp_exceptions || _HAS_EXCEPTIONS
# define ANKERL_NANOBENCH_THROW(...) throw __VA_ARGS__
#elif defined(_MSC_VER)
# define ANKERL_NANOBENCH_THROW(...) (_invoke_watson(nullptr, nullptr, nullptr, 0, 0))
#else
# define ANKERL_NANOBENCH_THROW(...) (__builtin_abort())
#endif

#if defined(_CPPRTTI) || defined(__GXX_RTTI)
# define ANKERL_NANOBENCH_HAS_RTTI 1
#else
# define ANKERL_NANOBENCH_HAS_RTTI 0
#endif

// declarations ///////////////////////////////////////////////////////////////////////////////////

namespace ankerl {
Expand Down Expand Up @@ -1712,7 +1726,7 @@ static std::ostream& generateResultTag(Node const& n, Result const& r, std::ostr
// static std::regex const regOpArg2("^([a-zA-Z]+)\\(([a-zA-Z]*)\\s*,\\s+([a-zA-Z]*)\\)$");

// nothing matches :(
throw std::runtime_error("command '" + std::string(n.begin, n.end) + "' not understood");
ANKERL_NANOBENCH_THROW(std::runtime_error("command '" + std::string(n.begin, n.end) + "' not understood"));
}

static void generateResultMeasurement(std::vector<Node> const& nodes, size_t idx, Result const& r, std::ostream& out) {
Expand All @@ -1725,10 +1739,10 @@ static void generateResultMeasurement(std::vector<Node> const& nodes, size_t idx
break;

case Node::Type::inverted_section:
throw std::runtime_error("got a inverted section inside measurement");
ANKERL_NANOBENCH_THROW(std::runtime_error("got a inverted section inside measurement"));

case Node::Type::section:
throw std::runtime_error("got a section inside measurement");
ANKERL_NANOBENCH_THROW(std::runtime_error("got a section inside measurement"));

case Node::Type::tag: {
auto m = Result::fromString(std::string(n.begin, n.end));
Expand All @@ -1755,15 +1769,15 @@ static void generateResult(std::vector<Node> const& nodes, size_t idx, std::vect
break;

case Node::Type::inverted_section:
throw std::runtime_error("got a inverted section inside result");
ANKERL_NANOBENCH_THROW(std::runtime_error("got a inverted section inside result"));

case Node::Type::section:
if (n == "measurement") {
for (size_t i = 0; i < r.size(); ++i) {
generateResultMeasurement(n.children, i, r, out);
}
} else {
throw std::runtime_error("got a section inside result");
ANKERL_NANOBENCH_THROW(std::runtime_error("got a section inside result"));
}
break;

Expand Down Expand Up @@ -1914,7 +1928,7 @@ void render(char const* mustacheTemplate, std::vector<Result> const& results, st
break;

case templates::Node::Type::inverted_section:
throw std::runtime_error("unknown list '" + std::string(n.begin, n.end) + "'");
ANKERL_NANOBENCH_THROW(std::runtime_error("unknown list '" + std::string(n.begin, n.end) + "'"));

case templates::Node::Type::section:
if (n == "result") {
Expand All @@ -1924,17 +1938,17 @@ void render(char const* mustacheTemplate, std::vector<Result> const& results, st
}
} else if (n == "measurement") {
if (results.size() != 1) {
throw std::runtime_error(
ANKERL_NANOBENCH_THROW(std::runtime_error(
"render: can only use section 'measurement' here if there is a single result, but there are " +
detail::fmt::to_s(results.size()));
detail::fmt::to_s(results.size())));
}
// when we only have a single result, we can immediately go into its measurement.
auto const& r = results.front();
for (size_t i = 0; i < r.size(); ++i) {
generateResultMeasurement(n.children, i, r, out);
}
} else {
throw std::runtime_error("render: unknown section '" + std::string(n.begin, n.end) + "'");
ANKERL_NANOBENCH_THROW(std::runtime_error("render: unknown section '" + std::string(n.begin, n.end) + "'"));
}
break;

Expand All @@ -1945,7 +1959,7 @@ void render(char const* mustacheTemplate, std::vector<Result> const& results, st
} else {
// This just uses the last result's config.
if (!generateConfigTag(n, results.back().config(), out)) {
throw std::runtime_error("unknown tag '" + std::string(n.begin, n.end) + "'");
ANKERL_NANOBENCH_THROW(std::runtime_error("unknown tag '" + std::string(n.begin, n.end) + "'"));
}
}
break;
Expand Down Expand Up @@ -2812,7 +2826,9 @@ Number::Number(int width, int precision, double value)

std::ostream& Number::write(std::ostream& os) const {
StreamStateRestorer const restorer(os);
#if ANKERL_NANOBENCH_HAS_RTTI
os.imbue(std::locale(os.getloc(), new NumSep(',')));
#endif
os << std::setw(mWidth) << std::setprecision(mPrecision) << std::fixed << mValue;
return os;
}
Expand Down Expand Up @@ -3390,8 +3406,8 @@ Rng::Rng(std::vector<uint64_t> const& data)
: mX(0)
, mY(0) {
if (data.size() != 2) {
throw std::runtime_error("ankerl::nanobench::Rng::Rng: needed exactly 2 entries in data, but got " +
detail::fmt::to_s(data.size()));
ANKERL_NANOBENCH_THROW(std::runtime_error("ankerl::nanobench::Rng::Rng: needed exactly 2 entries in data, but got " +
detail::fmt::to_s(data.size())));
}
mX = data[0];
mY = data[1];
Expand Down