more benching

This commit is contained in:
Benjamin Sergeant 2020-09-30 12:22:58 -07:00
parent bdadfcba19
commit da497f126a
2 changed files with 33 additions and 12 deletions

View File

@ -5,6 +5,7 @@
*/ */
#include "IXGzipCodec.h" #include "IXGzipCodec.h"
#include "IXBench.h"
#include <array> #include <array>
#include <string.h> #include <string.h>
@ -24,8 +25,13 @@ namespace ix
{ {
#ifdef IXWEBSOCKET_USE_DEFLATE #ifdef IXWEBSOCKET_USE_DEFLATE
int compressionLevel = 6; int compressionLevel = 6;
struct libdeflate_compressor *compressor = struct libdeflate_compressor *compressor;
libdeflate_alloc_compressor(compressionLevel);
{
Bench bench("creating compressor");
compressor =
libdeflate_alloc_compressor(compressionLevel);
}
const void *uncompressed_data = str.data(); const void *uncompressed_data = str.data();
size_t uncompressed_size = str.size(); size_t uncompressed_size = str.size();
@ -35,18 +41,25 @@ namespace ix
max_compressed_size = libdeflate_gzip_compress_bound(compressor, max_compressed_size = libdeflate_gzip_compress_bound(compressor,
uncompressed_size); uncompressed_size);
compressed_data = malloc(max_compressed_size); {
Bench bench("alloc data");
compressed_data = malloc(max_compressed_size);
}
if (compressed_data == NULL) if (compressed_data == NULL)
{ {
return std::string(); return std::string();
} }
actual_compressed_size = libdeflate_gzip_compress( {
compressor, Bench bench("compressing data");
uncompressed_data, actual_compressed_size = libdeflate_gzip_compress(
uncompressed_size, compressor,
compressed_data, uncompressed_data,
max_compressed_size); uncompressed_size,
compressed_data,
max_compressed_size);
}
if (actual_compressed_size == 0) if (actual_compressed_size == 0)
{ {
@ -57,8 +70,15 @@ namespace ix
libdeflate_free_compressor(compressor); libdeflate_free_compressor(compressor);
std::string out; std::string out;
out.append(reinterpret_cast<char*>(compressed_data), actual_compressed_size); {
free(compressed_data); Bench bench("append data");
out.append(reinterpret_cast<char*>(compressed_data), actual_compressed_size);
}
{
Bench bench("free data");
free(compressed_data);
}
return out; return out;
#else #else

View File

@ -1150,6 +1150,7 @@ namespace ix
std::string compressedBytes; std::string compressedBytes;
spdlog::info("compressing {} times", runCount);
std::vector<uint64_t> durations; std::vector<uint64_t> durations;
{ {
Bench bench("compressing file"); Bench bench("compressing file");
@ -1165,7 +1166,7 @@ namespace ix
size_t medianIdx = durations.size() / 2; size_t medianIdx = durations.size() / 2;
uint64_t medianRuntime = durations[medianIdx]; uint64_t medianRuntime = durations[medianIdx];
spdlog::info("compressing file in {}", medianRuntime); spdlog::info("median runtime to compress file: {}", medianRuntime);
} }
std::string outputFilename(filename); std::string outputFilename(filename);