mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 17:59:36 +01:00
add derivation parser benchmark
the current identified bottlenecks are parseString in derivations.cc and dirOf (because of std::filessystem creation).
This commit is contained in:
parent
47f5e5fbef
commit
1989dd7bf9
10 changed files with 270 additions and 2 deletions
45
src/libstore-tests/derivation-parser-bench.cc
Normal file
45
src/libstore-tests/derivation-parser-bench.cc
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#include <benchmark/benchmark.h>
|
||||
#include "nix/store/derivations.hh"
|
||||
#include "nix/store/store-api.hh"
|
||||
#include "nix/util/experimental-features.hh"
|
||||
#include "nix/store/store-open.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace nix;
|
||||
|
||||
// Benchmark parsing real derivation files
|
||||
static void BM_ParseRealDerivationFile(benchmark::State & state, const std::string & filename)
|
||||
{
|
||||
// Read the file once
|
||||
std::ifstream file(filename);
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
std::string content = buffer.str();
|
||||
|
||||
auto store = openStore("dummy://");
|
||||
ExperimentalFeatureSettings xpSettings;
|
||||
|
||||
for (auto _ : state) {
|
||||
auto drv = parseDerivation(*store, std::string(content), "test", xpSettings);
|
||||
benchmark::DoNotOptimize(drv);
|
||||
}
|
||||
state.SetBytesProcessed(state.iterations() * content.size());
|
||||
}
|
||||
|
||||
// Register benchmarks for actual test derivation files if they exist
|
||||
BENCHMARK_CAPTURE(BM_ParseRealDerivationFile, hello, std::string(NIX_UNIT_TEST_DATA) + "/derivation/hello.drv");
|
||||
BENCHMARK_CAPTURE(BM_ParseRealDerivationFile, firefox, std::string(NIX_UNIT_TEST_DATA) + "/derivation/firefox.drv");
|
||||
|
||||
// Custom main to initialize Nix before running benchmarks
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
// Initialize libstore
|
||||
nix::initLibStore(false);
|
||||
|
||||
// Initialize and run benchmarks
|
||||
::benchmark::Initialize(&argc, argv);
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue