mirror of
https://github.com/st3fan/ewm.git
synced 2025-01-03 09:29:45 +00:00
Fixes #170 - Create a benchmark for tty.c
This commit is contained in:
parent
a38375554d
commit
699072aa86
12
src/Makefile
12
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 $@
|
||||
|
||||
|
59
src/tty_test.c
Normal file
59
src/tty_test.c
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user