#define _POSIX_C_SOURCE 200809L #include "kryon.h" #include "kry_inject.h" #include #include #include #include /* This is intentionally a retained-tree test rather than a TextField unit * microbenchmark: each sample declares every field, reconciles the tree, * routes real synthetic input, and updates the complete UI. Rendering is * separately timed by KRYON_FRAME_TRACE in a real application: the headless * test environment has no graphics context. */ enum { WARMUP = 250, SAMPLES = 3000, FIELD_COUNT = 4, FIELD_SIZE = 512 }; typedef struct Field { char text[FIELD_SIZE]; int cursor; int focused; int focus_id; float y; } Field; static Field fields[FIELD_COUNT] = { { .focus_id = 101, .y = 20 }, { .focus_id = 102, .y = 70 }, { .focus_id = 103, .y = 120 }, { .focus_id = 104, .y = 170 } }; static UIKey screen_key = 1; static double now_us(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return (double)t.tv_sec*1e6+(double)t.tv_nsec/1e3; } static int cmp_double(const void *a, const void *b) { double x=*(const double *)a,y=*(const double *)b; return (x>y)-(x= 0) { samples[i] = elapsed; total += elapsed; } } UIGetTreeNodes(&after); qsort(samples, SAMPLES, sizeof(*samples), cmp_double); printf("{\"runtime\":\"retained-core-c\",\"scenario\":\"%s\",\"fields\":%d,\"samples\":%d,\"warmup\":%d,\"p50_us\":%.3f,\"p95_us\":%.3f,\"p99_us\":%.3f,\"max_us\":%.3f,\"mean_us\":%.3f,\"full_frame_budget_us\":4000,\"input_budget_p99_us\":1000,\"node_delta\":%d,\"mismatches\":%d}\n", name, FIELD_COUNT, SAMPLES, WARMUP, samples[SAMPLES/2], samples[(SAMPLES*95)/100], samples[(SAMPLES*99)/100], samples[SAMPLES-1], total/SAMPLES, after-before, wrong); i = samples[(SAMPLES*99)/100] >= 1000.0 || after != before || wrong; free(samples); return i; } int main(int argc, char **argv) { (void)argc; (void)argv; int failed = 0; failed |= run_scenario("typing_burst"); failed |= run_scenario("backspace"); failed |= run_scenario("selection_replace"); failed |= run_scenario("tab_traversal"); failed |= run_scenario("idle_frame"); return failed ? 1 : 0; }