diff --git a/README.md b/README.md index 220f704..3e27869 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ - [read_keys_SH3.py](read_keys_SH3.py) Scan key matrix and return key name(deprecated) - [read_keys_SH3.c](read_keys_SH3.c) Scan key matrix and return key name rewritten with C. nice performance - [x1](x1) Executable to analyze `[JHSBA]1` gen + - [lcdbench](lcdbench) Benchmark fb0 fill and show results ### License diff --git a/lcdbench/Makefile b/lcdbench/Makefile new file mode 100644 index 0000000..4dd6594 --- /dev/null +++ b/lcdbench/Makefile @@ -0,0 +1,11 @@ +CC?=arm-linux-gnueabi-gcc + +all: lcdbench + +.PHONY: +clean: + rm -f lcdbench + +lcdbench: lcdbench.c + $(CC) $< -o $@ + diff --git a/lcdbench/lcdbench.c b/lcdbench/lcdbench.c new file mode 100644 index 0000000..ba16a79 --- /dev/null +++ b/lcdbench/lcdbench.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +const int width = 800; +const int height = 480; + +// 1 loop = 2 draws +// 30 loop = 60 draws = 1 sec (60 fps) +const int nloop = 30 * 3; + +struct timespec diff(struct timespec start, struct timespec end); + +int main(void) { + FILE *f; + uint16_t buf1[width * height]; //RGB565 + uint16_t buf2[width * height]; + struct timespec ts1, ts2, d; + int i, j; + float elapsed; + + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + buf1[i * width + j] = (i << 8) + j; + buf2[i * width + j] = ~((i << 8) + j); + } + } + + f = fopen("/dev/fb0", "w"); + if (f == NULL) { + printf("Could not open /dev/fb0\n"); + return 1; + } + + clock_gettime(CLOCK_MONOTONIC, &ts1); + for (j = 0; j < nloop; j++) { + fwrite(buf1, sizeof(buf1), 1, f); + fseek(f, 0, SEEK_SET); + fwrite(buf2, sizeof(buf2), 1, f); + fseek(f, 0, SEEK_SET); + } + clock_gettime(CLOCK_MONOTONIC, &ts2); + + d = diff(ts1, ts2); + elapsed = (float)d.tv_sec + ((float)d.tv_nsec * 1e-9); + printf("Frames: %d\n", nloop * 2); + printf("Elapsed: %f\n", elapsed); + printf("Frames per second: %f\n", (float)(nloop * 2) / elapsed); +} + +// https://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/ +struct timespec diff(struct timespec start, struct timespec end) { + struct timespec temp; + if ((end.tv_nsec-start.tv_nsec)<0) { + temp.tv_sec = end.tv_sec-start.tv_sec-1; + temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; + } else { + temp.tv_sec = end.tv_sec-start.tv_sec; + temp.tv_nsec = end.tv_nsec-start.tv_nsec; + } + return temp; +}