#include #include "nix/store/derivations.hh" #include "nix/store/store-api.hh" #include "nix/util/experimental-features.hh" #include "nix/util/environment-variables.hh" #include "nix/store/store-open.hh" #include #include 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, getEnvNonEmpty("_NIX_TEST_UNIT_DATA").value_or(NIX_UNIT_TEST_DATA) + "/derivation/hello.drv"); BENCHMARK_CAPTURE( BM_ParseRealDerivationFile, firefox, getEnvNonEmpty("_NIX_TEST_UNIT_DATA").value_or(NIX_UNIT_TEST_DATA) + "/derivation/firefox.drv");