#include "../headers/common.h" #include "../headers/codecfactory.h" #include "../headers/caltime.h" #include "../headers/lr.h" #include "snappy.h" typedef uint64_t leco_type; int random(int m) { return rand() % m; } template static std::vector load_data_binary(const std::string& filename, bool print = true) { std::vector data; std::ifstream in(filename, std::ios::binary); if (!in.is_open()) { std::cerr << "unable to open " << filename << std::endl; exit(EXIT_FAILURE); } // Read size. uint64_t size; in.read(reinterpret_cast(&size), sizeof(uint64_t)); data.resize(size); // Read values. in.read(reinterpret_cast(data.data()), size * sizeof(T)); in.close(); return data; } template static std::vector load_data(const std::string& filename) { std::vector data; std::ifstream srcFile(filename, std::ios::in); if (!srcFile) { std::cout << "error opening source file." << std::endl; return data; } while (srcFile.good()) { T next; srcFile >> next; if (!srcFile.good()) { break; } data.emplace_back(next); } srcFile.close(); return data; } int main(int argc, const char *argv[]) { using namespace Codecset; std::string source_file = std::string(argv[1]); int blocks = atoi(argv[2]); int model_size = atoi(argv[3]); bool binary = atoi(argv[4]); std::ios::sync_with_stdio(false); // We pick a CODEC std::vector data; source_file = "../data/"+source_file; if(binary){ data = load_data_binary(source_file); } else{ data = load_data(source_file); } int N = data.size(); if (data.size() == 0) { std::cout << "Empty vector" << std::endl; return 0; } // std::sort(data.begin(),data.end()); int block_size = data.size() / blocks; blocks = data.size() / block_size; if (blocks * block_size < N) { blocks++; } int delta = 32; std::vector block_start_vec; std::vector start_index; std::vector seglen; int totalsize = 0; double start = getNow(); for (int i = 0; i < blocks; i++) { int block_length = block_size; if (i == blocks - 1) { block_length = N - (blocks - 1) * block_size; } // uint8_t *descriptor = (uint8_t *)malloc(block_length * sizeof(uint64_t)+1000); // uint8_t *res = descriptor; std::string compressed; int segment_size = snappy::Compress((char *)(data.data() + i * block_size), block_length * sizeof(leco_type), &compressed); // std::cout< recover(data.size()); double totaltime = 0.0; // std::cout << "decompress all!" << std::endl; int repeat = 10; start = getNow(); for (int iter = 0; iter < repeat; iter++) { for (int i = 0; i < blocks; i++) { int block_length = block_size; if (i == blocks - 1) { block_length = N - (blocks - 1) * block_size; } std::string uncomp_str; // const char* reover= reinterpret_cast(recover + block_size*i); snappy::Uncompress(block_start_vec[i].c_str(), seglen[i], &uncomp_str); // std::cout< } } end = getNow(); totaltime += (end - start); double da_ns = totaltime / (repeat * data.size()) * 1000000000; // std::cout << da_ns << std::endl; // std::cout << "random access decompress!" << std::endl; std::vector ra_pos; repeat = 1; for(int i=0;i buffer(data.size()); double randomaccesstime = 0.0; start = getNow(); uint32_t mark = 0; for (auto index : ra_pos) { std::string uncomp_str; snappy::Uncompress(block_start_vec[(int)index / block_size].c_str(), seglen[(int)index / block_size], &uncomp_str); leco_type tmpvalue; memcpy(&tmpvalue, uncomp_str.c_str() + (index % block_size) * sizeof(leco_type), sizeof(leco_type)); // std::cout<