mirror of
https://github.com/google/benchmark.git
synced 2024-12-28 21:40:15 +08:00
376ebc2635
* Support optional, user-directed collection of performance counters The patch allows an engineer wishing to drill into the root causes of a regression, for example. Currently, only single threaded runs are supported. The feature is a build-time opt in, and then a runtime opt in. The engineer may run the benchmark executable, passing a list of performance counter names (using libpfm's naming scheme) at the command line. The counter values will then be collected and reported back as UserCounters. This is different from #240 in that it is a benchmark user opt-in, and the counter collection is transparent to the benchmark. Currently, this is only supported on platforms where libpfm is supported. libpfm: http://perfmon2.sourceforge.net/ * 'Use' values param in Snapshot when BENCHMARK_OS_WINDOWS This is to avoid unused parameter warning-as-error * Added missing include for <vector> in perf_counters.cc * Moved doc to docs * Added license blurbs
162 lines
3.7 KiB
C++
162 lines
3.7 KiB
C++
//===---------------------------------------------------------------------===//
|
|
// statistics_test - Unit tests for src/statistics.cc
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
#include "../src/string_util.h"
|
|
#include "../src/internal_macros.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace {
|
|
TEST(StringUtilTest, stoul) {
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0ul, benchmark::stoul("0", &pos));
|
|
EXPECT_EQ(1ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(7ul, benchmark::stoul("7", &pos));
|
|
EXPECT_EQ(1ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(135ul, benchmark::stoul("135", &pos));
|
|
EXPECT_EQ(3ul, pos);
|
|
}
|
|
#if ULONG_MAX == 0xFFFFFFFFul
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0xFFFFFFFFul, benchmark::stoul("4294967295", &pos));
|
|
EXPECT_EQ(10ul, pos);
|
|
}
|
|
#elif ULONG_MAX == 0xFFFFFFFFFFFFFFFFul
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0xFFFFFFFFFFFFFFFFul, benchmark::stoul("18446744073709551615", &pos));
|
|
EXPECT_EQ(20ul, pos);
|
|
}
|
|
#endif
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(10ul, benchmark::stoul("1010", &pos, 2));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(520ul, benchmark::stoul("1010", &pos, 8));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(1010ul, benchmark::stoul("1010", &pos, 10));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(4112ul, benchmark::stoul("1010", &pos, 16));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0xBEEFul, benchmark::stoul("BEEF", &pos, 16));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
|
|
{
|
|
ASSERT_THROW(benchmark::stoul("this is a test"), std::invalid_argument);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
TEST(StringUtilTest, stoi) {
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0, benchmark::stoi("0", &pos));
|
|
EXPECT_EQ(1ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(-17, benchmark::stoi("-17", &pos));
|
|
EXPECT_EQ(3ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(1357, benchmark::stoi("1357", &pos));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(10, benchmark::stoi("1010", &pos, 2));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(520, benchmark::stoi("1010", &pos, 8));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(1010, benchmark::stoi("1010", &pos, 10));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(4112, benchmark::stoi("1010", &pos, 16));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0xBEEF, benchmark::stoi("BEEF", &pos, 16));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
|
|
{
|
|
ASSERT_THROW(benchmark::stoi("this is a test"), std::invalid_argument);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
TEST(StringUtilTest, stod) {
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(0.0, benchmark::stod("0", &pos));
|
|
EXPECT_EQ(1ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(-84.0, benchmark::stod("-84", &pos));
|
|
EXPECT_EQ(3ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(1234.0, benchmark::stod("1234", &pos));
|
|
EXPECT_EQ(4ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
EXPECT_EQ(1.5, benchmark::stod("1.5", &pos));
|
|
EXPECT_EQ(3ul, pos);
|
|
}
|
|
{
|
|
size_t pos = 0;
|
|
/* Note: exactly representable as double */
|
|
EXPECT_EQ(-1.25e+9, benchmark::stod("-1.25e+9", &pos));
|
|
EXPECT_EQ(8ul, pos);
|
|
}
|
|
#ifndef BENCHMARK_HAS_NO_EXCEPTIONS
|
|
{
|
|
ASSERT_THROW(benchmark::stod("this is a test"), std::invalid_argument);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
TEST(StringUtilTest, StrSplit) {
|
|
EXPECT_EQ(benchmark::StrSplit("", ','), std::vector<std::string>{""});
|
|
EXPECT_EQ(benchmark::StrSplit("hello", ','),
|
|
std::vector<std::string>({"hello"}));
|
|
EXPECT_EQ(benchmark::StrSplit("hello,there", ','),
|
|
std::vector<std::string>({"hello", "there"}));
|
|
}
|
|
|
|
} // end namespace
|