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
55 changes: 55 additions & 0 deletions benchmark/gzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include <cstdint> // std::uint8_t
#include <filesystem> // std::filesystem
#include <ios> // std::streamsize
#include <istream> // std::istream
#include <sstream> // std::istringstream
#include <string> // std::string

static void
// NOLINTNEXTLINE(readability-identifier-naming)
Expand Down Expand Up @@ -39,6 +43,55 @@ GZIP_Decompress_ISO_Language_Set_3_Locations(benchmark::State &state) {
}
}

static void
// NOLINTNEXTLINE(readability-identifier-naming)
GZIP_Decompress_Default_Level_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())};
const auto compressed{sourcemeta::core::gzip(
reinterpret_cast<const std::uint8_t *>(contents.data()),
contents.size())};

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

static void
// NOLINTNEXTLINE(readability-identifier-naming)
GZIP_Decompress_Stream_Default_Level_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())};
std::istringstream source{sourcemeta::core::gzip(
reinterpret_cast<const std::uint8_t *>(contents.data()),
contents.size())};

for (auto iteration : state) {
source.clear();
source.seekg(0);
sourcemeta::core::GZIPStreamBuffer buffer{source};
std::istream decompressed{&buffer};
std::string result;
result.resize(contents.size());
decompressed.read(result.data(),
static_cast<std::streamsize>(contents.size()));
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
// Reaching the end of the stream validates the member trailer
benchmark::DoNotOptimize(decompressed.peek());
benchmark::DoNotOptimize(result);
}
}

// NOLINTNEXTLINE(readability-identifier-naming)
static void GZIP_Compress_ISO_Language_Set_3_Schema(benchmark::State &state) {
const sourcemeta::core::FileView view{
Expand Down Expand Up @@ -72,5 +125,7 @@ static void GZIP_Decompress_ISO_Language_Set_3_Schema(benchmark::State &state) {

BENCHMARK(GZIP_Compress_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Decompress_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Decompress_Default_Level_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Decompress_Stream_Default_Level_ISO_Language_Set_3_Locations);
BENCHMARK(GZIP_Compress_ISO_Language_Set_3_Schema);
BENCHMARK(GZIP_Decompress_ISO_Language_Set_3_Schema);
3 changes: 1 addition & 2 deletions test/gzip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
sourcemeta_test(NAMESPACE sourcemeta PROJECT core NAME gzip
SOURCES
gzip_test.cc
gzip_error_test.cc
gzip_streambuf_test.cc)

target_link_libraries(sourcemeta_core_gzip_unit
PRIVATE sourcemeta::core::gzip)
target_link_libraries(sourcemeta_core_gzip_unit
PRIVATE sourcemeta::core::io)
Loading