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 "IXBench.h"
#include <array>
#include <string.h>
@ -24,8 +25,13 @@ namespace ix
{
#ifdef IXWEBSOCKET_USE_DEFLATE
int compressionLevel = 6;
struct libdeflate_compressor *compressor =
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);
{
Bench bench("alloc data");
compressed_data = malloc(max_compressed_size);
}
if (compressed_data == NULL)
{
return std::string();
}
{
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;
{
Bench bench("append data");
out.append(reinterpret_cast<char*>(compressed_data), actual_compressed_size);
}
{
Bench bench("free data");
free(compressed_data);
}
return out;
#else

View File

@ -1150,6 +1150,7 @@ namespace ix
std::string compressedBytes;
spdlog::info("compressing {} times", runCount);
std::vector<uint64_t> 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);