From 699072aa8619a6202d08efe3cec745247be0f1fe Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Sun, 1 Oct 2017 11:08:23 -0400 Subject: [PATCH] Fixes #170 - Create a benchmark for tty.c --- src/Makefile | 12 ++++++++-- src/tty_test.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/tty_test.c diff --git a/src/Makefile b/src/Makefile index 1b95ecb..817da3d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -56,6 +56,11 @@ SCR_TEST_SOURCES=cpu.c ins.c mem.c fmt.c two.c scr.c dsk.c chr.c alc.c utl.c scr SCR_TEST_OBJECTS=$(SCR_TEST_SOURCES:.c=.o) SCR_TEST_LIBS=-lSDL2 $(LUA_LIBS) +TTY_TEST_EXECUTABLE=tty_test +TTY_TEST_SOURCES=cpu.c ins.c mem.c fmt.c one.c tty.c pia.c chr.c utl.c tty_test.c lua.c +TTY_TEST_OBJECTS=$(TTY_TEST_SOURCES:.c=.o) +TTY_TEST_LIBS=-lSDL2 $(LUA_LIBS) + CPU_BENCH=cpu_bench CPU_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c utl.c cpu_bench.c lua.c CPU_BENCH_OBJECTS=$(CPU_BENCH_SOURCES:.c=.o) @@ -66,10 +71,10 @@ MEM_BENCH_SOURCES=cpu.c ins.c mem.c fmt.c utl.c mem_bench.c lua.c MEM_BENCH_OBJECTS=$(MEM_BENCH_SOURCES:.c=.o) MEM_BENCH_LIBS=$(LUA_LIBS) -all: $(EWM_SOURCES) $(EWM_EXECUTABLE) $(CPU_TEST_SOURCES) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) +all: $(EWM_SOURCES) $(EWM_EXECUTABLE) $(CPU_TEST_SOURCES) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_EXECUTABLE) $(TTY_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) clean: - rm -f $(EWM_OBJECTS) $(EWM_EXECUTABLE) $(CPU_TEST_OBJECTS) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) + rm -f $(EWM_OBJECTS) $(EWM_EXECUTABLE) $(CPU_TEST_OBJECTS) $(CPU_TEST_EXECUTABLE) $(SCR_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE) $(TTY_TEST_EXECUTABLE) $(CPU_BENCH) $(MEM_BENCH) $(EWM_EXECUTABLE): $(EWM_OBJECTS) $(CC) $(LDFLAGS) $(EWM_OBJECTS) $(EWM_LIBS) -o $@ @@ -80,6 +85,9 @@ $(CPU_TEST_EXECUTABLE): $(CPU_TEST_OBJECTS) $(SCR_TEST_EXECUTABLE): $(SCR_TEST_OBJECTS) $(CC) $(LDFLAGS) $(SCR_TEST_OBJECTS) $(SCR_TEST_LIBS) -o $@ +$(TTY_TEST_EXECUTABLE): $(TTY_TEST_OBJECTS) + $(CC) $(LDFLAGS) $(TTY_TEST_OBJECTS) $(TTY_TEST_LIBS) -o $@ + $(CPU_BENCH): $(CPU_BENCH_OBJECTS) $(CC) $(LDFLAGS) $(CPU_BENCH_OBJECTS) $(CPU_BENCH_LIBS) -o $@ diff --git a/src/tty_test.c b/src/tty_test.c new file mode 100644 index 0000000..d153e10 --- /dev/null +++ b/src/tty_test.c @@ -0,0 +1,59 @@ + +#include +#include + +#include "one.h" +#include "tty.h" + +void test(struct ewm_tty_t *tty) { + // TODO Setup + + for (int i = 0; i < (EWM_ONE_TTY_ROWS * EWM_ONE_TTY_COLUMNS); i++) { + tty->screen_buffer[i] = 32 + (rand() % 64); + } + + Uint64 start = SDL_GetPerformanceCounter(); + for (int i = 0; i < 1000; i++) { + SDL_SetRenderDrawColor(tty->renderer, 0, 0, 0, 255); + SDL_RenderClear(tty->renderer); + ewm_tty_refresh(tty, 1, EWM_ONE_FPS); + SDL_RenderPresent(tty->renderer); + } + Uint64 now = SDL_GetPerformanceCounter(); + double total = (double)((now - start)*1000) / SDL_GetPerformanceFrequency(); + double per_screen = total / 1000.0; + + printf("%-20s %.3f/refresh\n", "tty", per_screen); +} + +int main() { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) < 0) { + fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); + return 1; + } + + SDL_Window *window = SDL_CreateWindow("ewm - tty_test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 280*3, 192*3, SDL_WINDOW_SHOWN); + if (window == NULL) { + fprintf(stderr, "Failed create window: %s\n", SDL_GetError()); + return 1; + } + + SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (renderer == NULL) { + fprintf(stderr, "Failed to create renderer: %s\n", SDL_GetError()); + return 1; + } + + SDL_RenderSetLogicalSize(renderer, 280*3, 192*3); + + sleep(3); + + struct ewm_one_t *one = ewm_one_create(EWM_ONE_MODEL_APPLE1, renderer); + test(one->tty); + + SDL_DestroyWindow(window); + SDL_DestroyRenderer(renderer); + SDL_Quit(); + + return 0; +}