mirror of
https://github.com/simon987/fastimagehash.git
synced 2025-12-16 07:39:02 +00:00
Initial commit (squashed)
This commit is contained in:
83
benchmark.cpp
Normal file
83
benchmark.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include "fastimagehash.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
char *filepath;
|
||||
|
||||
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(buf, size, 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(buf, size, state.range(), 0);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void BM_dhash(benchmark::State &state) {
|
||||
|
||||
size_t size;
|
||||
void *buf = load_test_file(&size);
|
||||
|
||||
for (auto _ : state) {
|
||||
dhash(buf, size, state.range());
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void BM_ahash(benchmark::State &state) {
|
||||
|
||||
size_t size;
|
||||
void *buf = load_test_file(&size);
|
||||
|
||||
for (auto _ : state) {
|
||||
ahash(buf, size, state.range());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
filepath = argv[1];
|
||||
argv[1] = argv[0];
|
||||
|
||||
argc -= 1;
|
||||
|
||||
::benchmark::Initialize(&argc, argv + 1);
|
||||
::benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
Reference in New Issue
Block a user