mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 09:49:36 +01:00
This changes our GHA CI and nix-store-tests packaging to build and run the benchmarks. This does not affect the default packaging - the overrides apply only for the GHA CI.
39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
#include <benchmark/benchmark.h>
|
|
#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 <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,
|
|
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");
|