建立两个测试对象:
//复杂测试对象1
public class ComplexObject1 : ObjectBase
{
private byte[] data = new byte[1024];
public override void Init(params object[] paramList)
{
}
}
//复杂测试对象2
class ComplexObject2 : ObjectBase
{
private byte[] data = new byte[1024 * 1024];
public override void Init(params object[] paramList)
{
}
}
  测试代码:
class Program
{
const int Count1 = 1000000;
const int Count2 = 500;
static void Main(string[] args)
{
var list1 = new List<ComplexObject1>(Count1 * 2);
var list2 = new List<ComplexObject2>(Count2 * 2);
CodeElapseChecker.Initialize();
ObjectPoolManager<ComplexObject1>.Instance.Init(Count1);
ObjectPoolManager<ComplexObject2>.Instance.Init(Count2);
CodeElapseChecker.Time("TestComplexObject1", () => { list1.Add(new ComplexObject1()); }, Count1);
CodeElapseChecker.Time("TestPooledComplexObject1", () => { list1.Add(ObjectPoolManager<ComplexObject1>.Instance.NewObject()); }, Count1);
CodeElapseChecker.Time("TestComplexObject2", () => { list2.Add(new ComplexObject2()); }, Count2);
CodeElapseChecker.Time("TestPooledComplexObject2", () => { list2.Add(ObjectPoolManager<ComplexObject2>.Instance.NewObject()); }, Count2);
Console.WriteLine(list1.Count);
Console.WriteLine(list2.Count);
}
}
  运行测试结果:(采用Release、X64编译)