115 lines
3.1 KiB
C++
115 lines
3.1 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <fstream>
|
|
#include <chrono>
|
|
#include <ctime>
|
|
#include <random>
|
|
|
|
#include "Compressor.hpp"
|
|
#include "Decompressor.hpp"
|
|
|
|
/*
|
|
• Prikažite graf ali tabelo kompresijskega razmerja
|
|
• Prikažite graf ali tabelo časa kompresije
|
|
• Prikažite graf ali tabelo časa dekompresije
|
|
• 5-10 stavkov ugotovitev
|
|
|
|
• Uporabite N števil
|
|
• N = {5, 50, 500, 5000}
|
|
• Naključno generirana števila na intervalu od 0 do 255
|
|
• Števila (na intervalu med 0 in 255), ki se med seboj razlikujejo za M
|
|
(razlika med sosednjima številoma je med 0 in M)
|
|
• M = {5, 10, 15, 30}
|
|
• Primer: N = 5 in M = 5; podatki: 135, 133, 136, 141, 141
|
|
|
|
|
|
55 53 53 53 53 53 10 10 11 11 11 11
|
|
|
|
00110111 000000 01011 10100101011 01000 000010 01010 11
|
|
*/
|
|
|
|
void genRandNum(int N, int M, std::vector<uint8_t> &vec)
|
|
{
|
|
|
|
std::random_device rand_dev;
|
|
std::mt19937 generator(rand_dev());
|
|
std::uniform_real_distribution<double> distr(0.0, 1.0);
|
|
|
|
uint8_t last = 0;
|
|
uint8_t max = 255;
|
|
uint8_t min = 0;
|
|
for (int i = 0; i < N; i++)
|
|
{
|
|
// std::cout << 25 + static_cast<int>((distr(generator) * (63 - 25 + 1))) << '\n';
|
|
float r = distr(generator);
|
|
uint8_t num = min + (r * (max - min));
|
|
max = num + M;
|
|
if (max > 255)
|
|
max = 255;
|
|
min = num - M;
|
|
if (min < 0)
|
|
min = 0;
|
|
vec.push_back(num);
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
auto start = std::chrono::system_clock::now();
|
|
std::vector<int> N = {5, 50, 500, 5000, 50000};
|
|
std::vector<int> M = {2, 5, 10, 15, 30, 60};
|
|
|
|
printf("N, \t M, \t Compress time, \tDecompress time, \t Input size, \t Output size, \t Compression ratio, \n");
|
|
|
|
for (size_t i = 0; i < N.size(); i++)
|
|
{
|
|
for (size_t j = 0; j < M.size(); j++)
|
|
{
|
|
|
|
std::vector<uint8_t> input;
|
|
genRandNum(N[i], M[j], input);
|
|
|
|
Compressor compressor;
|
|
|
|
auto startCom = std::chrono::system_clock::now();
|
|
compressor.compress(input);
|
|
auto endCom = std::chrono::system_clock::now();
|
|
|
|
Decompressor decompressor;
|
|
decompressor.bitReader.buffer.add_end(compressor.bitWriter.buffer.buffer, compressor.bitWriter.buffer.taken);
|
|
|
|
auto startDec = std::chrono::system_clock::now();
|
|
std::vector<uint8_t> output = decompressor.decompress();
|
|
auto endDec = std::chrono::system_clock::now();
|
|
|
|
for (size_t k = 0; k < input.size(); k++)
|
|
{
|
|
if (input[k] != output[k])
|
|
{
|
|
printf("Error\n");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
std::chrono::duration<double> compTime = endCom - startCom;
|
|
std::chrono::duration<double> decTime = endDec - startDec;
|
|
|
|
printf("%d,\t %d,\t ", N[i], M[j]);
|
|
printf("%f,\t\t", compTime.count());
|
|
printf("%f,\t\t ", decTime.count());
|
|
uint64_t input_size = N[i] * sizeof(uint8_t);
|
|
uint64_t output_size = compressor.bitWriter.buffer.taken;
|
|
printf("%ld,\t\t ", input_size);
|
|
printf("%ld,\t\t ", output_size);
|
|
printf("%f,\t", (float)input_size / (float)output_size);
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
auto end = std::chrono::system_clock::now();
|
|
std::chrono::duration<double> decTime = end - start;
|
|
printf("Total time: %f\n", decTime.count());
|
|
return 0;
|
|
}
|