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

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

using UnityEngine;
using System.Collections;
using JungleDB;

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.commit();
		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;
	}
}