Advertisement
Guest User

SFML - sf::Texture::loadFromFile test

a guest
Nov 27th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3. #include <chrono>
  4.  
  5.  
  6. void load(std::string file, double& t) {
  7.     sf::Texture tex;
  8.     auto t1 = std::chrono::steady_clock::now();
  9.     tex.loadFromFile("test.png");
  10.     auto t2 = std::chrono::steady_clock::now();
  11.     t = std::chrono::duration_cast<std::chrono::duration<double>>(t2-t1).count();
  12. }
  13. double mean(double a[], int size) {
  14.     double tot = 0;
  15.     for (int i = 0; i < size; i++) {
  16.         tot += a[i];
  17.     }
  18.     return tot/(double)size;
  19. }
  20.  
  21. int main() {
  22.     // initializing
  23.     const int no_tests = 20;
  24.     double png[no_tests] = {0};
  25.     double jpg[no_tests] = {0};
  26.     double bmp[no_tests] = {0};
  27.  
  28.     // warm up the GPU
  29.     std::cout << "Warming up...\n";
  30.     {
  31.         double dummy;
  32.         load("test.png",dummy);
  33.         load("test.jpg",dummy);
  34.         load("test.bmp",dummy);
  35.     }
  36.  
  37.     // do tests
  38.     std::cout << "PNG test";
  39.     for (int i = 0; i < no_tests; i++) {
  40.         load("test.png", png[i]);
  41.         std::cout << ".";
  42.     }
  43.     std::cout << "\n";
  44.  
  45.     std::cout << "JPG test";
  46.     for (int i = 0; i < no_tests; i++) {
  47.         load("test.jpg", jpg[i]);
  48.         std::cout << ".";
  49.     }
  50.     std::cout << "\n";
  51.  
  52.     std::cout << "BMP test";
  53.     for (int i = 0; i < no_tests; i++) {
  54.         load("test.bmp", bmp[i]);
  55.         std::cout << ".";
  56.     }
  57.     std::cout << "\n\n";
  58.  
  59.     // show results
  60.     std::cout << "PNG time: " << mean(png,no_tests)*1000 << "ms\n";
  61.     std::cout << "JPG time: " << mean(jpg,no_tests)*1000 << "ms\n";
  62.     std::cout << "BMP time: " << mean(bmp,no_tests)*1000 << "ms\n";
  63.  
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement