So I started doing some more tests for optimization and I just cant figure it out.
This new code does some various tests. Its pretty self explanatory.
Whats interesting to me is that the same operation might take 20 times longer one run to the next. Here is my output:
https://legacy.sfmluploads.org/cache/pics/198_Capture.PNGTake a look at the last test. The one drawing 2000 1x1 pixel sprites.
In my output, the first 3 results are about 90 times slower than the following samples.
I just cant figure out why there would be such a large discrepancy in the numbers. Is there something going on under the hood that would contribute to this? Maybe my logic is just off? Maybe this is just normal? If anyone has any advice to optimize rendering I would love to hear it.
Here are the tests:
int main()
{
sf::Image image_1;
image_1.LoadFromFile("1x1.png");
sf::Sprite sprite_1;
sprite_1.SetImage(image_1);
sf::Image image_2048;
image_2048.LoadFromFile("2048x2048.png");
sf::Sprite sprite_2048;
sprite_2048.SetImage(image_2048);
sf::Image image_2048_2;
image_2048_2.LoadFromFile("2048x2048_2.png");
sf::Sprite sprite_2048_2;
sprite_2048_2.SetImage(image_2048_2);
float time = 0;
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Clock clock;
///////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<2000; i++)
{
App.Draw(sprite_2048);
}
App.Display();
time = clock.GetElapsedTime();
printf("draw one 2048x2048 2000 times: %f \n", time);
}
printf("\n\n");
///////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048);
App.Draw(sprite_2048_2);
}
App.Display();
time = clock.GetElapsedTime();
printf("draw two 2048x2048 alternating 1000 each: %f \n", time);
}
printf("\n\n");
///////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048);
}
for(int i=0; i<1000; i++)
{
App.Draw(sprite_2048_2);
}
App.Display();
time = clock.GetElapsedTime();
printf("draw two 2048x2048 batched 1000 each: %f \n", time);
}
printf("\n\n");
///////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=0; i<10; i++)
{
clock.Reset();
App.Clear();
for(int i=0; i<2000; i++)
{
App.Draw(sprite_1);
}
App.Display();
time = clock.GetElapsedTime();
printf("draw one 1x1 2000 times: %f \n", time);
}
printf("\n\n");
///////////////////////////////////////////////////////////////////////////////////////////////////////
int x;
std::cin>>x;
return EXIT_SUCCESS;
}