view Assets/Application/Scripts/Test/GetComponentTest.cs @ 8:599bd8ddb72b

Create Item Tree and Create Stage.
author Kazuma Takeda
date Tue, 17 Jan 2017 19:57:19 +0900
parents
children b55d586dd4eb
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;

//			Stopwatch 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;

//			Stopwatch 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;
//
//			Stopwatch 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 () {
		
	}
}