From a0fe0933c0e4281bb18212589df2f08a95efeb54 Mon Sep 17 00:00:00 2001 From: Azim Afroozeh Date: Thu, 18 Jul 2024 14:57:01 +0200 Subject: [PATCH] extend the simple compress example to 1, 1025, 1024 * 100 tuples --- example/simple_compress.cpp | 73 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/example/simple_compress.cpp b/example/simple_compress.cpp index e680f7f..ad3ca90 100644 --- a/example/simple_compress.cpp +++ b/example/simple_compress.cpp @@ -1,46 +1,45 @@ #include "alp.hpp" #include "helper.hpp" +#include #include +#include +using namespace alp; int main() { - size_t tuples_count = (1024 * 100); - size_t out_buffer_size = - (tuples_count * sizeof(double)) + 8096; // We leave some headroom in case of negative compression - size_t uncompressed_size = tuples_count * sizeof(double); - - double in[tuples_count]; - uint8_t out[out_buffer_size]; - example::fill_random_data(in, tuples_count, 2); - - /* - * Compress - */ - alp::AlpCompressor compressor = alp::AlpCompressor(); - printf("Compressing with ALP...\n"); - compressor.compress(in, tuples_count, out); - size_t compressed_size = compressor.get_size(); - double compression_ratio = (double)uncompressed_size / compressed_size; - printf("Uncompressed size (in bytes): %zu\n", uncompressed_size); - printf("Compressed size (in bytes): %zu\n", compressed_size); - printf("Compression Ratio: %f\n\n", compression_ratio); - - /* - * Decompress - */ - size_t decompressed_buffer_size = - alp::AlpApiUtils::align_value(tuples_count); - double decompressed[decompressed_buffer_size]; - alp::AlpDecompressor decompressor = alp::AlpDecompressor(); - printf("Decompressing with ALP...\n"); - decompressor.decompress(out, tuples_count, decompressed); - - /* - * Validity Test - */ - for (size_t i = 0; i < tuples_count; i++) { - assert(in[i] == decompressed[i]); + constexpr std::array n_tup_vec {1, 1025, 1024 * 100}; + for (const auto n_tup : n_tup_vec) { + size_t buffer_sz = n_tup * sizeof(double) + 8096; // We leave some headroom in case of negative compression + size_t original_sz = n_tup * sizeof(double); + + double in[n_tup]; + uint8_t out[buffer_sz]; + example::fill_random_data(in, n_tup, 2); + + // compress + auto compressor = AlpCompressor(); + compressor.compress(in, n_tup, out); + + // decompress + auto decompressed_buffer_size = AlpApiUtils::align_value(n_tup); + double decompressed[decompressed_buffer_size]; + auto decompressor = AlpDecompressor(); + decompressor.decompress(out, n_tup, decompressed); + + // check the correctnes + for (size_t i = 0; i < n_tup; i++) { + assert(in[i] == decompressed[i]); + } + + // print result + size_t compressed_size = compressor.get_size(); + double compression_ratio = static_cast(original_sz) / static_cast(compressed_size); + + std::cout << "-- Compressing " << n_tup << " random values with ALP" << std::endl; + std::cout << "-- Uncompressed size: " << original_sz << " bytes" << std::endl; + std::cout << "-- Compressed size: " << compressed_size << " bytes" << std::endl; + std::cout << "-- Compression ratio: " << compression_ratio << std::endl; + std::cout << "-----" << std::endl; } - printf("OK\n"); return 0; }