I made an empty scene with just one game object to display FPS.
When I run on my android phone, I get pretty bad stats.
Android Unity internal profiler stats:
cpu-player> min: 6.3 max: 25.7 avg: 20.3
cpu-ogles-drv> min: 0.2 max: 5.1 avg: 0.3
cpu-present> min: 0.3 max: 17.0 avg: 0.8
frametime> min: 15.2 max: 26.2 avg: 21.5
draw-call #> min: 2 max: 2 avg: 2 | batched: 0
tris #> min: 18 max: 18 avg: 18 | batched: 0
verts #> min: 40 max: 40 avg: 40 | batched: 0
Here is the script attached to my one game object to display FPS.
using UnityEngine;
using System.Collections;
public class DebugHUD : MonoBehaviour
{
public static DebugHUD debugHUD;
public bool debugOn = true;
public float updateInterval = 0.5f;
private int frames = 0;
private float duration = 0;
// Singleton
void Awake ()
{
if (debugHUD == null) {
DontDestroyOnLoad (gameObject);
debugHUD = this;
} else if (debugHUD != this) {
Destroy (gameObject);
}
if (!Debug.isDebugBuild)
debugOn = false;
if (guiText) {
guiText.fontSize = (int)(Screen.width * 0.05f);
if (debugOn)
StartCoroutine (UpdateFPS ());
else
guiText.enabled = false;
} else {
Debug.LogWarning ("Please attach GUIText component to game object");
}
}
void Update ()
{
++frames;
duration += Time.deltaTime;
}
// Display FPS data
IEnumerator UpdateFPS ()
{
float fps = 0;
string format;
// Cache reference to components
GUIText FPStext = guiText;
Material material = FPStext.material;
while (true) {
duration = 0;
frames = 0;
yield return new WaitForSeconds (updateInterval);
// Only do division once
duration = 1 / duration;
// Only update if FPS changes
if (fps - (frames * duration) < 0.01 && fps - (frames * duration) > -0.01) {
continue;
}
fps = frames * duration;
format = System.String.Format ("{0:F2} FPS", fps);
FPStext.text = format;
if (fps < 30)
material.color = Color.yellow;
else if (fps < 10)
material.color = Color.red;
else
material.color = Color.green;
}
}
}
The internal profiler says around 45fps and that’s what my script displays.
Does this mean that I won’t be able to get my fps any higher than this on this device?
It’s kind of disheartening that I have made probably the most efficient possible app and it only gets 45 fps.