mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
set up performance benchmarks (#8865)
This commit is contained in:
18
Code/Bench/CMakeLists.txt
Normal file
18
Code/Bench/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
add_executable(bench EXCLUDE_FROM_ALL smiles.cpp stereo.cpp)
|
||||||
|
target_link_libraries(bench rdkitCatch SmilesParse CIPLabeler)
|
||||||
|
|
||||||
|
if(RDK_BUILD_CPP_TESTS)
|
||||||
|
# add a fast version of the benchmarks to the default unit tests
|
||||||
|
# to protect the benchmarks from bit-rot
|
||||||
|
add_test(
|
||||||
|
NAME quickbench
|
||||||
|
COMMAND bench --benchmark-samples 1 --benchmark-warmup-time 0
|
||||||
|
)
|
||||||
|
|
||||||
|
# ctest does not automatically build test executables
|
||||||
|
# so, like with other unit tests in this repo, we need to manually
|
||||||
|
# build the target before running ctest. This usually gets done with
|
||||||
|
# an `all` or an `install` build. We re-add bench to he `all` group
|
||||||
|
# to keep it similar to the other unit tests
|
||||||
|
set_target_properties(bench PROPERTIES EXCLUDE_FROM_ALL FALSE)
|
||||||
|
endif(RDK_BUILD_CPP_TESTS)
|
||||||
12
Code/Bench/README.md
Normal file
12
Code/Bench/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# RDKit Benchmarks
|
||||||
|
|
||||||
|
To run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
cmake --build . --target bench -j "$(nproc)"
|
||||||
|
# see `./Code/Bench/bench --help` for options
|
||||||
|
./Code/Bench/bench
|
||||||
|
```
|
||||||
11
Code/Bench/bench_common.hpp
Normal file
11
Code/Bench/bench_common.hpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace bench_common {
|
||||||
|
constexpr const char *CASES[] = {
|
||||||
|
"COC1/C=C/OC2(C)Oc3c(C)c(O)c4c(O)c(c(/C=N/OC(c5ccccc5)c5ccccc5)cc4c3C2=O)NC(=O)/C(C)=C\\C=C\\C(C)C(O)C(C)C(O)C(C)C(OC(C)=O)C1C",
|
||||||
|
"Cn1cnc2n(C)c(=O)n(C)c(=O)c12",
|
||||||
|
"c1ccc2c(c1)c3ccccc3c4ccccc24",
|
||||||
|
"F[C@@H](Cl)[C@H](Br)[C@](I)(O)[C@@](N)(C#N)C(=O)O",
|
||||||
|
"C[S+](C)(C)[O-]",
|
||||||
|
};
|
||||||
|
} // namespace bench_common
|
||||||
30
Code/Bench/smiles.cpp
Normal file
30
Code/Bench/smiles.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <catch2/catch_all.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "bench_common.hpp"
|
||||||
|
|
||||||
|
#include <GraphMol/ROMol.h>
|
||||||
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
||||||
|
#include <GraphMol/SmilesParse/SmilesWrite.h>
|
||||||
|
|
||||||
|
using namespace RDKit;
|
||||||
|
|
||||||
|
TEST_CASE("SmilesToMol", "[smiles]") {
|
||||||
|
for (auto smiles : bench_common::CASES) {
|
||||||
|
BENCHMARK("SmilesToMol: " + std::string(smiles)) {
|
||||||
|
auto mol = v2::SmilesParse::MolFromSmiles(smiles);
|
||||||
|
REQUIRE(mol);
|
||||||
|
return mol;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("MolToSmiles", "[smiles]") {
|
||||||
|
for (auto smiles : bench_common::CASES) {
|
||||||
|
auto mol = v2::SmilesParse::MolFromSmiles(smiles);
|
||||||
|
REQUIRE(mol);
|
||||||
|
BENCHMARK("MolToSmiles: " + std::string(smiles)) {
|
||||||
|
return MolToSmiles(*mol);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
33
Code/Bench/stereo.cpp
Normal file
33
Code/Bench/stereo.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <catch2/catch_all.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "bench_common.hpp"
|
||||||
|
|
||||||
|
#include <GraphMol/CIPLabeler/CIPLabeler.h>
|
||||||
|
#include <GraphMol/Chirality.h>
|
||||||
|
#include <GraphMol/ROMol.h>
|
||||||
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
||||||
|
|
||||||
|
using namespace RDKit;
|
||||||
|
|
||||||
|
TEST_CASE("Chirality::findPotentialStereo", "[stereo]") {
|
||||||
|
for (auto smiles : bench_common::CASES) {
|
||||||
|
auto mol = v2::SmilesParse::MolFromSmiles(smiles);
|
||||||
|
REQUIRE(mol);
|
||||||
|
|
||||||
|
BENCHMARK("Chirality::findPotentialStereo: " + std::string(smiles)) {
|
||||||
|
return Chirality::findPotentialStereo(*mol);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("CIPLabeler::CIPLabeler", "[stereo]") {
|
||||||
|
for (auto smiles : bench_common::CASES) {
|
||||||
|
auto mol = v2::SmilesParse::MolFromSmiles(smiles);
|
||||||
|
REQUIRE(mol);
|
||||||
|
|
||||||
|
BENCHMARK("CIPLabeler::assignCIPLabels: " + std::string(smiles)) {
|
||||||
|
return Chirality::findPotentialStereo(*mol);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,3 +40,5 @@ add_subdirectory(MinimalLib)
|
|||||||
if(RDK_BUILD_FUZZ_TARGETS)
|
if(RDK_BUILD_FUZZ_TARGETS)
|
||||||
add_subdirectory(Fuzz)
|
add_subdirectory(Fuzz)
|
||||||
endif(RDK_BUILD_FUZZ_TARGETS)
|
endif(RDK_BUILD_FUZZ_TARGETS)
|
||||||
|
|
||||||
|
add_subdirectory(Bench)
|
||||||
|
|||||||
Reference in New Issue
Block a user