mirror of
https://github.com/progsource/maddy.git
synced 2026-03-25 07:50:39 +01:00
Add benchmark
Some checks failed
run-checks / run-clang-format (push) Has been cancelled
run-tests / test-on-ubuntu (push) Has been cancelled
run-tests / test-on-windows (push) Has been cancelled
run-tests / test-on-osx (push) Has been cancelled
Some checks failed
run-checks / run-clang-format (push) Has been cancelled
run-tests / test-on-ubuntu (push) Has been cancelled
run-tests / test-on-windows (push) Has been cancelled
run-tests / test-on-osx (push) Has been cancelled
* add benchmark option * updated changelog * added benchmark info to readme * add bench folder to format.py
This commit is contained in:
@@ -13,10 +13,11 @@ maddy uses [semver versioning](https://semver.org/).
|
||||
*  for now removed features.
|
||||
|
||||
## Upcoming
|
||||
|
||||
*  Correctly parse links with title text, i.e. `[link](http://example.com "example")`.
|
||||
*  Do not create invalid URLs from links with spaces, i.e. `[link](/ABC/some file)`.
|
||||
*  Do not create invalid HTML from links with quotes, i.e. `[link](/ABC/some"file)`.
|
||||
|
||||
*  benchmarks.
|
||||
|
||||
## version 1.4.0 2025-03-28
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ if(${MADDY_BUILD_WITH_TESTS})
|
||||
enable_testing()
|
||||
endif()
|
||||
|
||||
option(MADDY_BUILD_WITH_BENCH "enable benchmarks" OFF)
|
||||
option(MADDY_CREATE_PACKAGE "create a package for a version release" OFF)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -49,10 +50,14 @@ if(${MADDY_BUILD_WITH_TESTS})
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
if(${MADDY_BUILD_WITH_BENCH})
|
||||
add_subdirectory(bench)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
if(${MADDY_CREATE_PACKAGE})
|
||||
set(MADDY_PACKAGE_FILES include/ CMakeLists.txt LICENSE)
|
||||
set(MADDY_PACKAGE_FILES include/ CMakeLists.txt LICENSE AUTHORS)
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip
|
||||
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip --format=zip -- ${MADDY_PACKAGE_FILES}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
||||
15
README.md
15
README.md
@@ -98,6 +98,21 @@ make
|
||||
make test # or run the executable in ../build/MaddyTests
|
||||
```
|
||||
|
||||
## How to run the benchmarks
|
||||
|
||||
To get proper test results, the benchmarks should always be compiled as
|
||||
release build.
|
||||
|
||||
```shell
|
||||
git clone https://github.com/progsource/maddy.git
|
||||
cd maddy
|
||||
mkdir tmp
|
||||
cd tmp
|
||||
cmake -DMADDY_BUILD_WITH_BENCH=ON -DCMAKE_BUILD_TYPE=Release ..
|
||||
make BUILD_TYPE=Release
|
||||
../build/maddy_benchmark
|
||||
```
|
||||
|
||||
## How to contribute
|
||||
|
||||
There are different possibilities:
|
||||
|
||||
50
bench/CMakeLists.txt
Normal file
50
bench/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
# This project is licensed under the MIT license. For more information see the
|
||||
# LICENSE file.
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER}
|
||||
-fuse-ld=gold -Wl,--version
|
||||
ERROR_QUIET OUTPUT_VARIABLE ld_version)
|
||||
if ("${ld_version}" MATCHES "GNU gold")
|
||||
message(STATUS "Found Gold linker, use faster linker")
|
||||
set(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS
|
||||
"${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold ")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
nanobench
|
||||
GIT_REPOSITORY https://github.com/martinus/nanobench.git
|
||||
GIT_TAG v4.3.11
|
||||
GIT_SHALLOW TRUE
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(nanobench)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
file(GLOB_RECURSE MADDY_BENCHMARK_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
add_executable(
|
||||
maddy_benchmark
|
||||
${MADDY_BENCHMARK_FILES}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
|
||||
)
|
||||
target_include_directories(maddy_benchmark PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
target_link_libraries(maddy_benchmark maddy nanobench::nanobench)
|
||||
set_target_properties(maddy_benchmark PROPERTIES
|
||||
CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -O2 -Wall -Wno-ignored-qualifiers -Wpedantic -Wextra -Wno-deprecated -fno-exceptions -fno-rtti"
|
||||
)
|
||||
14
bench/README.md
Normal file
14
bench/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# maddy benchmarks
|
||||
|
||||
## How to run
|
||||
|
||||
The benchmarks have to be run in release mode to give proper results.
|
||||
|
||||
```shell
|
||||
# in main folder
|
||||
mkdir tmp
|
||||
cd tmp
|
||||
cmake -DMADDY_BUILD_WITH_BENCH=ON -DCMAKE_BUILD_TYPE=Release ..
|
||||
make BUILD_TYPE=Release
|
||||
../build/maddy_benchmark
|
||||
```
|
||||
63
bench/main.cpp
Normal file
63
bench/main.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This project is licensed under the MIT license. For more information see the
|
||||
* LICENSE file.
|
||||
*/
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#define ANKERL_NANOBENCH_IMPLEMENT
|
||||
#include <nanobench.h>
|
||||
|
||||
#include "maddy/parser.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
static const std::string markdownFile = "../docs/definitions.md";
|
||||
std::stringstream buffer;
|
||||
|
||||
{
|
||||
std::ifstream file(markdownFile);
|
||||
|
||||
if (!file.good() || !file.is_open())
|
||||
{
|
||||
std::cout << "could not read file at " << markdownFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer << file.rdbuf();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
if (!buffer.good() || buffer.str().empty())
|
||||
{
|
||||
std::cout << "buffer is invalid" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
// maddy 1.*
|
||||
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
|
||||
|
||||
// This is the place in the future to compare maddy with other libraries.
|
||||
// For now it can be used to check if changes in maddy code result in better
|
||||
// performance.
|
||||
|
||||
ankerl::nanobench::Bench()
|
||||
.title("maddy test")
|
||||
.warmup(100)
|
||||
.relative(true)
|
||||
.run(
|
||||
"maddy 1.x",
|
||||
[&]()
|
||||
{
|
||||
buffer.clear(); // clear any error flags
|
||||
buffer.seekg(0, buffer.beg);
|
||||
ankerl::nanobench::doNotOptimizeAway(parser->Parse(buffer));
|
||||
}
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -60,6 +60,8 @@ def format_files(dry_run):
|
||||
during the actual formatting process.
|
||||
"""
|
||||
patterns = [
|
||||
"bench/**/*.h",
|
||||
"bench/**/*.cpp",
|
||||
"include/**/*.h",
|
||||
"tests/**/*.h",
|
||||
"tests/**/*.cpp",
|
||||
|
||||
Reference in New Issue
Block a user