File tree Expand file tree Collapse file tree 7 files changed +39
-6
lines changed
examples/google_benchmark_cmake
google_benchmark/include/benchmark Expand file tree Collapse file tree 7 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ set_property(
7777)
7878
7979if (NOT CODSPEED_MODE STREQUAL "off" )
80- target_compile_definitions (codspeed INTERFACE -DCODSPEED_ENABLED)
80+ target_compile_definitions (codspeed PUBLIC -DCODSPEED_ENABLED)
8181
8282 if (NOT CMAKE_BUILD_TYPE )
8383 message (
@@ -95,10 +95,10 @@ if(NOT CODSPEED_MODE STREQUAL "off")
9595 if (CODSPEED_MODE STREQUAL "instrumentation" )
9696 target_compile_definitions (
9797 codspeed
98- INTERFACE -DCODSPEED_INSTRUMENTATION
98+ PUBLIC -DCODSPEED_INSTRUMENTATION
9999 )
100100 elseif (CODSPEED_MODE STREQUAL "walltime" )
101- target_compile_definitions (codspeed INTERFACE -DCODSPEED_WALLTIME)
101+ target_compile_definitions (codspeed PUBLIC -DCODSPEED_WALLTIME)
102102 else ()
103103 message (
104104 FATAL_ERROR
Original file line number Diff line number Diff line change 11#ifndef CODSPEED_H
22#define CODSPEED_H
33
4+ #include < cstdint>
45#include < string>
56#include < vector>
67
@@ -33,7 +34,7 @@ class CodSpeed {
3334struct RawWalltimeBenchmark {
3435 std::string name;
3536 std::string uri;
36- long iter_per_round;
37+ int64_t iter_per_round;
3738 double mean_ns;
3839 double median_ns;
3940 double stdev_ns;
Original file line number Diff line number Diff line change 33
44#include < string>
55
6+ #ifdef CODSPEED_INSTRUMENTATION
67#include " callgrind.h"
8+ #endif
79
810inline std::string get_version () {
911#ifdef CODSPEED_VERSION
@@ -13,6 +15,7 @@ inline std::string get_version() {
1315#endif
1416}
1517
18+ #ifdef CODSPEED_INSTRUMENTATION
1619inline bool measurement_is_instrumented () { return RUNNING_ON_VALGRIND; }
1720
1821inline void measurement_set_metadata () {
@@ -30,5 +33,12 @@ __attribute__((always_inline)) inline void measurement_stop(
3033 CALLGRIND_STOP_INSTRUMENTATION;
3134 CALLGRIND_DUMP_STATS_AT (name.c_str ());
3235};
36+ #else
37+ // Stub implementations for non-instrumentation builds
38+ inline bool measurement_is_instrumented () { return false ; }
39+ inline void measurement_set_metadata () {}
40+ inline void measurement_start () {}
41+ inline void measurement_stop (const std::string &name) { (void )name; }
42+ #endif
3343
3444#endif // MEASUREMENT_H
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ void CodSpeed::start_benchmark(const std::string &name) {
7676
7777 // Sanity check URI and add a placeholder if format is wrong
7878 if (name.find (" ::" ) == std::string::npos) {
79- std::string uri = " unknown_file::" + name;
79+ uri = " unknown_file::" + name;
8080 std::cout << " WARNING: Benchmark name does not contain '::'. Using URI: "
8181 << uri << std::endl;
8282 }
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ std::string extract_lambda_namespace(const std::string &pretty_func) {
4646 return extract_namespace_clang (pretty_func);
4747#elif __GNUC__
4848 return extract_namespace_gcc (pretty_func);
49+ #elif _MSC_VER
50+ // MSVC doesn't support __PRETTY_FUNCTION__ in the same way
51+ // Return empty string as fallback for Windows
52+ return {};
4953#else
5054#error "Unsupported compiler"
5155#endif
Original file line number Diff line number Diff line change @@ -6,12 +6,19 @@ project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)
66# Treat warnings as errors
77if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
88 add_compile_options (-Wall -Wextra -Werror)
9+ elseif (MSVC )
10+ add_compile_options (/W4 /WX
11+ /wd5051 # Ignore [[maybe_unused]] C++17 warnings from Google Benchmark
12+ /wd4038 # Ignore STL <filesystem> C++17 warnings
13+ )
914endif ()
1015
1116# On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected.
1217set (CMAKE_BUILD_TYPE RelWithDebInfo)
1318
14- option (BENCHMARK_ENABLE_GTEST_TESTS OFF )
19+ # Disable Google Benchmark tests
20+ set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)
21+ set (BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)
1522
1623FetchContent_Declare(
1724 google_benchmark
Original file line number Diff line number Diff line change @@ -1459,16 +1459,27 @@ class Fixture : public internal::Benchmark {
14591459#define BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method ) \
14601460 BaseClass##_##Method##_Benchmark
14611461
1462+ #ifdef _MSC_VER
1463+ #define BENCHMARK_PRIVATE_DECLARE (n ) \
1464+ /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
1465+ static ::benchmark::internal::Benchmark const * const BENCHMARK_PRIVATE_NAME ( \
1466+ n)
1467+ #else
14621468#define BENCHMARK_PRIVATE_DECLARE (n ) \
14631469 /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
14641470 static ::benchmark::internal::Benchmark const * const BENCHMARK_PRIVATE_NAME ( \
14651471 n) [[maybe_unused]]
1472+ #endif
14661473
14671474#ifdef CODSPEED_ENABLED
14681475#define CUR_FILE \
14691476 codspeed::get_path_relative_to_workspace (__FILE__) + "::"
1477+ #ifdef _MSC_VER
1478+ #define NAMESPACE std::string (" " )
1479+ #else
14701480#define NAMESPACE \
14711481 (([]() { return codspeed::extract_lambda_namespace (__PRETTY_FUNCTION__); })())
1482+ #endif
14721483#define STATIC_NAMESPACE_STRING (name ) static std::string name = NAMESPACE;
14731484
14741485#define FILE_AND_NAMESPACE CUR_FILE + NAMESPACE
You can’t perform that action at this time.
0 commit comments