我正在尝试压缩大量16位整数(通过相机获取),我想尽快压缩它。但是,在查看了几个选项后,似乎大多数库都针对32位数据进行了优化。 (例如https://github.com/lemire/FastPFor)
我也尝试过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。速度比效率更重要