libragephoto: add benchmark to C implementation
CMakeLists.txt: update RAGEPHOTO_BENCHMARK description RagePhoto.c: add benchmark RagePhoto.cpp: change benchmark clock from std::chrono::high_resolution_clock to std::chrono::steady_clock
This commit is contained in:
parent
6046b7213a
commit
1b7b3c977b
3 changed files with 20 additions and 3 deletions
|
@ -69,7 +69,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# RagePhoto Benchmark
|
# RagePhoto Benchmark
|
||||||
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark (C++ only)" OFF)
|
option(RAGEPHOTO_BENCHMARK "Build with libragephoto benchmark" OFF)
|
||||||
|
|
||||||
# RagePhoto API
|
# RagePhoto API
|
||||||
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
|
option(RAGEPHOTO_C_API "Build libragephoto with C API support" ON)
|
||||||
|
|
|
@ -22,6 +22,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef RAGEPHOTO_BENCHMARK
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(UNICODE_ICONV)
|
#if defined(UNICODE_ICONV)
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
#elif defined(UNICODE_WINCVT)
|
#elif defined(UNICODE_WINCVT)
|
||||||
|
@ -217,6 +221,11 @@ RagePhotoData* ragephoto_getphotodata(ragephoto_t instance_t)
|
||||||
|
|
||||||
bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t length)
|
bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser, const char *data, size_t length)
|
||||||
{
|
{
|
||||||
|
#ifdef RAGEPHOTO_BENCHMARK
|
||||||
|
struct timespec benchmark_parse_start;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &benchmark_parse_start);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Avoid data conflicts
|
// Avoid data conflicts
|
||||||
ragephotodata_clear(rp_data);
|
ragephotodata_clear(rp_data);
|
||||||
|
|
||||||
|
@ -522,6 +531,14 @@ bool ragephotodata_load(RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RAGEPHOTO_BENCHMARK
|
||||||
|
struct timespec benchmark_parse_end;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &benchmark_parse_end);
|
||||||
|
const uint64_t benchmark_ns = (UINT64_C(1000000000) * benchmark_parse_end.tv_sec + benchmark_parse_end.tv_nsec) -
|
||||||
|
(UINT64_C(1000000000) * benchmark_parse_start.tv_sec + benchmark_parse_start.tv_nsec);
|
||||||
|
printf("Benchmark: %" PRIu64 "ns\n", benchmark_ns);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef RAGEPHOTO_DEBUG
|
#ifdef RAGEPHOTO_DEBUG
|
||||||
printf("header: %s\n", rp_data->header);
|
printf("header: %s\n", rp_data->header);
|
||||||
printf("headerSum: %" PRIu32 "\n", rp_data->headerSum);
|
printf("headerSum: %" PRIu32 "\n", rp_data->headerSum);
|
||||||
|
|
|
@ -219,7 +219,7 @@ RagePhotoData* RagePhoto::data()
|
||||||
bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
|
bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, RagePhotoFormatParser *rp_parser)
|
||||||
{
|
{
|
||||||
#ifdef RAGEPHOTO_BENCHMARK
|
#ifdef RAGEPHOTO_BENCHMARK
|
||||||
auto benchmark_parse_start = std::chrono::high_resolution_clock::now();
|
auto benchmark_parse_start = std::chrono::steady_clock::now();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Avoid data conflicts
|
// Avoid data conflicts
|
||||||
|
@ -541,7 +541,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RAGEPHOTO_BENCHMARK
|
#ifdef RAGEPHOTO_BENCHMARK
|
||||||
auto benchmark_parse_end = std::chrono::high_resolution_clock::now();
|
auto benchmark_parse_end = std::chrono::steady_clock::now();
|
||||||
auto benchmark_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_parse_end - benchmark_parse_start);
|
auto benchmark_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark_parse_end - benchmark_parse_start);
|
||||||
std::cout << "Benchmark: " << benchmark_ns.count() << "ns" << std::endl;
|
std::cout << "Benchmark: " << benchmark_ns.count() << "ns" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue