I'm making a lua-sfml engine and i decide to test the performace making the same code on pure C++.
All compiler optimizations are on on both projects ( -O3 -fexpensive-optimizations ). (using codeblocks)
Not frame limit in both projects.
Lua-jit gets version 11 fps stable ( with 1000 crates on display , physics engine active ( there are 3 physics object active in the scene, some events dispatcher actives )
In C++ pure version got 8 fps stable ( with ONLY 1000 crates on the display..no physics engine active..no Lua states actives )
I use 2 counters for the test.. a custom counter on the game..and FRAPS.. both counter say the same fps rate. ( 11 for lua / 8 for c++ )
C++ code for the test only this no more:
#include <iostream>
using namespace std ;
#include <SFML/Graphics.hpp>
using namespace sf ;
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(600, 600), "My window") ;
int fps_rate = 0 ;
Clock *fps = new Clock ;
sf::Texture t ;
// load the texture
t.loadFromFile( "crate.png" ) ;
t.setSmooth( true ) ;
Sprite *obj = new Sprite[ 1000 ] ;
for( int s = 0 ; s < 1000 ; ++s )
obj[s].setTexture( t ) ;
// run the program as long as the window is open
while (window.isOpen())
{
// fps counter
++fps_rate ;
if ( fps->getElapsedTime().asSeconds() >= 1 )
{ fps->restart() ;
cout << fps_rate << endl ;
fps_rate = 0 ;
}
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// draw everything here...
for( int i = 0 ; i < 1000 ; ++i )
{
window.draw( obj[ i ] ) ;
}
// end the current frame
window.display();
}
return 0;
}
Screenshots:
lua version
The small crate and the long crates are physics objects. (the small crates is falling)
The bigs crates ( there are one thousand , you cant see it because are one behind other )
The console show the fps..and the yellow numbers are shown by FRAPS.
The same in the C++ version :
As you can see.. no physics..no lua States..
Please..if you can optimizate more this c++ code please post it for test it.
I would like yours reviews.
PD: link for the full images:
c++ :
http://www.subirimagenes.com/imagedata.php?url=http://s2.subirimagenes.com/imagen/9376734c.pnglua :
http://www.subirimagenes.com/imagedata.php?url=http://s2.subirimagenes.com/imagen/9376732luaversion.pngLua game engine topic:
http://en.sfml-dev.org/forums/index.php?topic=18074.0