Creating a benchmark script for Sylphis3D

Suppose that you want to benchmark a 3D game engine. What do you do? The common solution is:

  • Have a demo file to play
  • Play it on the benchmark machine
  • Count the time elapsed

Next is a script to do this in Sylphis3D:

import sylphis
import pyui 
import mthread

##
## The function that does the measurement
##
def bench():
    mthread.sleep(0.1) # Sleep a little time to let things settle

    timer = sylphis.CTimer() # Generate a timer to count time
    startFrame = CEngine.getFrameCount()# Log the number of frames rendered by the engine at the start of the benchmark

    mthread.sleep(50.0) # Sleep for 50.0 seconds of game world time

    time = timer.getTime() # Read the real world time it took to render all the frames
    frames = float(CEngine.getFrameCount() - startFrame) # Calculate the number of frames the engine rendered
    print "Average FPS : %4.2f" % (frames / time)

    shutdown() # Shutdown the engine

CClient.loadMap('maps/bench.cmap') # Load the benchmark map
pyui.deactivate() # Deactivate the GUI
CEngine.setFPS(30.0) # Set the engine to generate a constant frames per game world second
mthread.parallelize(bench) # Run bench() in parallel

The script is named benchmark.py placed in the base folder and invoked by running like this(creating a shortcut is handy):

sylphis.exe -exec benchmark

The scripts loads and runs the map, and invokes a function that runs in parallel with the game engine, that will time the process for 50 second of game world time. Microthreads in action!!!