Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <chrono>
- void load(std::string file, double& t) {
- sf::Texture tex;
- auto t1 = std::chrono::steady_clock::now();
- tex.loadFromFile("test.png");
- auto t2 = std::chrono::steady_clock::now();
- t = std::chrono::duration_cast<std::chrono::duration<double>>(t2-t1).count();
- }
- double mean(double a[], int size) {
- double tot = 0;
- for (int i = 0; i < size; i++) {
- tot += a[i];
- }
- return tot/(double)size;
- }
- int main() {
- // initializing
- const int no_tests = 20;
- double png[no_tests] = {0};
- double jpg[no_tests] = {0};
- double bmp[no_tests] = {0};
- // warm up the GPU
- std::cout << "Warming up...\n";
- {
- double dummy;
- load("test.png",dummy);
- load("test.jpg",dummy);
- load("test.bmp",dummy);
- }
- // do tests
- std::cout << "PNG test";
- for (int i = 0; i < no_tests; i++) {
- load("test.png", png[i]);
- std::cout << ".";
- }
- std::cout << "\n";
- std::cout << "JPG test";
- for (int i = 0; i < no_tests; i++) {
- load("test.jpg", jpg[i]);
- std::cout << ".";
- }
- std::cout << "\n";
- std::cout << "BMP test";
- for (int i = 0; i < no_tests; i++) {
- load("test.bmp", bmp[i]);
- std::cout << ".";
- }
- std::cout << "\n\n";
- // show results
- std::cout << "PNG time: " << mean(png,no_tests)*1000 << "ms\n";
- std::cout << "JPG time: " << mean(jpg,no_tests)*1000 << "ms\n";
- std::cout << "BMP time: " << mean(bmp,no_tests)*1000 << "ms\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement