diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index bbf00705a..9922e96e4 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -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}) @@ -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 diff --git a/benchmark/files/iso_language_2023_set_3_locations.json.gz b/benchmark/files/iso_language_2023_set_3_locations.json.gz new file mode 100644 index 000000000..6bf023c9f Binary files /dev/null and b/benchmark/files/iso_language_2023_set_3_locations.json.gz differ diff --git a/benchmark/files/iso_language_2023_set_3_schema.json.gz b/benchmark/files/iso_language_2023_set_3_schema.json.gz new file mode 100644 index 000000000..91bc97d67 Binary files /dev/null and b/benchmark/files/iso_language_2023_set_3_schema.json.gz differ diff --git a/benchmark/gzip.cc b/benchmark/gzip.cc new file mode 100644 index 000000000..8b629d7f1 --- /dev/null +++ b/benchmark/gzip.cc @@ -0,0 +1,72 @@ +#include + +#include +#include + +#include // std::uint8_t +#include // 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(), view.size())}; + + for (auto _ : state) { + auto result{sourcemeta::core::gzip( + reinterpret_cast(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(), view.size()).size()}; + + for (auto _ : state) { + auto result{sourcemeta::core::gunzip(view.as(), 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(), view.size())}; + + for (auto _ : state) { + auto result{sourcemeta::core::gzip( + reinterpret_cast(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(), view.size()).size()}; + + for (auto _ : state) { + auto result{sourcemeta::core::gunzip(view.as(), 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);