#include#include void myFunction() { sf::sleep(sf::milliseconds(1000)); // simulate some heavy work } int main() { sf::Clock clock; myFunction(); sf::Time elapsed = clock.getElapsedTime(); // get the elapsed time std::cout << "Execution time: " << elapsed.asSeconds() << " seconds"; return 0; }
#includeBoth examples use SFML Time library to measure time intervals and manage application performance.#include void myFunction() { std::cout << "Hello World!" << std::endl; } int main() { sf::Clock clock; sf::Time interval = sf::seconds(1.0f); // set the interval to 1 second sf::Timer timer(interval); while (clock.getElapsedTime().asSeconds() < 10) // run for 10 seconds { timer.restart(); // restart the timer timer.wait(); // wait for the interval to finish myFunction(); // execute the function } return 0; }