Skip to content

Instantly share code, notes, and snippets.

@eXpl0it3r
Last active August 29, 2015 14:21
Show Gist options
  • Save eXpl0it3r/aa74c0d89505c8eb053b to your computer and use it in GitHub Desktop.
Save eXpl0it3r/aa74c0d89505c8eb053b to your computer and use it in GitHub Desktop.
Opening many windows and drawing to them
#include <SFML/Graphics.hpp>
#include <iostream>
unsigned int first = 0;
unsigned int second = 0;
std::size_t count = 50;
void run()
{
sf::CircleShape circle{10.f};
sf::RectangleShape rectangle{{60.f, 20.f }};
sf::RenderWindow window({800, 600}, "Minimal Example");
int x = 1;
while (x <= 2)
{
sf::Clock clock;
// Start timing
sf::Time startTime = clock.restart();
// "Clear" the window from previouly drawn graphics
window.clear(sf::Color::Black);
window.draw(circle);
window.draw(rectangle);
window.display();
// End timing
sf::Time endTime = clock.restart();
std::cout << x << ": " << endTime.asMicroseconds() << std::endl;
if(x == 1)
first += endTime.asMicroseconds();
else if(x == 2)
second += endTime.asMicroseconds();
++x;
}
}
int main()
{
for(std::size_t i = 0; i < count; ++i)
run();
std::cout << "1: " << static_cast<float>(first) / count << std::endl;
std::cout << "2: " << static_cast<float>(second) / count << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment