Merged
Conversation
A significant performance increase can be had by copying the first row to all other rows.
Owner
|
@smalltimewizard did you review the performance gain? Please, could you provide more info, and example or some metrics? |
Author
|
The following code performs a barebones test. // gcc main.c -o bench.exe -I "./include" -L "./lib" -lraylib -lgdi32 -lwinmm
#include <stdio.h>
#include <time.h>
#include "raylib.h"
#define GRIDW 64
#define GRIDH 64
#define CELLW 24
#define CELLH 24
#define RUNS 10000
int main(int argc, char* argv[]) {
SetTraceLogLevel(LOG_WARNING);
Image benchimage = {0};
benchimage = GenImageColor(GRIDW * CELLW, GRIDH * CELLH, (Color){0,0,0,0}); // Set transparent image of the proper size
ImageFormat(&benchimage, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
double timerstart = (double) clock();
int runs = 0;
while (runs < RUNS) {
for (int i = 0; i < GRIDW * GRIDH; i++) {
ImageDrawRectangleRec(&benchimage, (Rectangle){(i % GRIDW) * CELLW, (i / GRIDW) * CELLH, CELLW, CELLH}, (Color){GetRandomValue(0,255), GetRandomValue(0,255), GetRandomValue(0,255), 255});
}
runs++;
}
printf("%d calls took %f seconds to run.", GRIDW * GRIDH * RUNS, (double) (clock() - timerstart)/CLOCKS_PER_SEC);
return 0;
};This is 40,960,000 calls, fully replacing a 64x64 grid of 24x24 randomly-colored squares 10,000 times. |
Author
Owner
|
@smalltimewizard thank you very much for the benchmark, reviewed and verified that the improvement is considerable, it went from 160 seconds to 14 seconds on my system (11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, Windows 10 Pro 64bit, compiled with GCC 12.2.0). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


A significant performance increase can be had by copying the first row to all other rows.