diff --git a/benchmarks/build.sh b/benchmarks/build.sh new file mode 100755 index 0000000..c53d7ea --- /dev/null +++ b/benchmarks/build.sh @@ -0,0 +1 @@ +gcc -L/usr/local/lib -I/usr/local/include random_triangles.c -o random_triangles -lSDL diff --git a/benchmarks/random_triangles.c b/benchmarks/random_triangles.c new file mode 100644 index 0000000..3b82789 --- /dev/null +++ b/benchmarks/random_triangles.c @@ -0,0 +1,53 @@ +#include "SDL/SDL.h" +#include + +int main(int argc, char **argv) { + SDL_Init(SDL_INIT_EVERYTHING); + + SDL_Window* window = SDL_CreateWindow("demo window", 100, 100, 512, 512, 0); + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); + + int i; + SDL_Point p1, p2, p3; + SDL_Event event; + + int start_time = SDL_GetTicks(); + int frames=0; + + int running=1; + + while(running) { + frames++; + if(frames == 1000) { + printf("FPS %f\n", (float)frames/(SDL_GetTicks()-start_time)*1000); + frames = 0; + start_time = SDL_GetTicks(); + } + + while(SDL_PollEvent(&event)) { + if(event.type == SDL_WINDOWEVENT) { + if(event.window.event == SDL_WINDOWEVENT_CLOSE) { + running=0; + } + } + } + + // draw + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); + + for(i=0; i < 20; ++i) { + SDL_SetRenderDrawColor(renderer, rand()%255, rand()%255, rand()%255, 255); + p1.x = rand()%512; + p1.y = rand()%512; + p2.x = rand()%512; + p2.y = rand()%512; + p3.x = rand()%512; + p3.y = rand()%512; + SDL_Point points[4] = { p1, p2, p3, p1 }; + SDL_RenderDrawLines(renderer, points, 4); + } + SDL_RenderPresent(renderer); + } +} diff --git a/demo/random_rectangles.py b/demo/random_rectangles.py index 74bd002..6ef6429 100755 --- a/demo/random_rectangles.py +++ b/demo/random_rectangles.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python import random from csdl.video import Rect from demo_utils import simple_timed_loop