Manual loop unrolling

This commit is contained in:
Carlos Sanchez 2024-07-22 20:49:30 -04:00
parent 4768169ea2
commit 4db50f3f73

10
main.c
View File

@ -68,9 +68,9 @@ void drawTexInto(struct texture tex, struct texture buffer, struct rect texbound
i32 bufi = 3 * (x + buffer.width * y);
// You can get rid of this for loop for more performance, but probably
// not a big deal with -O3, it'll be unrolled
for(int i = 0; i < 3; i++) {
buffer.data[bufi + i] = tex.data[texi + i];
}
buffer.data[bufi] = tex.data[texi];
buffer.data[bufi + 1] = tex.data[texi + 1];
buffer.data[bufi + 2] = tex.data[texi + 2];
texx += stepx;
}
texy += stepy;
@ -98,10 +98,10 @@ int main() {
// We actually stretch a texture here
struct rect texrect = { 0, 0, 16, 16 };
struct rect bufrect = { 10, 13, 502, 509 };
struct rect bufrect = { 10, 10, 26, 26 };
clock_t start = clock();
for(int i = 0; i < 50; i++) { //overdraw factor
for(int i = 0; i < 50000; i++) { //overdraw factor
drawTexInto(tex, fb, texrect, bufrect);
}
clock_t end = clock();