日期:2014-05-20 浏览次数:20721 次
private class TestCaseType
{
public TestCaseDelegate proc; //测试程序
public string desc; //测试程序的标题(摘要说明)
}
private delegate void TestCaseDelegate();
private static IEnumerable<TestCaseType> GetTestCases(this Assembly[] assembly)
{
。。。。
}
private static void StressTest(this Assembly[] assembly, int 次数)
{
var tps = GetTestCases(assembly);
if (tps.Count() == 0)
{
System.Console.WriteLine("******** 没有测试用例 ********");
return;
}
var map = tps.AsParallel().SelectMany(tp => Clone(tp, 次数)).Select(tp => Test(tp));
var reduce = from t in map
group t by t.proc into g
orderby g.Average(p => p.mi) descending
select new { proc = g.Key, desc = g.First().desc, mi = (long)g.Average(p => p.mi) };
int testCnd = 0;
reduce.ForEach(r => { System.Console.WriteLine("{0} 平均{1}毫秒\t{2}", ++testCnd, r.mi, r.desc.Description); });
}
//将测试用例重复多次
private static IEnumerable<TestCaseType> Clone(TestCaseType t, int 倍数)
{
var c = new List<TestCaseType>();