File tree Expand file tree Collapse file tree 7 files changed +46
-12
lines changed
examples/google_benchmark_cmake
google_benchmark/include/benchmark Expand file tree Collapse file tree 7 files changed +46
-12
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+ uint64_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,29 @@ 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+ # Set C++17 standard
11+ set (CMAKE_CXX_STANDARD 17)
12+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
13+
14+ add_compile_options (
15+ /W4
16+ /WX
17+ /wd5051 # Ignore [[maybe_unused]] C++17 warnings from Google Benchmark
18+ /wd4038 # Ignore STL <filesystem> C++17 warnings
19+ )
920endif ()
1021
1122# On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected.
1223set (CMAKE_BUILD_TYPE RelWithDebInfo)
1324
14- option (BENCHMARK_ENABLE_GTEST_TESTS OFF )
25+ # Disable Google Benchmark tests for examples
26+ set (BENCHMARK_ENABLE_GTEST_TESTS
27+ OFF
28+ CACHE BOOL
29+ "Enable testing of the benchmark library."
30+ FORCE
31+ )
1532
1633FetchContent_Declare(
1734 google_benchmark
Original file line number Diff line number Diff line change @@ -1459,14 +1459,16 @@ class Fixture : public internal::Benchmark {
14591459#define BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method ) \
14601460 BaseClass##_##Method##_Benchmark
14611461
1462- #define BENCHMARK_PRIVATE_DECLARE (n ) \
1463- /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
1464- static ::benchmark::internal::Benchmark const * const BENCHMARK_PRIVATE_NAME ( \
1465- n) [[maybe_unused]]
1462+ #define BENCHMARK_PRIVATE_DECLARE (n ) \
1463+ /* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
1464+ static ::benchmark::internal::Benchmark const * const BENCHMARK_PRIVATE_NAME (n)
14661465
14671466#ifdef CODSPEED_ENABLED
1468- #define CUR_FILE \
1469- codspeed::get_path_relative_to_workspace (__FILE__) + "::"
1467+ #define CUR_FILE codspeed::get_path_relative_to_workspace (__FILE__) + "::"
1468+ #ifdef _MSC_VER
1469+ // TODO: __PRETTY_FUNCTION__ is not available in MSVC and we dont support
1470+ #define __PRETTY_FUNCTION__ " unsupported"
1471+ #endif
14701472#define NAMESPACE \
14711473 (([]() { return codspeed::extract_lambda_namespace (__PRETTY_FUNCTION__); })())
14721474#define STATIC_NAMESPACE_STRING (name ) static std::string name = NAMESPACE;
You can’t perform that action at this time.
0 commit comments