Skip to content

Commit c96f9df

Browse files
committed
init
0 parents  commit c96f9df

File tree

13 files changed

+1421
-0
lines changed

13 files changed

+1421
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(version_weaver)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED True)
6+
if (NOT CMAKE_BUILD_TYPE)
7+
message(STATUS "No build type selected, default to Release")
8+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
9+
endif()
10+
11+
12+
add_subdirectory(src)
13+
enable_testing()
14+
add_subdirectory(tests)
15+
add_subdirectory(benchmarks)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# version_weaver: fast semver library
2+
3+
Usage:
4+
```
5+
cmake -B build
6+
cmake --build build
7+
ctest --test-dir build
8+
./build/benchmarks/benchmark
9+
```

benchmarks/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_executable(benchmark benchmark.cpp)
2+
target_include_directories(version_weaver
3+
PUBLIC
4+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/benchmarks>
5+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
6+
)
7+
target_link_libraries(benchmark version_weaver)

benchmarks/benchmark.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
#include "performancecounters/benchmarker.h"
3+
#include <algorithm>
4+
#include <charconv>
5+
#include <filesystem>
6+
#include <fstream>
7+
#include <iostream>
8+
#include <random>
9+
#include <stdlib.h>
10+
#include <vector>
11+
#include "version_weaver.h"
12+
13+
void pretty_print(size_t volume, size_t bytes, std::string name,
14+
event_aggregate agg, bool display = true) {
15+
printf("%-40s : ", name.c_str());
16+
printf(" %5.2f Gi/s ", volume / agg.fastest_elapsed_ns());
17+
double range = (agg.elapsed_ns() - agg.fastest_elapsed_ns())/agg.elapsed_ns() * 100.0;
18+
printf(" %5.2f GB/s (%2.0f %%) ", bytes / agg.fastest_elapsed_ns(), range);
19+
if (collector.has_events()) {
20+
printf(" %5.2f GHz ", agg.fastest_cycles() / agg.fastest_elapsed_ns());
21+
printf(" %5.2f c/b ", agg.fastest_cycles() / bytes);
22+
printf(" %5.2f i/b ", agg.fastest_instructions() / bytes);
23+
printf(" %5.2f i/c ", agg.fastest_instructions() / agg.fastest_cycles());
24+
}
25+
printf("\n");
26+
}
27+
28+
void bench(const std::vector<std::string> &input) {
29+
size_t volume = input.size();
30+
size_t bytes = 0;
31+
for (size_t i = 0; i < volume; i++) {
32+
bytes += input[i].size();
33+
}
34+
std::cout << "volume : " << volume << " strings" << std::endl;
35+
std::cout << "volume : " << bytes / 1024 / 1024.
36+
<< " MB" << std::endl;
37+
volatile size_t sum = 0;
38+
39+
size_t min_repeat = 10;
40+
size_t min_time_ns = 10000000000;
41+
size_t max_repeat = 100000;
42+
pretty_print(volume, bytes, "validate",
43+
bench([&input,&sum]() { for(std::string_view v : input) { sum += version_weaver::validate(v); } },
44+
min_repeat, min_time_ns, max_repeat));
45+
46+
}
47+
48+
49+
int main(int argc, char **argv) {
50+
bench({"1.2.4", "13.4.1"});
51+
return EXIT_SUCCESS;
52+
}

0 commit comments

Comments
 (0)