private static String getMethodName(MethodToRun run) { object[] attributes = run.Method.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes.Length > 0) { return(((DescriptionAttribute)attributes[0]).Description); } if (run.Method.Name.StartsWith("Run")) { return(run.Method.Name.Substring("Run".Length)); } return(run.Method.Name); }
public void Run(MethodToRun run, bool displayBeginEnd) { String methodName = getMethodName(run); if (displayBeginEnd) { WriteLine("Begin [{0}]", methodName); } MapMethodToPerf perfMethod = getCurrentPerf(); perfMethod.Start(); perfList.Add(new MapMethodToPerf()); run(); perfList.RemoveAt(perfList.Count - 1); perfMethod.Stop(); CountPerMethod countPerMethod; perfMethod.TryGetValue(run.Method, out countPerMethod); if (countPerMethod == null) { countPerMethod = new CountPerMethod(); countPerMethod.name = methodName; countPerMethod.totalElapsedTime = 0; countPerMethod.countCall = 0; perfMethod.Add(run.Method, countPerMethod); } long elapsedTime = perfMethod.ElapsedMilliseconds; countPerMethod.totalElapsedTime += elapsedTime; countPerMethod.countCall++; if (displayBeginEnd) { WriteLine("End [{0}] computed in {1}ms", methodName, elapsedTime); WriteLine(); } else { WriteLine("{0}\t computed in {1}ms", methodName, elapsedTime); } }
public void Run(MethodToRun run) { Run(run, false); }