Created
June 24, 2013 15:27
-
-
Save bananu7/5850874 to your computer and use it in GitHub Desktop.
GL vs C++ benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <chrono> | |
#include <windows.h> | |
#include <gl/GLEW.h> | |
#include <vector> | |
using namespace std; | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); | |
std::pair<unsigned,unsigned> test_manual (unsigned n) { | |
std::vector<GLuint> texIds(n+1, 0); | |
std::chrono::time_point<std::chrono::system_clock> start, end; | |
unsigned creation_usec, destruction_usec; | |
start = std::chrono::system_clock::now(); | |
for (int i = 0; i < n; ++i) { | |
glGenTextures(1, texIds.data() + n); | |
} | |
end = std::chrono::system_clock::now(); | |
creation_usec = std::chrono::duration_cast<std::chrono::microseconds> | |
(end-start).count(); | |
start = std::chrono::system_clock::now(); | |
for (int i = 0; i < n; ++i) { | |
glDeleteTextures(1, texIds.data() + n); | |
} | |
end = std::chrono::system_clock::now(); | |
destruction_usec = std::chrono::duration_cast<std::chrono::microseconds> | |
(end-start).count(); | |
return std::make_pair(creation_usec, destruction_usec); | |
} | |
std::pair<unsigned,unsigned> test_gl (unsigned n) { | |
std::vector<GLuint> texIds(n+1, 0); | |
std::chrono::time_point<std::chrono::system_clock> start, end; | |
unsigned creation_usec, destruction_usec; | |
start = std::chrono::system_clock::now(); | |
glGenTextures(n, texIds.data()); | |
end = std::chrono::system_clock::now(); | |
creation_usec = std::chrono::duration_cast<std::chrono::microseconds> | |
(end-start).count(); | |
start = std::chrono::system_clock::now(); | |
glDeleteTextures(n, texIds.data()); | |
end = std::chrono::system_clock::now(); | |
destruction_usec = std::chrono::duration_cast<std::chrono::microseconds> | |
(end-start).count(); | |
return std::make_pair(creation_usec, destruction_usec); | |
} | |
#include "Window.h" | |
int main () { | |
WinAPIOpenGLWindow win; | |
win.Create("Benchmark", 100, 100, 32, false, WndProc); | |
static const unsigned N = 1e5; | |
auto manual_result = test_manual(N); | |
auto gl_result = test_gl(N); | |
std::cout << "manual: " << manual_result.first << ", " << manual_result.second << std::endl; | |
std::cout << "gl : " << gl_result.first << ", " << gl_result.second << std::endl; | |
win.Kill(); | |
} | |
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (uMsg) | |
{ | |
case WM_SYSCOMMAND: { | |
switch (wParam) { | |
case SC_SCREENSAVE: | |
case SC_MONITORPOWER: | |
return 0; | |
} | |
break; | |
} | |
case WM_CLOSE: { | |
PostQuitMessage(0); | |
return 0; | |
} | |
} | |
return DefWindowProc(hWnd,uMsg,wParam,lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment