using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
class TestObject {
int n;
string name;
public TestObject() {
n = 0;
name = "abc";
}
}
// テスト用のクラス
public class TestClass : MonoBehaviour {
const int ArrayNum = 5000; // 配列数
float fBaseTime = 0.0f;
float fCurTime = 0.0f;
int [] array; // 配列
System.Collections.ArrayList al0;
System.Collections.ArrayList al1;
System.Collections.ArrayList al2;
System.Collections.ArrayList al3;
void Start() {
TestArray();
}
void Update() {
if(Input.GetKeyDown(KeyCode.Alpha1)) {
StartCoroutine( WaitFunc(1.0F) );
}
if(Input.GetKeyDown(KeyCode.Alpha2)) {
StartCoroutine( WaitFunc(1.5F) );
}
if(Input.GetKeyDown(KeyCode.Alpha4)) {
TestArray();
}
}
// 配列のテスト
void TestArray() {
// 配列の作成
array = new int [ ArrayNum ];
al0 = new ArrayList();
al1 = new ArrayList();
al2 = new ArrayList();
al3 = new ArrayList();
// Test1 何もしない
fBaseTime = Time.realtimeSinceStartup;
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test1 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test2 配列に値セット
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
array[i] = i;
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test2 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test3 配列に整数を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al0.Add( i );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test3 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
Debug.Log("al0.Count = " + al0.Count);
// Test4 配列に整数を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al1.Add( 9876 );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test4 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test5 配列に文字列を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al2.Add( "abcdefghijklmnopqrstu" );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test5 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test5 配列にクラスを追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
TestObject o = new TestObject();
al3.Add( o );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
}
IEnumerator WaitFunc(float t) {
fBaseTime = Time.realtimeSinceStartup;
yield return new WaitForSeconds( t );
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
}
}
2012年2月26日日曜日
Unity 処理時間計測 (2)
C#版
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿