view Assets/Application/Scripts/Test/GetComponentTest.cs @ 13:e297afe0889d default tip

Add Prefab.
author Kazuma Takeda
date Tue, 07 Feb 2017 20:49:26 +0900
parents b55d586dd4eb
children
line wrap: on
line source

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;

public class GetComponentTest : MonoBehaviour {

	int times = 100;
	// Use this for initialization
	void Start () {

		for (int i = 0; i < 100; i++) {
			GameObject obj = Resources.Load<GameObject> ("Prefabs/Box/Wood");
		}

		double total_generic = 0d;
		double total_as = 0d;
		double total_basic = 0d;
		double total_basic_typeof = 0d;

		for(int count = 0; count < times; count++) {

			Stopwatch st = new Stopwatch ();
			st.Start ();
			for (int i = 0; i < 10000; i++) {
				GameObject obj = Resources.Load ("Prefabs/Box/Wood") as GameObject;
			}
			st.Stop ();
			total_as += st.Elapsed.TotalMilliseconds;

			st = new Stopwatch ();
			st.Start ();
			for (int i = 0; i < 10000; i++) {
				GameObject obj = Resources.Load<GameObject> ("Prefabs/Box/Wood");
			}
			st.Stop ();
			total_generic += st.Elapsed.TotalMilliseconds;

			st = new Stopwatch ();
			st.Start ();
			for (int i = 0; i < 10000; i++) {
				GameObject obj = (GameObject) Resources.Load ("Prefabs/Box/Wood");
			}
			st.Stop ();
			total_basic += st.Elapsed.TotalMilliseconds;

			st = new Stopwatch ();
			st.Start ();
			for (int i = 0; i < 10000; i++) {
				GameObject obj = (GameObject) Resources.Load ("Prefabs/Box/Wood", typeof(GameObject));
			}
			st.Stop ();
			total_basic_typeof += st.Elapsed.TotalMilliseconds;
		}

		print ("as average : " + total_as / (double)times + "ms");
		print ("generic average : " + total_generic / (double)times + "ms");
		print ("basic average : " + total_basic / (double)times + "ms");
		print ("basic typeof average : " + total_basic_typeof / (double)times + "ms");

	}
	
	// Update is called once per frame
	void Update () {
		
	}
}