// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System.Collections.Generic; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; using TazelCommandLine = Progmasoft.Tazel.Cli.CommandLine; using Progmasoft.Tazel.Driver; using Progmasoft.Tazel.Dsl.Custom.Parser; using Progmasoft.Tazel.Label; using Progmasoft.Tazel.Project; namespace Progmasoft.Tazel.Benchmarks; /// What a build does many times: read labels, match globs, read depfiles and command lines. [MemoryDiagnoser] public class Readers { private const string Depfile = """ .tazel/out/linux-amd64-debug/_objs/app/src/main.cpp.o: src/main.cpp \ /usr/include/stdio.h /usr/include/bits/libc-header-start.h \ /usr/include/features.h include/math/vec\ tor.hpp include/math/details.inl """; private const string Custom = """ build-no-cache: ("tazel" 'build' `--no-cache`); fetch: ("cargo" "fetch") ("tazel" "fetch"); build with: ("tazel" "build" <1> <2>); """; private static readonly string[] BuildLine = ["build", "//app/...", "--mode=release", "--compiler-options=-O3,-g", "--feature", "lto", "--color:never"]; /// Reads one label. [Benchmark] public Selection Label() => Labels.Selection("@dep//app/cli:greeter-main", PackageId.Root); /// Matches a path against a pattern with **. [Benchmark] public bool Glob() => FileSets.Matches("src/**/test_*.cpp", "src/a/b/c/test_vector.cpp"); /// Reads the inputs of a depfile. [Benchmark] public IReadOnlyList DepfileInputs() => Depfiles.Inputs(Depfile); /// Reads a tazel_custom.txt. [Benchmark] public int CustomCommands() => CustomParser.Parse(Custom).Count; /// Reads a command line. [Benchmark] public object CommandLineOfABuild() => TazelCommandLine.Parse(BuildLine); } /// Runs the benchmarks: dotnet run -c Release --project benchmarks/Progmasoft.Tazel.Benchmarks. public static class Program { /// Runs what the arguments select. public static void Main(string[] arguments) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(arguments); }