File tree Expand file tree Collapse file tree 8 files changed +55
-12
lines changed
examples/google_benchmark_cmake
google_benchmark/include/benchmark Expand file tree Collapse file tree 8 files changed +55
-12
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,21 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
3
3
4
4
CODSPEED_VERSION = "1.1.1"
5
5
6
+ config_setting (
7
+ name = "windows" ,
8
+ constraint_values = ["@platforms//os:windows" ],
9
+ )
10
+
6
11
# Define the codspeed library
7
12
cc_library (
8
13
name = "codspeed" ,
9
14
srcs = glob (["src/**/*.cpp" ] + ["src/**/*.h" ]),
10
15
hdrs = glob (["include/**/*.h" ] + ["include/**/*.hpp" ]),
11
16
includes = ["include" ],
17
+ copts = select ({
18
+ ":windows" : ["/std:c++17" ],
19
+ "//conditions:default" : [],
20
+ }),
12
21
defines = [
13
22
"CODSPEED_VERSION=\\ \" {}\\ \" " .format (CODSPEED_VERSION ),
14
23
] + select ({
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ set_property(
77
77
)
78
78
79
79
if (NOT CODSPEED_MODE STREQUAL "off" )
80
- target_compile_definitions (codspeed INTERFACE -DCODSPEED_ENABLED )
80
+ target_compile_definitions (codspeed PUBLIC -DCODSPEED_ENABLED )
81
81
82
82
if (NOT CMAKE_BUILD_TYPE )
83
83
message (
@@ -95,10 +95,10 @@ if(NOT CODSPEED_MODE STREQUAL "off")
95
95
if (CODSPEED_MODE STREQUAL "instrumentation" )
96
96
target_compile_definitions (
97
97
codspeed
98
- INTERFACE -DCODSPEED_INSTRUMENTATION
98
+ PUBLIC -DCODSPEED_INSTRUMENTATION
99
99
)
100
100
elseif (CODSPEED_MODE STREQUAL "walltime" )
101
- target_compile_definitions (codspeed INTERFACE -DCODSPEED_WALLTIME )
101
+ target_compile_definitions (codspeed PUBLIC -DCODSPEED_WALLTIME )
102
102
else ()
103
103
message (
104
104
FATAL_ERROR
Original file line number Diff line number Diff line change 1
1
#ifndef CODSPEED_H
2
2
#define CODSPEED_H
3
3
4
+ #include < cstdint>
4
5
#include < string>
5
6
#include < vector>
6
7
@@ -33,7 +34,7 @@ class CodSpeed {
33
34
struct RawWalltimeBenchmark {
34
35
std::string name;
35
36
std::string uri;
36
- long iter_per_round;
37
+ uint64_t iter_per_round;
37
38
double mean_ns;
38
39
double median_ns;
39
40
double stdev_ns;
Original file line number Diff line number Diff line change 3
3
4
4
#include < string>
5
5
6
+ #ifdef CODSPEED_INSTRUMENTATION
6
7
#include " callgrind.h"
8
+ #endif
7
9
8
10
inline std::string get_version () {
9
11
#ifdef CODSPEED_VERSION
@@ -13,6 +15,7 @@ inline std::string get_version() {
13
15
#endif
14
16
}
15
17
18
+ #ifdef CODSPEED_INSTRUMENTATION
16
19
inline bool measurement_is_instrumented () { return RUNNING_ON_VALGRIND; }
17
20
18
21
inline void measurement_set_metadata () {
@@ -30,5 +33,12 @@ __attribute__((always_inline)) inline void measurement_stop(
30
33
CALLGRIND_STOP_INSTRUMENTATION;
31
34
CALLGRIND_DUMP_STATS_AT (name.c_str ());
32
35
};
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
33
43
34
44
#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) {
76
76
77
77
// Sanity check URI and add a placeholder if format is wrong
78
78
if (name.find (" ::" ) == std::string::npos) {
79
- std::string uri = " unknown_file::" + name;
79
+ uri = " unknown_file::" + name;
80
80
std::cout << " WARNING: Benchmark name does not contain '::'. Using URI: "
81
81
<< uri << std::endl;
82
82
}
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ std::string extract_lambda_namespace(const std::string &pretty_func) {
46
46
return extract_namespace_clang (pretty_func);
47
47
#elif __GNUC__
48
48
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 {};
49
53
#else
50
54
#error "Unsupported compiler"
51
55
#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)
6
6
# Treat warnings as errors
7
7
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
8
8
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
+ )
9
20
endif ()
10
21
11
22
# On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected.
12
23
set (CMAKE_BUILD_TYPE RelWithDebInfo )
13
24
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
+ )
15
32
16
33
FetchContent_Declare (
17
34
google_benchmark
Original file line number Diff line number Diff line change @@ -1459,14 +1459,16 @@ class Fixture : public internal::Benchmark {
1459
1459
#define BENCHMARK_PRIVATE_CONCAT_NAME (BaseClass, Method ) \
1460
1460
BaseClass##_##Method##_Benchmark
1461
1461
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)
1466
1465
1467
1466
#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
1470
1472
#define NAMESPACE \
1471
1473
(([]() { return codspeed::extract_lambda_namespace (__PRETTY_FUNCTION__); })())
1472
1474
#define STATIC_NAMESPACE_STRING (name ) static std::string name = NAMESPACE;
You can’t perform that action at this time.
0 commit comments