view Assets/Application/BenchMarkTest.cs @ 5:12f4f937da7f

Add BenchMark
author Kazuma
date Thu, 10 Nov 2016 04:21:19 +0900
parents
children ad4729c5eec4
line wrap: on
line source

using UnityEngine;
using System.Collections;

public class BenchMarkTest : MonoBehaviour {

	public static string key = "KEY";
	public static string indexKey = "INDEXKEY";
	// Use this for initialization
	void Start () {
		System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
		sw.Start ();
		Jungle jungle = new DefaultJungle(new NullJournal(), "hoge", new DefaultTreeEditor(new DefaultTraverser()));
		jungle.createNewTree("TestTree");
		JungleTree tree = jungle.getTreeByName("TestTree");
		JungleTreeEditor editor = tree.getTreeEditor();
		editor = createTree(editor, 0, 3, new DefaultNodePath());
		Either<Error, JungleTreeEditor> either = editor.success();
		DebugCommon.Assert (either.isA (), "[Error]" + either.a());
		sw.Stop ();
		print ("[Time]"  + sw.Elapsed);
	}

	public JungleTreeEditor createTree(JungleTreeEditor editor, int _curY, int _maxHeight, NodePath path) {

		if (_curY == _maxHeight) {
			return editor;
		}
		for (int i = 0; i < 3; i++) {
			Either<Error, JungleTreeEditor> either = editor.addNewChildAt (path, _curY);
			DebugCommon.Assert (either.isA (), "Error");
			editor = either.b ();
			string value = path.add (_curY).ToString ();
			either = editor.putAttribute (path.add (_curY), key, System.Text.Encoding.ASCII.GetBytes (value));
			DebugCommon.Assert (either.isA (), "Error");
			editor = either.b ();
			string value2 = value + "+ index";
			either = editor.putAttribute (path.add (_curY), indexKey, System.Text.Encoding.ASCII.GetBytes (value2));
			DebugCommon.Assert (either.isA (), "Error");
			editor = either.b ();
			editor = createTree (editor, _curY + 1, _maxHeight, path);
		}
		return editor;
	}
}