Files
rdkit/Code/Bench/pickle.cpp
Andrew Dirksen 2adf5211e6 add more benchmarking (#8878)
* Add many new c++ catch2 performance benchmarks.

* inline splitmix64 from boost, splitmix64 is not always available in boost. fun fact, this version is ~twice as fast

* reduce intensity of memory pressure test, target 200MB usage.

* new bench compound; accept suggestion from code review

* bench MolToCXSmiles

* Update Code/Bench/stereo.cpp

* impl first part of the suggestions from code reveiw

* impl second part of the suggestions from code reveiw
2025-11-27 14:25:57 +01:00

42 lines
1.0 KiB
C++

#include <catch2/catch_all.hpp>
#include <string>
#include <sstream>
#include "bench_common.hpp"
#include <GraphMol/MolPickler.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
using namespace RDKit;
TEST_CASE("MolPickler::pickleMol", "[pickle]") {
auto samples = bench_common::load_samples();
BENCHMARK("MolPickler::pickleMol") {
std::stringstream buf;
for (auto &mol : samples) {
MolPickler::pickleMol(mol, buf);
}
return buf.str().size();
};
}
TEST_CASE("MolPickler::molFromPickle", "[pickle]") {
auto samples = bench_common::load_samples();
std::vector<std::string> pickles;
pickles.reserve(samples.size());
for (auto &mol : samples) {
std::string pickled;
MolPickler::pickleMol(mol, pickled);
pickles.push_back(std::move(pickled));
}
BENCHMARK("MolPickler::molFromPickle") {
auto total_atoms = 0;
for (auto &pickled : pickles) {
ROMol res(pickled);
total_atoms += res.getNumAtoms();
}
REQUIRE(total_atoms > 0);
return total_atoms;
};
}