void Render() { Benchy.Begin(); Benchy.Begin("Find main camera"); GameObject mainCamera = FindMainCamera(); Benchy.End("Find main camera"); if (mainCamera) { ParticleSystem particleSystem = mainCamera.GetComponent <ParticleSystem> (); if (particleSystem) { counter++; Benchy.Begin("Main particle system code"); if (counter >= 100) { if (!particleSystem.isPlaying) { particleSystem.Play(); } particleSystem.startColor = new Color(Random.Range(0, 255) / 255f, Random.Range(0, 255) / 255f, Random.Range(0, 255) / 255f, Random.Range(0, 255) / 255f); particleSystem.startRotation = Random.Range(0, 20); counter = 0; } Benchy.End("Main particle system code"); } } Benchy.End(); }
void Update() { Benchy.Begin(); ManualTestSharedCallsA classA = gameObject.GetComponent <ManualTestSharedCallsA>(); classA.ThisIsASharedMethod(); Benchy.End(); }
void CallSomeOtherMethod() { Benchy.Begin(); Benchy.Begin("Checking something on method"); // Some code could possibly have been here Benchy.End("Checking something on method"); Benchy.End(); }
unsafe List <MyTestResult> BenchAll <T>(string name, T item, IntPtr ptr, int length, Random random, int testRuns) { var methods = new Benchy <T>[] { Newtonsoft, Jil, ProtoBuf, #if FPBENCH Brianary, #endif CameronismPointer, CameronismStream, CameronismFakeStream, }; var testGroup = new TestGroup(name); return(methods .OrderBy(_ => random.Next()) .Select(method => { var positions = new List <long?>(); var result = new MyTestResult { Case = testGroup.Name, Serializer = method.Method.Name, Lengths = positions, }; Action plan = () => { using (var ms = new UnmanagedMemoryStream((byte *)ptr, 0, length, FileAccess.Write)) { method.Invoke(item, ms); positions.Add(ms.Position); } }; var serializeResult = testGroup .Plan(method.Method.Name, plan, testRuns) .GetResult(); var filter = new SimpleSpeedTester.Core.OutcomeFilters.ExcludeMinAndMaxTestOutcomeFilter(); var summary = serializeResult.GetSummary(filter); result.Summary = summary; positions.Sort(); if (positions.Count > 1 && positions.First() != positions.Last()) { throw new Exception("Inconsistent results from " + method.Method.Name); } return result; }) .ToList()); }
public void ThisIsASharedMethod() { Benchy.Begin(); // A method that's as about as useful as the rest of the class :) float x = 3 * 2.3938384f; double y = Mathf.Sqrt(x); y = y + .99f; Benchy.End(); }
void Update() { Benchy.Begin(); if (counter > 100) { counter = 0; ThisIsASharedMethod(); } counter++; Benchy.End(); }
public static void Exit(string methodName, object caller) { try { string className = new StackFrame(1, false).GetMethod().DeclaringType.Name; if (caller == null) { Benchy.EndInjected(methodName, className); } else { Benchy.EndInjected(methodName, System.String.Format("{0}", caller.GetType())); } } catch {} }
//[NeverProfileMethod] // Just another example of how to mix and match manually profiled sections with auto sections void CalculateStuff() { Benchy.Begin(); int nextNumber = Random.Range(0, 1000000); if (IsPrime(nextNumber)) { Benchy.Begin("Checking if prime already found"); if (primeNumbers.ContainsKey(nextNumber)) { primeNumbers [nextNumber] = true; } else { primeNumbers.Add(nextNumber, false); } Benchy.End("Checking if prime already found"); } int sumOfAllPrimes = primeNumbers.Sum(x => x.Key); sumOfAllPrimes += 1; CallSomeOtherMethod(); Benchy.End(); }