summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xyuvbench/build-linux-x86_64-gcc.sh8
-rw-r--r--yuvbench/kbench.h14
-rw-r--r--yuvbench/yuvbench.c24
-rw-r--r--yuvbench/yuvbench.h1
-rw-r--r--yuvbench/yuvbench_libyuv.c21
5 files changed, 58 insertions, 10 deletions
diff --git a/yuvbench/build-linux-x86_64-gcc.sh b/yuvbench/build-linux-x86_64-gcc.sh
index 555a195..19d8784 100755
--- a/yuvbench/build-linux-x86_64-gcc.sh
+++ b/yuvbench/build-linux-x86_64-gcc.sh
@@ -1,7 +1,9 @@
#!/bin/sh
-CFLAGS="-Wall -Wextra -Wpedantic -O3 -g -DYUVBENCH_BAD"
-LFLAGS=""
+CFLAGS="-Wall -Wextra -Wpedantic -O3 -g -DYUVBENCH_BAD -DYUVBENCH_LIBYUV -DYUVBENCH_SWSCALE"
+LFLAGS="$(pkg-config --libs libswscale) -lyuv"
mkdir -p build
gcc -o build/yuvbench.o $CFLAGS -c ./yuvbench.c
gcc -o build/yuvbench_bad.o $CFLAGS -c ./yuvbench_bad.c
-gcc -o build/yuvbench $LFLAGS build/yuvbench.o build/yuvbench_bad.o
+gcc -o build/yuvbench_libyuv.o $CFLAGS -c ./yuvbench_libyuv.c
+gcc -o build/yuvbench_swscale.o $CFLAGS $(pkg-config --cflags libswscale) -c ./yuvbench_swscale.c
+gcc -o build/yuvbench $LFLAGS build/yuvbench.o build/yuvbench_bad.o build/yuvbench_libyuv.o build/yuvbench_swscale.o
diff --git a/yuvbench/kbench.h b/yuvbench/kbench.h
index c5d4149..42ec646 100644
--- a/yuvbench/kbench.h
+++ b/yuvbench/kbench.h
@@ -9,6 +9,10 @@ double KBenchElapsedTime(uintptr_t t0, uintptr_t t1);
#ifdef KBENCH_IMPLEMENTATION
+#ifdef __linux__
+#include <time.h>
+#endif
+
uintptr_t KBenchTS(void)
{
uintptr_t result = 0;
@@ -16,6 +20,12 @@ uintptr_t KBenchTS(void)
#if defined(__APPLE__) && defined(__clang__) && defined(__aarch64__)
__asm__ volatile("mrs %0, CNTVCT_EL0" : "=r"(result) :: "memory");
#endif
+ // linux: use clock_gettime
+#if defined(__linux__)
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ result = (uintptr_t)ts.tv_sec * 1e9 + (uintptr_t)ts.tv_nsec;
+#endif
return result;
}
@@ -35,6 +45,10 @@ double KBenchElapsedTime(uintptr_t t0, uintptr_t t1)
__asm__ volatile("mrs %0, CNTFRQ_EL0" : "=r"(cntfreq_el0) :: "memory");
val = (double)elapsed / (double)cntfreq_el0;
#endif
+ // linux: use clock_gettime
+#if defined(__linux__) && defined(__GNUC__) && defined(__amd64__)
+ val = (double)elapsed / 1e9;
+#endif
return val;
}
diff --git a/yuvbench/yuvbench.c b/yuvbench/yuvbench.c
index 095104e..3a92371 100644
--- a/yuvbench/yuvbench.c
+++ b/yuvbench/yuvbench.c
@@ -9,6 +9,9 @@ Backend yuvbench_accelerate(void);
#ifdef YUVBENCH_BAD
Backend yuvbench_bad(void);
#endif
+#ifdef YUVBENCH_LIBYUV
+Backend yuvbench_libyuv(void);
+#endif
#ifdef YUVBENCH_SWSCALE
Backend yuvbench_swscale(void);
#endif
@@ -44,14 +47,14 @@ static void run_backend(Backend b)
return;
}
- printf("running warnups...\n");
- int warmup = 20;
+ printf(" running warnups...\n");
+ int warmup = 100;
for (int i = 0; i < warmup; ++i) {
b.convert_fn(&ctx);
}
- printf("testing...\n");
- int tests = 1000;
+ printf(" testing...\n");
+ int tests = 2500;
double* tests_table = calloc(tests, sizeof(double)); assert(tests_table);
for (int i = 0; i < tests; ++i) {
uintptr_t t0 = KBenchTS();
@@ -79,9 +82,9 @@ static void run_backend(Backend b)
}
ts_avg += (tests_table[i] / (double)tests);
}
- printf("min result: %fms\n", ts_min * 1000.0f);
- printf("max result: %fms\n", ts_max * 1000.0f);
- printf("avg result: %fms\n", ts_avg * 1000.0f);
+ printf(" min result: %fms\n", ts_min * 1000.0f);
+ printf(" max result: %fms\n", ts_max * 1000.0f);
+ printf(" avg result: %fms\n", ts_avg * 1000.0f);
if (G.show) {
@@ -186,12 +189,19 @@ int main(int argc, char** argv)
G.out_buf = calloc(1, G.out_len);
#ifdef YUVBENCH_ACCELERATE
+ printf("YUVBENCH_ACCELERATE\n");
run_backend(yuvbench_accelerate());
#endif
#ifdef YUVBENCH_BAD
+ printf("YUVBENCH_BAD\n");
run_backend(yuvbench_bad());
#endif
+#ifdef YUVBENCH_LIBYUV
+ printf("YUVBENCH_LIBYUV\n");
+ run_backend(yuvbench_libyuv());
+#endif
#ifdef YUVBENCH_SWSCALE
+ printf("YUVBENCH_SWSCALE\n");
run_backend(yuvbench_swscale());
#endif
}
diff --git a/yuvbench/yuvbench.h b/yuvbench/yuvbench.h
index ba6711a..0abdf15 100644
--- a/yuvbench/yuvbench.h
+++ b/yuvbench/yuvbench.h
@@ -4,6 +4,7 @@
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/yuvbench/yuvbench_libyuv.c b/yuvbench/yuvbench_libyuv.c
new file mode 100644
index 0000000..64da249
--- /dev/null
+++ b/yuvbench/yuvbench_libyuv.c
@@ -0,0 +1,21 @@
+#include "yuvbench.h"
+
+#include <libyuv.h>
+#include <libyuv/convert_argb.h>
+
+static bool yuvbench_libyuv_convert(Ctx* ctx)
+{
+ const uint32_t w = ctx->inp_w;
+ const uint32_t h = ctx->inp_h;
+ const uint8_t* Y = (const uint8_t*)ctx->inp_buf;
+ const uint8_t* Cb = Y + (w * h);
+ const uint8_t* Cr = Cb + (w / 2 * h / 2);
+ return I420ToRAW(Y, w, Cb, w / 2, Cr, w / 2, ctx->out_buf, w * 3, w, h) == 0;
+}
+
+Backend yuvbench_libyuv(void)
+{
+ Backend b = { 0 };
+ b.convert_fn = yuvbench_libyuv_convert;
+ return b;
+}