summaryrefslogtreecommitdiffstats
path: root/contrib/libs/benchmark
diff options
context:
space:
mode:
authorkungasc <[email protected]>2023-05-25 15:11:20 +0300
committerkungasc <[email protected]>2023-05-25 15:11:20 +0300
commit36161a0673e3c898b48819ba206fa38409b896f5 (patch)
treed98bcdc33efd57c970f4a4b367cb49659b874cb9 /contrib/libs/benchmark
parent1fdca17f924b7862c94f670192a3b57ac27ec215 (diff)
Add precharge benchmark
Diffstat (limited to 'contrib/libs/benchmark')
-rw-r--r--contrib/libs/benchmark/CMakeLists.darwin-x86_64.txt50
-rw-r--r--contrib/libs/benchmark/CMakeLists.linux-aarch64.txt51
-rw-r--r--contrib/libs/benchmark/CMakeLists.linux-x86_64.txt51
-rw-r--r--contrib/libs/benchmark/CMakeLists.txt17
-rw-r--r--contrib/libs/benchmark/CMakeLists.windows-x86_64.txt50
-rw-r--r--contrib/libs/benchmark/test/benchmark_gtest.cc169
-rw-r--r--contrib/libs/benchmark/test/benchmark_name_gtest.cc82
-rw-r--r--contrib/libs/benchmark/test/commandlineflags_gtest.cc228
-rw-r--r--contrib/libs/benchmark/test/statistics_gtest.cc35
-rw-r--r--contrib/libs/benchmark/test/string_util_gtest.cc152
10 files changed, 885 insertions, 0 deletions
diff --git a/contrib/libs/benchmark/CMakeLists.darwin-x86_64.txt b/contrib/libs/benchmark/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 00000000000..ccc95a4d97a
--- /dev/null
+++ b/contrib/libs/benchmark/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,50 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(contrib-libs-benchmark)
+target_compile_options(contrib-libs-benchmark PUBLIC
+ -DBENCHMARK_STATIC_DEFINE
+)
+target_compile_options(contrib-libs-benchmark PRIVATE
+ -DHAVE_POSIX_REGEX
+ -DHAVE_STD_REGEX
+ -DHAVE_STEADY_CLOCK
+ $<IF:$<CXX_COMPILER_ID:MSVC>,,-Wno-everything>
+)
+target_include_directories(contrib-libs-benchmark PUBLIC
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/include
+)
+target_include_directories(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src
+)
+target_link_libraries(contrib-libs-benchmark PUBLIC
+ contrib-libs-cxxsupp
+)
+target_sources(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_api_internal.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_name.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_register.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_runner.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/check.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/colorprint.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/commandlineflags.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/complexity.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/console_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/counter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/csv_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/json_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/perf_counters.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sleep.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/statistics.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/string_util.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sysinfo.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/timers.cc
+)
diff --git a/contrib/libs/benchmark/CMakeLists.linux-aarch64.txt b/contrib/libs/benchmark/CMakeLists.linux-aarch64.txt
new file mode 100644
index 00000000000..e341ad39afe
--- /dev/null
+++ b/contrib/libs/benchmark/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,51 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(contrib-libs-benchmark)
+target_compile_options(contrib-libs-benchmark PUBLIC
+ -DBENCHMARK_STATIC_DEFINE
+)
+target_compile_options(contrib-libs-benchmark PRIVATE
+ -DHAVE_POSIX_REGEX
+ -DHAVE_STD_REGEX
+ -DHAVE_STEADY_CLOCK
+ $<IF:$<CXX_COMPILER_ID:MSVC>,,-Wno-everything>
+)
+target_include_directories(contrib-libs-benchmark PUBLIC
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/include
+)
+target_include_directories(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src
+)
+target_link_libraries(contrib-libs-benchmark PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+)
+target_sources(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_api_internal.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_name.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_register.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_runner.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/check.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/colorprint.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/commandlineflags.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/complexity.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/console_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/counter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/csv_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/json_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/perf_counters.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sleep.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/statistics.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/string_util.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sysinfo.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/timers.cc
+)
diff --git a/contrib/libs/benchmark/CMakeLists.linux-x86_64.txt b/contrib/libs/benchmark/CMakeLists.linux-x86_64.txt
new file mode 100644
index 00000000000..e341ad39afe
--- /dev/null
+++ b/contrib/libs/benchmark/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,51 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(contrib-libs-benchmark)
+target_compile_options(contrib-libs-benchmark PUBLIC
+ -DBENCHMARK_STATIC_DEFINE
+)
+target_compile_options(contrib-libs-benchmark PRIVATE
+ -DHAVE_POSIX_REGEX
+ -DHAVE_STD_REGEX
+ -DHAVE_STEADY_CLOCK
+ $<IF:$<CXX_COMPILER_ID:MSVC>,,-Wno-everything>
+)
+target_include_directories(contrib-libs-benchmark PUBLIC
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/include
+)
+target_include_directories(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src
+)
+target_link_libraries(contrib-libs-benchmark PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+)
+target_sources(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_api_internal.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_name.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_register.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_runner.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/check.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/colorprint.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/commandlineflags.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/complexity.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/console_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/counter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/csv_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/json_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/perf_counters.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sleep.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/statistics.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/string_util.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sysinfo.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/timers.cc
+)
diff --git a/contrib/libs/benchmark/CMakeLists.txt b/contrib/libs/benchmark/CMakeLists.txt
new file mode 100644
index 00000000000..f8b31df0c11
--- /dev/null
+++ b/contrib/libs/benchmark/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/contrib/libs/benchmark/CMakeLists.windows-x86_64.txt b/contrib/libs/benchmark/CMakeLists.windows-x86_64.txt
new file mode 100644
index 00000000000..ccc95a4d97a
--- /dev/null
+++ b/contrib/libs/benchmark/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,50 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(contrib-libs-benchmark)
+target_compile_options(contrib-libs-benchmark PUBLIC
+ -DBENCHMARK_STATIC_DEFINE
+)
+target_compile_options(contrib-libs-benchmark PRIVATE
+ -DHAVE_POSIX_REGEX
+ -DHAVE_STD_REGEX
+ -DHAVE_STEADY_CLOCK
+ $<IF:$<CXX_COMPILER_ID:MSVC>,,-Wno-everything>
+)
+target_include_directories(contrib-libs-benchmark PUBLIC
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/include
+)
+target_include_directories(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src
+)
+target_link_libraries(contrib-libs-benchmark PUBLIC
+ contrib-libs-cxxsupp
+)
+target_sources(contrib-libs-benchmark PRIVATE
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_api_internal.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_name.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_register.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/benchmark_runner.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/check.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/colorprint.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/commandlineflags.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/complexity.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/console_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/counter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/csv_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/json_reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/perf_counters.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/reporter.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sleep.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/statistics.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/string_util.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/sysinfo.cc
+ ${CMAKE_SOURCE_DIR}/contrib/libs/benchmark/src/timers.cc
+)
diff --git a/contrib/libs/benchmark/test/benchmark_gtest.cc b/contrib/libs/benchmark/test/benchmark_gtest.cc
new file mode 100644
index 00000000000..2c9e555d92d
--- /dev/null
+++ b/contrib/libs/benchmark/test/benchmark_gtest.cc
@@ -0,0 +1,169 @@
+#include <map>
+#include <string>
+#include <vector>
+
+#include "../src/benchmark_register.h"
+#include "benchmark/benchmark.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace benchmark {
+namespace internal {
+
+namespace {
+
+TEST(AddRangeTest, Simple) {
+ std::vector<int> dst;
+ AddRange(&dst, 1, 2, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(1, 2));
+}
+
+TEST(AddRangeTest, Simple64) {
+ std::vector<int64_t> dst;
+ AddRange(&dst, static_cast<int64_t>(1), static_cast<int64_t>(2), 2);
+ EXPECT_THAT(dst, testing::ElementsAre(1, 2));
+}
+
+TEST(AddRangeTest, Advanced) {
+ std::vector<int> dst;
+ AddRange(&dst, 5, 15, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(5, 8, 15));
+}
+
+TEST(AddRangeTest, Advanced64) {
+ std::vector<int64_t> dst;
+ AddRange(&dst, static_cast<int64_t>(5), static_cast<int64_t>(15), 2);
+ EXPECT_THAT(dst, testing::ElementsAre(5, 8, 15));
+}
+
+TEST(AddRangeTest, FullRange8) {
+ std::vector<int8_t> dst;
+ AddRange(&dst, int8_t{1}, std::numeric_limits<int8_t>::max(), int8_t{8});
+ EXPECT_THAT(
+ dst, testing::ElementsAre(int8_t{1}, int8_t{8}, int8_t{64}, int8_t{127}));
+}
+
+TEST(AddRangeTest, FullRange64) {
+ std::vector<int64_t> dst;
+ AddRange(&dst, int64_t{1}, std::numeric_limits<int64_t>::max(), 1024);
+ EXPECT_THAT(
+ dst, testing::ElementsAre(1LL, 1024LL, 1048576LL, 1073741824LL,
+ 1099511627776LL, 1125899906842624LL,
+ 1152921504606846976LL, 9223372036854775807LL));
+}
+
+TEST(AddRangeTest, NegativeRanges) {
+ std::vector<int> dst;
+ AddRange(&dst, -8, 0, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(-8, -4, -2, -1, 0));
+}
+
+TEST(AddRangeTest, StrictlyNegative) {
+ std::vector<int> dst;
+ AddRange(&dst, -8, -1, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(-8, -4, -2, -1));
+}
+
+TEST(AddRangeTest, SymmetricNegativeRanges) {
+ std::vector<int> dst;
+ AddRange(&dst, -8, 8, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(-8, -4, -2, -1, 0, 1, 2, 4, 8));
+}
+
+TEST(AddRangeTest, SymmetricNegativeRangesOddMult) {
+ std::vector<int> dst;
+ AddRange(&dst, -30, 32, 5);
+ EXPECT_THAT(dst, testing::ElementsAre(-30, -25, -5, -1, 0, 1, 5, 25, 32));
+}
+
+TEST(AddRangeTest, NegativeRangesAsymmetric) {
+ std::vector<int> dst;
+ AddRange(&dst, -3, 5, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(-3, -2, -1, 0, 1, 2, 4, 5));
+}
+
+TEST(AddRangeTest, NegativeRangesLargeStep) {
+ // Always include -1, 0, 1 when crossing zero.
+ std::vector<int> dst;
+ AddRange(&dst, -8, 8, 10);
+ EXPECT_THAT(dst, testing::ElementsAre(-8, -1, 0, 1, 8));
+}
+
+TEST(AddRangeTest, ZeroOnlyRange) {
+ std::vector<int> dst;
+ AddRange(&dst, 0, 0, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(0));
+}
+
+TEST(AddRangeTest, ZeroStartingRange) {
+ std::vector<int> dst;
+ AddRange(&dst, 0, 2, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(0, 1, 2));
+}
+
+TEST(AddRangeTest, NegativeRange64) {
+ std::vector<int64_t> dst;
+ AddRange<int64_t>(&dst, -4, 4, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(-4, -2, -1, 0, 1, 2, 4));
+}
+
+TEST(AddRangeTest, NegativeRangePreservesExistingOrder) {
+ // If elements already exist in the range, ensure we don't change
+ // their ordering by adding negative values.
+ std::vector<int64_t> dst = {1, 2, 3};
+ AddRange<int64_t>(&dst, -2, 2, 2);
+ EXPECT_THAT(dst, testing::ElementsAre(1, 2, 3, -2, -1, 0, 1, 2));
+}
+
+TEST(AddRangeTest, FullNegativeRange64) {
+ std::vector<int64_t> dst;
+ const auto min = std::numeric_limits<int64_t>::min();
+ const auto max = std::numeric_limits<int64_t>::max();
+ AddRange(&dst, min, max, 1024);
+ EXPECT_THAT(
+ dst, testing::ElementsAreArray(std::vector<int64_t>{
+ min, -1152921504606846976LL, -1125899906842624LL,
+ -1099511627776LL, -1073741824LL, -1048576LL, -1024LL, -1LL, 0LL,
+ 1LL, 1024LL, 1048576LL, 1073741824LL, 1099511627776LL,
+ 1125899906842624LL, 1152921504606846976LL, max}));
+}
+
+TEST(AddRangeTest, Simple8) {
+ std::vector<int8_t> dst;
+ AddRange<int8_t>(&dst, int8_t{1}, int8_t{8}, int8_t{2});
+ EXPECT_THAT(dst,
+ testing::ElementsAre(int8_t{1}, int8_t{2}, int8_t{4}, int8_t{8}));
+}
+
+TEST(AddCustomContext, Simple) {
+ std::map<std::string, std::string> *&global_context = GetGlobalContext();
+ EXPECT_THAT(global_context, nullptr);
+
+ AddCustomContext("foo", "bar");
+ AddCustomContext("baz", "qux");
+
+ EXPECT_THAT(*global_context,
+ testing::UnorderedElementsAre(testing::Pair("foo", "bar"),
+ testing::Pair("baz", "qux")));
+
+ delete global_context;
+ global_context = nullptr;
+}
+
+TEST(AddCustomContext, DuplicateKey) {
+ std::map<std::string, std::string> *&global_context = GetGlobalContext();
+ EXPECT_THAT(global_context, nullptr);
+
+ AddCustomContext("foo", "bar");
+ AddCustomContext("foo", "qux");
+
+ EXPECT_THAT(*global_context,
+ testing::UnorderedElementsAre(testing::Pair("foo", "bar")));
+
+ delete global_context;
+ global_context = nullptr;
+}
+
+} // namespace
+} // namespace internal
+} // namespace benchmark
diff --git a/contrib/libs/benchmark/test/benchmark_name_gtest.cc b/contrib/libs/benchmark/test/benchmark_name_gtest.cc
new file mode 100644
index 00000000000..0a6746d04df
--- /dev/null
+++ b/contrib/libs/benchmark/test/benchmark_name_gtest.cc
@@ -0,0 +1,82 @@
+#include "benchmark/benchmark.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace benchmark;
+using namespace benchmark::internal;
+
+TEST(BenchmarkNameTest, Empty) {
+ const auto name = BenchmarkName();
+ EXPECT_EQ(name.str(), std::string());
+}
+
+TEST(BenchmarkNameTest, FunctionName) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ EXPECT_EQ(name.str(), "function_name");
+}
+
+TEST(BenchmarkNameTest, FunctionNameAndArgs) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.args = "some_args:3/4/5";
+ EXPECT_EQ(name.str(), "function_name/some_args:3/4/5");
+}
+
+TEST(BenchmarkNameTest, MinTime) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.args = "some_args:3/4";
+ name.min_time = "min_time:3.4s";
+ EXPECT_EQ(name.str(), "function_name/some_args:3/4/min_time:3.4s");
+}
+
+TEST(BenchmarkNameTest, MinWarmUpTime) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.args = "some_args:3/4";
+ name.min_warmup_time = "min_warmup_time:3.5s";
+ EXPECT_EQ(name.str(), "function_name/some_args:3/4/min_warmup_time:3.5s");
+}
+
+TEST(BenchmarkNameTest, Iterations) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.min_time = "min_time:3.4s";
+ name.iterations = "iterations:42";
+ EXPECT_EQ(name.str(), "function_name/min_time:3.4s/iterations:42");
+}
+
+TEST(BenchmarkNameTest, Repetitions) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.min_time = "min_time:3.4s";
+ name.repetitions = "repetitions:24";
+ EXPECT_EQ(name.str(), "function_name/min_time:3.4s/repetitions:24");
+}
+
+TEST(BenchmarkNameTest, TimeType) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.min_time = "min_time:3.4s";
+ name.time_type = "hammer_time";
+ EXPECT_EQ(name.str(), "function_name/min_time:3.4s/hammer_time");
+}
+
+TEST(BenchmarkNameTest, Threads) {
+ auto name = BenchmarkName();
+ name.function_name = "function_name";
+ name.min_time = "min_time:3.4s";
+ name.threads = "threads:256";
+ EXPECT_EQ(name.str(), "function_name/min_time:3.4s/threads:256");
+}
+
+TEST(BenchmarkNameTest, TestEmptyFunctionName) {
+ auto name = BenchmarkName();
+ name.args = "first:3/second:4";
+ name.threads = "threads:22";
+ EXPECT_EQ(name.str(), "first:3/second:4/threads:22");
+}
+
+} // end namespace
diff --git a/contrib/libs/benchmark/test/commandlineflags_gtest.cc b/contrib/libs/benchmark/test/commandlineflags_gtest.cc
new file mode 100644
index 00000000000..8412008ffe3
--- /dev/null
+++ b/contrib/libs/benchmark/test/commandlineflags_gtest.cc
@@ -0,0 +1,228 @@
+#include <cstdlib>
+
+#include "../src/commandlineflags.h"
+#include "../src/internal_macros.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace benchmark {
+namespace {
+
+#if defined(BENCHMARK_OS_WINDOWS)
+int setenv(const char* name, const char* value, int overwrite) {
+ if (!overwrite) {
+ // NOTE: getenv_s is far superior but not available under mingw.
+ char* env_value = getenv(name);
+ if (env_value == nullptr) {
+ return -1;
+ }
+ }
+ return _putenv_s(name, value);
+}
+
+int unsetenv(const char* name) { return _putenv_s(name, ""); }
+
+#endif // BENCHMARK_OS_WINDOWS
+
+TEST(BoolFromEnv, Default) {
+ ASSERT_EQ(unsetenv("NOT_IN_ENV"), 0);
+ EXPECT_EQ(BoolFromEnv("not_in_env", true), true);
+}
+
+TEST(BoolFromEnv, False) {
+ ASSERT_EQ(setenv("IN_ENV", "0", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "N", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "n", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "NO", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "No", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "no", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "F", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "f", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "FALSE", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "False", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "false", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "OFF", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "Off", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "off", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", true), false);
+ unsetenv("IN_ENV");
+}
+
+TEST(BoolFromEnv, True) {
+ ASSERT_EQ(setenv("IN_ENV", "1", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "Y", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "y", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "YES", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "Yes", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "yes", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "T", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "t", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "TRUE", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "True", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "true", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "ON", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "On", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+ ASSERT_EQ(setenv("IN_ENV", "on", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+
+#ifndef BENCHMARK_OS_WINDOWS
+ ASSERT_EQ(setenv("IN_ENV", "", 1), 0);
+ EXPECT_EQ(BoolFromEnv("in_env", false), true);
+ unsetenv("IN_ENV");
+#endif
+}
+
+TEST(Int32FromEnv, NotInEnv) {
+ ASSERT_EQ(unsetenv("NOT_IN_ENV"), 0);
+ EXPECT_EQ(Int32FromEnv("not_in_env", 42), 42);
+}
+
+TEST(Int32FromEnv, InvalidInteger) {
+ ASSERT_EQ(setenv("IN_ENV", "foo", 1), 0);
+ EXPECT_EQ(Int32FromEnv("in_env", 42), 42);
+ unsetenv("IN_ENV");
+}
+
+TEST(Int32FromEnv, ValidInteger) {
+ ASSERT_EQ(setenv("IN_ENV", "42", 1), 0);
+ EXPECT_EQ(Int32FromEnv("in_env", 64), 42);
+ unsetenv("IN_ENV");
+}
+
+TEST(DoubleFromEnv, NotInEnv) {
+ ASSERT_EQ(unsetenv("NOT_IN_ENV"), 0);
+ EXPECT_EQ(DoubleFromEnv("not_in_env", 0.51), 0.51);
+}
+
+TEST(DoubleFromEnv, InvalidReal) {
+ ASSERT_EQ(setenv("IN_ENV", "foo", 1), 0);
+ EXPECT_EQ(DoubleFromEnv("in_env", 0.51), 0.51);
+ unsetenv("IN_ENV");
+}
+
+TEST(DoubleFromEnv, ValidReal) {
+ ASSERT_EQ(setenv("IN_ENV", "0.51", 1), 0);
+ EXPECT_EQ(DoubleFromEnv("in_env", 0.71), 0.51);
+ unsetenv("IN_ENV");
+}
+
+TEST(StringFromEnv, Default) {
+ ASSERT_EQ(unsetenv("NOT_IN_ENV"), 0);
+ EXPECT_STREQ(StringFromEnv("not_in_env", "foo"), "foo");
+}
+
+TEST(StringFromEnv, Valid) {
+ ASSERT_EQ(setenv("IN_ENV", "foo", 1), 0);
+ EXPECT_STREQ(StringFromEnv("in_env", "bar"), "foo");
+ unsetenv("IN_ENV");
+}
+
+TEST(KvPairsFromEnv, Default) {
+ ASSERT_EQ(unsetenv("NOT_IN_ENV"), 0);
+ EXPECT_THAT(KvPairsFromEnv("not_in_env", {{"foo", "bar"}}),
+ testing::ElementsAre(testing::Pair("foo", "bar")));
+}
+
+TEST(KvPairsFromEnv, MalformedReturnsDefault) {
+ ASSERT_EQ(setenv("IN_ENV", "foo", 1), 0);
+ EXPECT_THAT(KvPairsFromEnv("in_env", {{"foo", "bar"}}),
+ testing::ElementsAre(testing::Pair("foo", "bar")));
+ unsetenv("IN_ENV");
+}
+
+TEST(KvPairsFromEnv, Single) {
+ ASSERT_EQ(setenv("IN_ENV", "foo=bar", 1), 0);
+ EXPECT_THAT(KvPairsFromEnv("in_env", {}),
+ testing::ElementsAre(testing::Pair("foo", "bar")));
+ unsetenv("IN_ENV");
+}
+
+TEST(KvPairsFromEnv, Multiple) {
+ ASSERT_EQ(setenv("IN_ENV", "foo=bar,baz=qux", 1), 0);
+ EXPECT_THAT(KvPairsFromEnv("in_env", {}),
+ testing::UnorderedElementsAre(testing::Pair("foo", "bar"),
+ testing::Pair("baz", "qux")));
+ unsetenv("IN_ENV");
+}
+
+} // namespace
+} // namespace benchmark
diff --git a/contrib/libs/benchmark/test/statistics_gtest.cc b/contrib/libs/benchmark/test/statistics_gtest.cc
new file mode 100644
index 00000000000..1de2d87d4ba
--- /dev/null
+++ b/contrib/libs/benchmark/test/statistics_gtest.cc
@@ -0,0 +1,35 @@
+//===---------------------------------------------------------------------===//
+// statistics_test - Unit tests for src/statistics.cc
+//===---------------------------------------------------------------------===//
+
+#include "../src/statistics.h"
+#include "gtest/gtest.h"
+
+namespace {
+TEST(StatisticsTest, Mean) {
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({42, 42, 42, 42}), 42.0);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1, 2, 3, 4}), 2.5);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1, 2, 5, 10, 10, 14}), 7.0);
+}
+
+TEST(StatisticsTest, Median) {
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({42, 42, 42, 42}), 42.0);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 3, 4}), 2.5);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 5, 10, 10}), 5.0);
+}
+
+TEST(StatisticsTest, StdDev) {
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({101, 101, 101, 101}), 0.0);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({1, 2, 3}), 1.0);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({2.5, 2.4, 3.3, 4.2, 5.1}),
+ 1.151086443322134);
+}
+
+TEST(StatisticsTest, CV) {
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({101, 101, 101, 101}), 0.0);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({1, 2, 3}), 1. / 2.);
+ EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({2.5, 2.4, 3.3, 4.2, 5.1}),
+ 0.32888184094918121);
+}
+
+} // end namespace
diff --git a/contrib/libs/benchmark/test/string_util_gtest.cc b/contrib/libs/benchmark/test/string_util_gtest.cc
new file mode 100644
index 00000000000..698f2d43eb8
--- /dev/null
+++ b/contrib/libs/benchmark/test/string_util_gtest.cc
@@ -0,0 +1,152 @@
+//===---------------------------------------------------------------------===//
+// statistics_test - Unit tests for src/statistics.cc
+//===---------------------------------------------------------------------===//
+
+#include "../src/internal_macros.h"
+#include "../src/string_util.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);
+} // namespace
+{
+ 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,is,more", ','),
+ std::vector<std::string>({"hello", "there", "is", "more"}));
+}
+
+} // end namespace