mirror of
https://github.com/simon987/fastimagehash.git
synced 2025-04-10 14:16:49 +00:00
109 lines
2.2 KiB
C++
109 lines
2.2 KiB
C++
#include <benchmark/benchmark.h>
|
|
#include "fastimagehash.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
char *filepath;
|
|
uchar tmp[512];
|
|
|
|
void *load_test_file(size_t *buf_len) {
|
|
FILE *file = fopen(filepath, "rb");
|
|
|
|
fseek(file, 0, SEEK_END);
|
|
*buf_len = ftell(file);
|
|
fclose(file);
|
|
|
|
void *buf = malloc(*buf_len);
|
|
file = fopen(filepath, "rb");
|
|
fread(buf, *buf_len, 1, file);
|
|
return buf;
|
|
}
|
|
|
|
static void BM_phash(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
for (auto _ : state) {
|
|
phash_mem(buf, size, tmp, state.range(), 4);
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
static void BM_whash(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
for (auto _ : state) {
|
|
whash_mem(buf, size, tmp, state.range(), 0, "haar");
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
static void BM_dhash(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
for (auto _ : state) {
|
|
dhash_mem(buf, size, tmp, state.range());
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
static void BM_ahash(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
for (auto _ : state) {
|
|
ahash_mem(buf, size, tmp, state.range());
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
static void BM_mhash(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
for (auto _ : state) {
|
|
mhash_mem(buf, size, tmp, state.range());
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
static void BM_multi(benchmark::State &state) {
|
|
size_t size;
|
|
void *buf = load_test_file(&size);
|
|
|
|
multi_hash_t *m = multi_hash_create(state.range());
|
|
|
|
for (auto _ : state) {
|
|
multi_hash_file(filepath, m, state.range(), 4, 0, "haar");
|
|
}
|
|
|
|
multi_hash_destroy(m);
|
|
|
|
free(buf);
|
|
}
|
|
|
|
BENCHMARK(BM_phash)->ArgName("size")->Arg(8);
|
|
BENCHMARK(BM_whash)->ArgName("size")->Arg(8);
|
|
BENCHMARK(BM_dhash)->ArgName("size")->Arg(8);
|
|
BENCHMARK(BM_ahash)->ArgName("size")->Arg(8);
|
|
BENCHMARK(BM_mhash)->ArgName("size")->Arg(8);
|
|
BENCHMARK(BM_multi)->ArgName("size")->Arg(8);
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
filepath = argv[1];
|
|
argv[1] = argv[0];
|
|
|
|
argc -= 1;
|
|
|
|
::benchmark::Initialize(&argc, argv + 1);
|
|
::benchmark::RunSpecifiedBenchmarks();
|
|
}
|