From f2dc9dbb2d3879f90eccf84ee117def9e52c9586 Mon Sep 17 00:00:00 2001 From: Serpent7776 Date: Thu, 2 May 2024 13:58:14 +0200 Subject: [PATCH 1/2] Add measurement samples to xml reporter --- src/catch2/reporters/catch_reporter_xml.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp index 35a3028ee2..38f5206e67 100644 --- a/src/catch2/reporters/catch_reporter_xml.cpp +++ b/src/catch2/reporters/catch_reporter_xml.cpp @@ -250,6 +250,12 @@ namespace Catch { .writeAttribute("lowSevere"_sr, benchmarkStats.outliers.low_severe) .writeAttribute("highMild"_sr, benchmarkStats.outliers.high_mild) .writeAttribute("highSevere"_sr, benchmarkStats.outliers.high_severe); + auto samples = m_xml.scopedElement("samples"); + for (auto const& sample : benchmarkStats.samples) { + m_xml.startElement("sample", XmlFormatting::Indent) + .writeText(std::to_string(sample.count()), XmlFormatting::None) + .endElement(XmlFormatting::Newline); + } m_xml.endElement(); } From 95fa9b20e2c647757a6a16e82e99dd99b7647b3c Mon Sep 17 00:00:00 2001 From: Serpent7776 Date: Thu, 2 May 2024 13:58:32 +0200 Subject: [PATCH 2/2] Add box plot drawing script --- extras/boxplot_xml.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 extras/boxplot_xml.R diff --git a/extras/boxplot_xml.R b/extras/boxplot_xml.R new file mode 100644 index 0000000000..016518872f --- /dev/null +++ b/extras/boxplot_xml.R @@ -0,0 +1,34 @@ +library(XML) +library(ggplot2) + +args <- commandArgs(trailingOnly = TRUE) +data <- xmlParse(args[1]) + +for (test_case in data["//TestCase"]) { + test_case_name <- xpathSApply(test_case, "./@name", paste) + results <- xpathSApply(test_case, ".//BenchmarkResults") + samples <- xpathSApply(test_case, ".//sample", xmlValue) + counts <- xpathSApply(test_case, ".//BenchmarkResults", function(r) { + xmlGetAttr(r, "samples", default = 0, converter = as.integer) + }) + names <- xpathSApply(test_case, ".//BenchmarkResults/@name", paste) + + if (length(names) == 0 || sum(counts) == 0) next + names <- rep(names, counts) + + df <- data.frame( + methods = names, + samples = as.numeric(samples) + ) + + p <- ggplot(df, aes(x = methods, y = samples, fill = methods)) + + geom_boxplot(size = 0.5, staplewidth = 0.5) + + theme(axis.text.x = element_text(angle = -45, vjust = 1, hjust = 0)) + + labs(x = "Benchmark", y = "Time [ns]", title = test_case_name, fill = "Benchmark") + + scale_y_continuous(limits = c(0, NA)) + print(p) + test_case_name |> + gsub(pattern = "\\s", replacement = "_") |> + paste(".png", sep = "") |> + ggsave() +}