Skip to content

Commit 3812785

Browse files
committed
feat: initial commit
0 parents  commit 3812785

File tree

11 files changed

+211
-0
lines changed

11 files changed

+211
-0
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
build/

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cmake.sourceDirectory": "/workspaces/codspeed-cpp/picobench"
3+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# codspeed-cpp

google_benchmark/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
include(FetchContent)
3+
4+
project(codspeed_google_benchmark_compat VERSION 0.0.0 LANGUAGES CXX)
5+
6+
FetchContent_Declare(
7+
google_benchmark
8+
GIT_REPOSITORY https://github.com/google/benchmark.git
9+
GIT_TAG 12235e24652fc7f809373e7c11a5f73c5763fc4c # v1.9.0
10+
)
11+
FetchContent_MakeAvailable(google_benchmark)
12+
13+
add_library(codspeed_picobench_compat)
14+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
macro(pb_example name)
2+
set(tgt picobench-example-${name})
3+
add_executable(${tgt} ${ARGN})
4+
target_link_libraries(${tgt} codspeed_picobench_compat)
5+
set_target_properties(${tgt} PROPERTIES FOLDER example)
6+
add_custom_target(
7+
picobench-run-example-${name}
8+
COMMAND ${tgt}
9+
)
10+
endmacro()
11+
12+
pb_example(basic basic.cpp)

google_benchmark/examples/basic.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define PICOBENCH_DEBUG
2+
#define PICOBENCH_IMPLEMENT_WITH_MAIN
3+
#include "codspeed_picobench_compat/picobench.hpp"
4+
5+
#include <vector>
6+
#include <deque>
7+
#include <cstdlib>
8+
9+
void rand_vector(picobench::state& s)
10+
{
11+
std::vector<int> v;
12+
for (auto _ : s)
13+
{
14+
v.push_back(rand());
15+
}
16+
}
17+
PICOBENCH(rand_vector);
18+
19+
void rand_vector_reserve(picobench::state& s)
20+
{
21+
std::vector<int> v;
22+
v.reserve(s.iterations());
23+
for (auto _ : s)
24+
{
25+
v.push_back(rand());
26+
}
27+
}
28+
PICOBENCH(rand_vector_reserve);
29+
30+
void rand_deque(picobench::state& s)
31+
{
32+
std::deque<int> v;
33+
for (auto _ : s)
34+
{
35+
v.push_back(rand());
36+
}
37+
}
38+
PICOBENCH(rand_deque);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
2+
#define CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
3+
4+
#include "picobench/picobench.hpp"
5+
#include <iostream>
6+
7+
// Undefine the original PICOBENCH macro
8+
// #undef PICOBENCH
9+
10+
// Define a new PICOBENCH macro that wraps the original functionality
11+
#define PICOBENCH2(func) \
12+
do { \
13+
std::cout << "Registering benchmark for " << #func << std::endl; \
14+
static auto& I_PICOBENCH_PP_CAT(picobench, PICOBENCH_UNIQUE_SYM_SUFFIX) = \
15+
PICOBENCH_NAMESPACE::global_registry::new_benchmark(#func, func); \
16+
} while (0)
17+
18+
#endif // CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED

picobench/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
include(FetchContent)
3+
4+
project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)
5+
6+
FetchContent_Declare(
7+
picobench
8+
GIT_REPOSITORY https://github.com/iboB/picobench.git
9+
GIT_TAG 7b5de5ab7dad0a9d6627e63c8757c9c4f0c6b1b3 # v2.07
10+
)
11+
FetchContent_MakeAvailable(picobench)
12+
13+
add_library(codspeed_picobench_compat INTERFACE)
14+
add_library(codspeed_picobench_compat::codspeed_picobench_compat ALIAS codspeed_picobench_compat)
15+
target_include_directories(
16+
codspeed_picobench_compat
17+
INTERFACE
18+
${picobench_SOURCE_DIR}/include
19+
include
20+
)
21+
22+
add_subdirectory(examples)
23+

picobench/examples/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
macro(pb_example name)
2+
set(tgt picobench-example-${name})
3+
add_executable(${tgt} ${ARGN})
4+
target_link_libraries(${tgt} codspeed_picobench_compat)
5+
set_target_properties(${tgt} PROPERTIES FOLDER example)
6+
add_custom_target(
7+
picobench-run-example-${name}
8+
COMMAND ${tgt}
9+
)
10+
endmacro()
11+
12+
pb_example(basic basic.cpp)

picobench/examples/basic.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define PICOBENCH_DEBUG
2+
#define PICOBENCH_IMPLEMENT_WITH_MAIN
3+
#include "codspeed_picobench_compat/picobench.hpp"
4+
5+
#include <vector>
6+
#include <deque>
7+
#include <cstdlib>
8+
9+
void rand_vector(picobench::state& s)
10+
{
11+
std::vector<int> v;
12+
for (auto _ : s)
13+
{
14+
v.push_back(rand());
15+
}
16+
}
17+
PICOBENCH(rand_vector);
18+
19+
void rand_vector_reserve(picobench::state& s)
20+
{
21+
std::vector<int> v;
22+
v.reserve(s.iterations());
23+
for (auto _ : s)
24+
{
25+
v.push_back(rand());
26+
}
27+
}
28+
PICOBENCH(rand_vector_reserve);
29+
30+
void rand_deque(picobench::state& s)
31+
{
32+
std::deque<int> v;
33+
for (auto _ : s)
34+
{
35+
v.push_back(rand());
36+
}
37+
}
38+
PICOBENCH(rand_deque);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
2+
#define CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
3+
4+
#include "picobench/picobench.hpp"
5+
#include <iostream>
6+
7+
// Undefine the original PICOBENCH macro
8+
// #undef PICOBENCH
9+
10+
// Define a new PICOBENCH macro that wraps the original functionality
11+
#define PICOBENCH2(func) \
12+
do { \
13+
std::cout << "Registering benchmark for " << #func << std::endl; \
14+
static auto& I_PICOBENCH_PP_CAT(picobench, PICOBENCH_UNIQUE_SYM_SUFFIX) = \
15+
PICOBENCH_NAMESPACE::global_registry::new_benchmark(#func, func); \
16+
} while (0)
17+
18+
#endif // CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED

0 commit comments

Comments
 (0)