Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if(SOURCEMETA_CORE_HTML)
list(APPEND BENCHMARK_SOURCES html.cc)
endif()

if(SOURCEMETA_CORE_GZIP)
list(APPEND BENCHMARK_SOURCES gzip.cc)
endif()

if(BENCHMARK_SOURCES)
sourcemeta_googlebenchmark(NAMESPACE sourcemeta PROJECT core
SOURCES ${BENCHMARK_SOURCES})
Expand Down Expand Up @@ -78,6 +82,11 @@ if(BENCHMARK_SOURCES)
PRIVATE sourcemeta::core::html)
endif()

if(SOURCEMETA_CORE_GZIP)
target_link_libraries(sourcemeta_core_benchmark
PRIVATE sourcemeta::core::gzip sourcemeta::core::io)
endif()

add_custom_target(benchmark_all
COMMAND sourcemeta_core_benchmark
DEPENDS sourcemeta_core_benchmark
Expand Down
Binary file not shown.
Binary file not shown.
72 changes: 72 additions & 0 deletions benchmark/gzip.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <benchmark/benchmark.h>

#include <sourcemeta/core/gzip.h>
#include <sourcemeta/core/io.h>

#include <cstdint> // std::uint8_t
#include <filesystem> // std::filesystem

static void
GZIP_Compress_ISO_Language_Set_3_Locations(benchmark::State &state) {
const sourcemeta::core::FileView view{
std::filesystem::path{CURRENT_DIRECTORY} / "files" /
"iso_language_2023_set_3_locations.json.gz"};
const auto contents{
sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size())};
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileView::as<std::uint8_t>() asserts that the file has at least 1 byte; if a benchmark fixture is empty/corrupt this would abort in debug builds before gunzip() can report a decompression error.

Severity: low

Other Locations
  • benchmark/gzip.cc:32
  • benchmark/gzip.cc:35
  • benchmark/gzip.cc:47
  • benchmark/gzip.cc:60
  • benchmark/gzip.cc:63

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.


for (auto _ : state) {
auto result{sourcemeta::core::gzip(
reinterpret_cast<const std::uint8_t *>(contents.data()),
contents.size())};
benchmark::DoNotOptimize(result);
}
}

static void
GZIP_Decompress_ISO_Language_Set_3_Locations(benchmark::State &state) {
const sourcemeta::core::FileView view{
std::filesystem::path{CURRENT_DIRECTORY} / "files" /
"iso_language_2023_set_3_locations.json.gz"};
const auto output_hint{
sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size()).size()};

for (auto _ : state) {
auto result{sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size(),
output_hint)};
benchmark::DoNotOptimize(result);
}
}

static void GZIP_Compress_ISO_Language_Set_3_Schema(benchmark::State &state) {
const sourcemeta::core::FileView view{
std::filesystem::path{CURRENT_DIRECTORY} / "files" /
"iso_language_2023_set_3_schema.json.gz"};
const auto contents{
sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size())};

for (auto _ : state) {
auto result{sourcemeta::core::gzip(
reinterpret_cast<const std::uint8_t *>(contents.data()),
contents.size())};
benchmark::DoNotOptimize(result);
}
}

static void GZIP_Decompress_ISO_Language_Set_3_Schema(benchmark::State &state) {
const sourcemeta::core::FileView view{
std::filesystem::path{CURRENT_DIRECTORY} / "files" /
"iso_language_2023_set_3_schema.json.gz"};
const auto output_hint{
sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size()).size()};

for (auto _ : state) {
auto result{sourcemeta::core::gunzip(view.as<std::uint8_t>(), view.size(),
output_hint)};
benchmark::DoNotOptimize(result);
}
}

BENCHMARK(GZIP_Compress_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Decompress_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Compress_ISO_Language_Set_3_Schema);
BENCHMARK(GZIP_Decompress_ISO_Language_Set_3_Schema);
Loading