summaryrefslogtreecommitdiff
path: root/tests/benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmark.c')
-rw-r--r--tests/benchmark.c89
1 files changed, 52 insertions, 37 deletions
diff --git a/tests/benchmark.c b/tests/benchmark.c
index a685e8b..7687316 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -9,10 +9,11 @@
#include "yasl/yasl.h"
#include "yasl/loop.h"
-#include "common/loop.h"
+#include "yasl/timing.h"
+#include "yasl/native.h"
#include "common/input.h"
#if YASL_HAS_WAYLAND
-#include "wayland/internal.h"
+#include "yasl/native/wayland.h"
#endif
static inline uint64_t get_time_ns(void) {
@@ -22,63 +23,77 @@ static inline uint64_t get_time_ns(void) {
}
#if YASL_HAS_WAYLAND
-/* Benchmark 1: Surface Lookup in conn_surface_for */
+/* Benchmark 1: Public Wayland Surface Handle Lookup */
static void bench_surface_lookup(void) {
const int num_surfaces = 16;
const int lookups = 10000000;
- struct wayland_display c = {0};
- struct wayland_surface surfaces[num_surfaces];
- void *dummy_proxies[num_surfaces][16];
-
- for (int i = 0; i < num_surfaces; i++) {
- memset(&surfaces[i], 0, sizeof(surfaces[i]));
- memset(dummy_proxies[i], 0, sizeof(dummy_proxies[i]));
- surfaces[i].conn = &c;
- surfaces[i].surface = (struct wl_surface *)dummy_proxies[i];
- wl_proxy_set_user_data((struct wl_proxy *)dummy_proxies[i], &surfaces[i]);
- surfaces[i].conn_next = c.surfaces;
- c.surfaces = &surfaces[i];
+ struct yasl_display_spec spec = {
+ .app_id = "org.yasl.benchmark",
+ .backend = YASL_BACKEND_WAYLAND,
+ };
+ struct yasl_display *d = yasl_display_open(NULL, &spec);
+ struct yasl_surface *surfaces[num_surfaces];
+ memset(surfaces, 0, sizeof(surfaces));
+
+ if (d) {
+ for (int i = 0; i < num_surfaces; i++) {
+ struct yasl_surface_spec sspec = {
+ .title = "Benchmark",
+ .size = { .x = 320, .y = 240 },
+ };
+ surfaces[i] = yasl_surface_create_toplevel(d, &sspec);
+ }
}
- struct wl_surface *target = (struct wl_surface *)dummy_proxies[0];
-
uint64_t t0 = get_time_ns();
uintptr_t sum = 0;
for (int i = 0; i < lookups; i++) {
- struct wayland_surface *found = conn_surface_for(&c, target);
+ struct wl_surface *found = yasl_wayland_surface_get_wl_surface(surfaces[i % num_surfaces]);
sum += (uintptr_t)found;
}
uint64_t t1 = get_time_ns();
- printf("[1] conn_surface_for : %7.2f ms (%d lookups over %d surfaces, checksum=%lx)\n",
+ printf("[1] wayland_surface_lookup : %7.2f ms (%d lookups over %d surfaces, checksum=%lx)\n",
(double)(t1 - t0) / 1e6, lookups, num_surfaces, (unsigned long)sum);
+
+ if (d) {
+ for (int i = 0; i < num_surfaces; i++) {
+ if (surfaces[i]) yasl_surface_destroy(surfaces[i]);
+ }
+ yasl_display_close(d);
+ }
}
-/* Benchmark 2: Wayland Output & Refresh Tracking */
+/* Benchmark 2: Public Surface Geometry & Refresh Timing */
static void bench_output_follow(void) {
const int iters = 10000000;
- struct wayland_display c = {0};
- struct wl_conn_output outs[4];
- for (int i = 0; i < 4; i++) {
- memset(&outs[i], 0, sizeof(outs[i]));
- outs[i].mask = 1ull << i;
- outs[i].scale = i + 1;
- outs[i].refresh_ns = 16666666 / (i + 1);
- outs[i].next = (i < 3) ? &outs[i + 1] : NULL;
+ struct yasl_display_spec spec = {
+ .app_id = "org.yasl.benchmark",
+ .backend = YASL_BACKEND_WAYLAND,
+ };
+ struct yasl_display *d = yasl_display_open(NULL, &spec);
+ struct yasl_surface *s = NULL;
+ if (d) {
+ struct yasl_surface_spec sspec = {
+ .title = "Benchmark",
+ .size = { .x = 320, .y = 240 },
+ };
+ s = yasl_surface_create_toplevel(d, &sspec);
}
- c.outputs = &outs[0];
- struct wayland_surface w = {0};
- w.conn = &c;
- w.outputs = 0x3;
- w.pending_scale_120 = 2 * YASL_SCALE_UNIT;
- w.frac_scale = (struct wp_fractional_scale_v1 *)1;
uint64_t t0 = get_time_ns();
+ uint64_t sum = 0;
for (int i = 0; i < iters; i++) {
- surface_follow_outputs(&w);
+ struct yasl_geometry geom = yasl_surface_geometry(s);
+ struct yasl_timing timing = yasl_surface_timing(s);
+ int dev = yasl_scale_to_device(320.0, geom.scale_120);
+ sum += (uint64_t)dev + timing.refresh_ns;
}
uint64_t t1 = get_time_ns();
- printf("[2] surface_follow_outputs : %7.2f ms (%d iterations over outputs list)\n",
- (double)(t1 - t0) / 1e6, iters);
+ printf("[2] surface_geometry_timing : %7.2f ms (%d iterations, checksum=%llu)\n",
+ (double)(t1 - t0) / 1e6, iters, (unsigned long long)sum);
+
+ if (s) yasl_surface_destroy(s);
+ if (d) yasl_display_close(d);
}
#endif