Skip to content

Instantly share code, notes, and snippets.

@friuns2
Created December 16, 2019 12:22
Show Gist options
  • Save friuns2/74d8a610d67e473457598b71b6e44bed to your computer and use it in GitHub Desktop.
Save friuns2/74d8a610d67e473457598b71b6e44bed to your computer and use it in GitHub Desktop.
perofrmance test
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
public class Test64 : MonoBehaviour
{
public bool mtRendering;
#if UNITY_EDITOR
public void OnValidate()
{
PlayerSettings.MTRendering=mtRendering;
}
#endif
public GameObject refere;
private string deVNam="";
Camera cam;
void Start()
{
Random.seed = 0;
cam = GetComponent<Camera>();
QualitySettings.SetQualityLevel(0,true);
deVNam = SystemInfo.graphicsDeviceName;
#if UNITY_5_3_OR_NEWER
deVNam += ":" + SystemInfo.graphicsDeviceType + " experemental:" + (!SystemInfo.graphicsMultiThreaded);
#endif
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = 9999;
var cube = (GameObject)Instantiate(refere);
for (int j = 0; j < 100; j++)
{
materials.Add(cube.GetComponent<Renderer>().material = new Material(cube.GetComponent<Renderer>().material));
for (int i = 0; i < 100; i++)
{
var a = (GameObject)Instantiate(cube);
a.transform.position = Random.insideUnitSphere * 20;
a.transform.rotation = Random.rotation;
}
}
}
private List<Material> materials = new List<Material>();
private bool hq;
void OnGUI()
{
hq = GUILayout.Toggle(hq, "hq");
#if UNITY_5_3_OR_NEWER
Graphics.activeTier = hq ? GraphicsTier.Tier3 : GraphicsTier.Tier1;
#endif
cam.renderingPath = hq? RenderingPath.UsePlayerSettings:RenderingPath.VertexLit;
Shader.globalMaximumLOD = hq?999999 :100;
GUI.color = Color.red;
#if UNITY_5_3_OR_NEWER
if (hq)
{
var instancing = GUILayout.Toggle(materials[0].enableInstancing, "gpu instancing");
if (instancing != materials[0].enableInstancing)
{
materials[0].enableInstancing = instancing;
foreach (var a in materials)
a.enableInstancing = materials[0].enableInstancing;
}
}
#endif
GUILayout.Label(deVNam);
GUILayout.Label(fpsString);
}
private float fps=0;
private string fpsString="";
public void Update()
{
cam.transform.position+=Vector3.forward*Input.GetAxis("Mouse ScrollWheel")*10;
fps = Mathf.Lerp(fps, 1f / Time.deltaTime, Time.deltaTime * 5);
if (TimeElapsed(.3f))
fpsString = Mathf.RoundToInt(fps).ToString();
}
public static bool TimeElapsed(float seconds)
{
if (Time.deltaTime > seconds || seconds <= 0) return true;
var time = Time.time;
if (time % seconds < (time - Time.deltaTime) % seconds)
return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment