From da497f126a446d7c234b0e424adcdfd5b244ac7d Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 30 Sep 2020 12:22:58 -0700 Subject: [PATCH] more benching --- ixwebsocket/IXGzipCodec.cpp | 42 +++++++++++++++++++++++++++---------- ws/ws.cpp | 3 ++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/ixwebsocket/IXGzipCodec.cpp b/ixwebsocket/IXGzipCodec.cpp index d5e07c47..7ab37664 100644 --- a/ixwebsocket/IXGzipCodec.cpp +++ b/ixwebsocket/IXGzipCodec.cpp @@ -5,6 +5,7 @@ */ #include "IXGzipCodec.h" +#include "IXBench.h" #include #include @@ -24,8 +25,13 @@ namespace ix { #ifdef IXWEBSOCKET_USE_DEFLATE int compressionLevel = 6; - struct libdeflate_compressor *compressor = - libdeflate_alloc_compressor(compressionLevel); + struct libdeflate_compressor *compressor; + + { + Bench bench("creating compressor"); + compressor = + libdeflate_alloc_compressor(compressionLevel); + } const void *uncompressed_data = str.data(); size_t uncompressed_size = str.size(); @@ -35,18 +41,25 @@ namespace ix max_compressed_size = libdeflate_gzip_compress_bound(compressor, uncompressed_size); - compressed_data = malloc(max_compressed_size); + { + Bench bench("alloc data"); + compressed_data = malloc(max_compressed_size); + } + if (compressed_data == NULL) { return std::string(); } - actual_compressed_size = libdeflate_gzip_compress( - compressor, - uncompressed_data, - uncompressed_size, - compressed_data, - max_compressed_size); + { + Bench bench("compressing data"); + actual_compressed_size = libdeflate_gzip_compress( + compressor, + uncompressed_data, + uncompressed_size, + compressed_data, + max_compressed_size); + } if (actual_compressed_size == 0) { @@ -57,8 +70,15 @@ namespace ix libdeflate_free_compressor(compressor); std::string out; - out.append(reinterpret_cast(compressed_data), actual_compressed_size); - free(compressed_data); + { + Bench bench("append data"); + out.append(reinterpret_cast(compressed_data), actual_compressed_size); + } + + { + Bench bench("free data"); + free(compressed_data); + } return out; #else diff --git a/ws/ws.cpp b/ws/ws.cpp index 3a254e1b..e077f2f3 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -1150,6 +1150,7 @@ namespace ix std::string compressedBytes; + spdlog::info("compressing {} times", runCount); std::vector durations; { Bench bench("compressing file"); @@ -1165,7 +1166,7 @@ namespace ix size_t medianIdx = durations.size() / 2; uint64_t medianRuntime = durations[medianIdx]; - spdlog::info("compressing file in {}", medianRuntime); + spdlog::info("median runtime to compress file: {}", medianRuntime); } std::string outputFilename(filename);