-1
我試圖壓縮16位整數(通過相機獲取)的大數組,並且我想盡可能快地壓縮它。然而,在查看了幾個選項後,似乎大多數庫都針對32位數據進行了優化。 (例如https://github.com/lemire/FastPFor)16位整數陣列壓縮
我也試過Oroch庫(https://github.com/ademakov/Oroch),但它似乎並不像它的特別有效的..
#include <cstdlib>
#include <chrono>
#include <iostream>
#include <vector>
#include "oroch/varint.h"
unsigned long length = 1365ul*1531ul*1265ul;
using namespace std;
static vector<uint8_t> x;
static vector<uint16_t> img(length);
void *read_tiff(string filename,unsigned long length,vector<uint16_t> buffer)
{
FILE *ptr_file;
ptr_file = fopen(filename.c_str(),"rb");
printf("length of array: %lu\n",length);
rewind(ptr_file);
printf("ok here?");
uint16_t temp;
int k;
for (k=0;k<length;k++)
{
//printf("%d",k);
fread(&temp,2,1,ptr_file);
buffer[k] = temp;
}
fclose(ptr_file);
}
int main(){
cout<<"this is working!\n";
string dir;
dir = "somedir";
read_tiff(dir,length,img);
cout<<"reading successful";
auto start = chrono::high_resolution_clock::now();
size_t size = oroch::varint_codec<uint16_t>::space(img.begin(),img.end());
x.resize(size);
uint8_t *data = x.data();
oroch::varint_codec<uint16_t>::encode(data,img.begin(),img.end());
auto finish = chrono::high_resolution_clock::now();
auto time = chrono::duration_cast<chrono::milliseconds>(finish - start);
cout << "emcode time : " << time.count() << " ms" << std::endl;
return EXIT_SUCCESS;
}
是否有其他整數類型用戶友好的圖書館嗎?
p.s.速度比效率更重要