[BUG] Benchmark registration order affects reported outcomes
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- cpp
- Área
- performance
Línea de trabajo
Reproduce la secuencia de registro proporcionada de BM_DoWork y BM_DoWork1 en Windows 11 con MSVC 17.14.15 y, a continuación, compara los resultados después de cambiar el orden de registro. Empieza siguiendo el recorrido de registro y ejecución del benchmark alrededor de BENCHMARK y KeepRunningBatch; se considera terminado cuando el orden ya no provoca cambios sistemáticos grandes o la limitación queda documentada claramente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Hello,
I have the following bechmark:
#include <benchmark/benchmark.h>
#include <gtest/gtest.h>
/**
* defines / pre-allocates a std::vector<std::wstring> examples (within g_dataset)
*/
#include "Helpers.h"
#include <chrono>
#include <cstdint>
#include <ranges>
#include <vector>
#include <execution>
#include <codecvt>
std::string DoWork(const std::wstring& input)
{
std::string result(input.size(), '\0');
std::transform(std::execution::par_unseq, std::begin(input), std::end(input), std::begin(result),
[](wchar_t inChar) { return (char)(inChar & 0x0ff); });
return result;
}
std::wstring DoWork1(const std::string& input)
{
std::wstring result(input.size(), L'\0');
std::transform(std::execution::par_unseq, std::begin(input), std::end(input), std::begin(result),
[](wchar_t inChar) { return (wchar_t)(inChar & 0x0ff); });
return result;
}
template <typename InStringT,
typename Fn,
typename OutStringT = std::invoke_result_t<Fn,InStringT>>
void RunOnExamples(const std::vector<InStringT>& examples, Fn&& fn,
std::vector<OutStringT>& results)
{
for (size_t iterations = 0; iterations < examples.size(); iterations++) {
results[iterations] = fn(examples[iterations]);
}
}
static void BM_DoWork(benchmark::State& state)
{
state.PauseTiming();
auto expectedResults = std::vector<std::string>(g_dataset.examples.size());
state.ResumeTiming();
while (state.KeepRunningBatch(g_dataset.examples.size())) {
RunOnExamples(g_dataset.examples, DoWork, expectedResults);
}
state.SetItemsProcessed(state.iterations() * g_dataset.examples.size());
}
static void BM_DoWork1(benchmark::State& state)
{
state.PauseTiming();
auto expectedResults = std::vector<std::wstring>(g_dataset.examples.size());
std::vector<std::string> examples(g_dataset.examples.size());
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> myconv;
for (size_t i = 0; i < g_dataset.examples.size(); i++) {
examples[i] = myconv.to_bytes(g_dataset.examples[i]);
}
state.ResumeTiming();
while (state.KeepRunningBatch(g_dataset.examples.size())) {
RunOnExamples(examples, DoWork1, expectedResults);
}
state.SetItemsProcessed(state.iterations() * g_dataset.examples.size());
}
#pragma endregion
#pragma region Run benchmarks
BENCHMARK(BM_DoWork);
BENCHMARK(BM_DoWork);
BENCHMARK(BM_DoWork);
BENCHMARK(BM_DoWork1);
BENCHMARK(BM_DoWork1);
BENCHMARK(BM_DoWork1);
#pragma endregion
The output looks like this - the items_per_second decreases in rather big jumps:
Run on (20 X 2918 MHz CPU s)
CPU Caches:
L1 Data 48 KiB (x10)
L1 Instruction 32 KiB (x10)
L2 Unified 1280 KiB (x10)
L3 Unified 24576 KiB (x1)
------------------------------------------------------------------------------
Benchmark Time CPU Iterations UserCounters...
------------------------------------------------------------------------------
BM_DoWork 86347685 ns 6438 ns 1000000 items_per_second=155.34G/s
BM_DoWork 86352813 ns 10688 ns 1000000 items_per_second=93.5673G/s
BM_DoWork 86358084 ns 15141 ns 1000000 items_per_second=66.0475G/s
BM_DoWork1 86363182 ns 19484 ns 1000000 items_per_second=51.3232G/s
BM_DoWork1 86369707 ns 25062 ns 1000000 items_per_second=39.9002G/s
BM_DoWork1 86378334 ns 32438 ns 1000000 items_per_second=30.8285G/s
If I reorder the benchmarks, the same pattern is observed.
There has been a similar question on StackOverlow a couple of years ago, but it remained unanswered.
System
Which OS, compiler, and compiler version are you using:
- OS: Microsoft Windows 11
- Compiler and version: MSVC 17.14.15
Expected behavior
Registering benchmarks in different order shouldn't affect the measured performance - a deviation of "a couple" percent is expected, but nothing like the steady decreasing in huge jumps.
- Lenguaje dominante
- C++
- Estrellas
- 10.5k
- Forks
- 1.8k
- Merge medio
- 2 d 2 h
- PR fusionados (30 d)
- 30
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de google/benchmark
-
[BUG] Confusing title in docs/platform_specific_build_instructions.mdPosiblemente ocupada @skryabae la tomó hace 27 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
[BUG] Memory manager counts allocations not part of benchmarkQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
google/benchmark#2149 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Three small hardening notes from a security review: CSV formula-prefix neutralization, full C0 escaping in the JSON reporter, and type diagnostics in gbench/compare.pyPosiblemente ocupada @Aryan9891 la tomó hace 6 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 64/100
google/benchmark#2299 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
[FR] Add native Zig bindings via top-level `bindings/zig`Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 42/100
google/benchmark#2266 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
google/benchmark#2195 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de google/benchmark
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
-
[XLA] hlo/pass/README.md says passes implement Run; since the NVI change they implement RunImplAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA-RTX/NRI#312 ·
Los mantenedores suelen responder en 1 día
-
permute_q_b_proj / permute_wv_proj accept scale factors from another devicePosiblemente ocupada @0z5a la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
deepseek-ai/FlashMLA#247 ·
Los mantenedores suelen responder en 1 día
-
Linux npm packaging leaves workspace files that block subsequent CI checkoutPosiblemente ocupada @Spockkk0225 la tomó hoy. Abiertoci
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
alibaba/neug#1195 · 1 comentario ·
Los mantenedores suelen responder en 1 día