Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Tiled Background & Performance (Q and Benchmarks)  (Read 1382 times)

0 Members and 1 Guest are viewing this topic.

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Tiled Background & Performance (Q and Benchmarks)
« on: July 24, 2014, 02:09:08 pm »
I recently added a tiled background to my project.  It was a straightforward implementation.  I parse the information from a tmx file (Tiled Editor) and then loop through each layer and tile.  I have two layers and my map is 50 tiles by 50 tiles.  So to draw the background I loop 5,000 times (2 layers x 50 tiles wide x 50 height).

Looking at the debug and release build before implementing this I was running at 680 FPS.  If I loop through the logic, but don't call the draw method my release's performance holds at  680 FPS, but my debug's performance plunges to 40 FPS!  Next, if I loop through all the logic, and call the draw method my debug FPS drops to 15 and my release FPS drops to 330.

First, I thought it was really strange the performance hit looping through the logic takes in debug mode.  That's a 17x performance decrease.  It seems very quickly my game would become unplayable in debug mode. 

Next, my release mode is running at 330 FPS with a character and a background.  That seems fast enough, but I wish I had something to compare it to.  Does this seem like a reasonable place to begin building a simple 2D game on?

Finally, I can think of a number of optimizations.  The simplest being to not redraw the character and background every single frame.  I mention the character and background together, because I center the camera on the character.  They are linked.  Is there a "recommended" number of times to redraw per second?


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Tiled Background & Performance (Q and Benchmarks)
« Reply #1 on: July 24, 2014, 02:16:19 pm »
Looking at the debug and release build before implementing this I was running at 680 FPS.  If I loop through the logic [...] my debug's performance plunges to 40 FPS! [...] That's a 17x performance decrease.
No, it's not. Frames per second is not a linear scale. FPS is generally not the best way to measure performance.

First, don't optimize prematurely. If the performance is sufficient, you might waste your time. Second, it is expected that the debug mode is slower, because it does not optimize code and includes a lot of runtime checks. It is good to keep the game playable so you can debug it, but never optimize in debug mode. Third, if you really want to optimize something, do it systematically. Don't guess, use a profiler to find the bottlenecks and improve those parts specifically.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Kanefa

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: Tiled Background & Performance (Q and Benchmarks)
« Reply #2 on: July 24, 2014, 03:08:08 pm »
Good advice.  Thanks!

 

anything