Game Development Community

Sample Perf Testing code

by Jason Swearingen · in Torque Game Builder · 03/16/2006 (1:53 pm) · 1 replies

Here is some sample perf test code I wrote for TGB, meant to be used with the spaceScrollerDemo.

all it does is create staticsprites (as lightweight as possible, so no physics, etc) tiled across the screen.

The code lets you delete sprites after a certain durration, if you want to make sure GC is working okay. The code is pretty self-explanatory, and hopefully people can leverage it if they want :)

$stressMinX=-35;
$stressMaxX=35;
$stressMinY=-35;
$stressMaxY=35;
$stressX=$stressMinX;
$stressY=$stressMinY;
$stressSizeX=10;
$stressSizeY=10;
$stressPermObjectCount=0;

spaceSceneGraph2D.setDebugOn( 0 );

//count = how many you want to add
//lapScale = how much to shrink or expand the object size when it loops at the end of the screen.
//durration is how long you want the object to persist.  use 0 for perminent.  
//   durration 0 objects are added to a counter $stressPermObjectCount, 
//   which is displayed after the call to this function.
function stressX(%count, %lapScale, %durration)
{
	for(%i=0;%i<%count;%i++)
	{
		// Generate new StressBlock Sprite.
		%stressBlock = new t2dStaticSprite() { scenegraph = spaceSceneGraph2D; };
		//%stressBlock.setGraphGroup( 1 );
		%stressBlock.setLayer( 20 );
		if(%durration==0)
		{
			$stressPermObjectCount++;
		}else{
			%stressBlock.setLifetime( %durration );
		}
		%stressBlock.setPosition( $stressX, $stressY );
		%stressBlock.setSize( $stressSizeX, $stressSizeY );


		%stressBlock.setImageMap( ringImageMap );

		%stressBlock.setWorldLimit(off);
		%stressBlock.setCollisionActive( false, false );
		%stressBlock.setCollisionPhysics( false, false );
		%stressBlock.setImmovable(true);

		$stressX=$stressX+$stressSizeX;
		if($stressX>$stressMaxX)
		{
			$stressX=$stressMinX;
			$stressY=$stressY=$stressY+$stressSizeY;
			if($stressY>$stressMaxY)
			{
				$stressY=$stressMinY;
				$stressSizeX=$stressSizeX*%lapScale;
				$stressSizeY=$stressSizeY*%lapScale;
			}
		}
	}
	if(%durration==0)
	{
		echo("$stressPermObjectCount = " @ $stressPermObjectCount);
	}
}
function stress100()
{
	stressX( 100, 0.99, 0 );
}
function stress10Bind(%val)
{
	stress100();
}


Using a single 64x64 sprite, I was able to put about 4000 sprites on my screen before the game play became too choppy.

Here is a listing of my fps at different stress Object Counts:

System specs: P4 @3ghz, 128mb ati fire GL card, 800x600@16bit fullscreen.
240fps @ 0 stress objects
51fps @ 2000 stress objects
31fps @ 4000 stress objects

Here is a screenshot in windowed mode (800x600), with 4918 objects (4200 stress objects) @ 24.9 fps
www.cwite.org/public/scratch/jasons_tgb1_1_stress_01.jpg

#1
03/16/2006 (2:01 pm)
And fyi, 2000-3000 objects seems pretty acceptable for all game types (including fast action)

4000+ objects seem to be acceptable only for games that wont need fast action, as the choppiness of the moving sprites is definatly noticable (but not yet unplayable)