public static void RunTest() { // Allocate the objects. s_lifeTimeManager = new ObjectLifeTimeManager(); LifeTimeStrategy ltStrategy; int threadMediumLifeTime = s_mediumLifeTime; int threadShortLifeTime = s_shortLifeTime; int threadMediumDataSize = s_mediumDataSize; int threadShortDataSize = s_shortDataSize; int threadMediumDataCount = s_mediumDataCount; int threadShortDataCount = s_shortDataCount; float threadPercentPinned = s_percentPinned; float threadPercentWeak = s_percentWeak; bool threadRunFinalizer = s_runFinalizer; string threadStrategy = s_strategy; string threadObjectGraph = s_objectGraph; if (threadObjectGraph.ToLower() == "tree") { s_lifeTimeManager.SetObjectContainer(new BinaryTreeObjectContainer <LifeTime>()); } else { s_lifeTimeManager.SetObjectContainer(new ArrayObjectContainer <LifeTime>()); } s_lifeTimeManager.Init(threadShortDataCount + threadMediumDataCount); if (threadStrategy.ToLower() == "random") { ltStrategy = new RandomLifeTimeStrategy(threadMediumLifeTime, threadShortLifeTime, threadMediumDataCount, threadShortDataCount); } else { // may be we need to specify the elapsed time. ltStrategy = new TimeBasedLifeTimeStrategy(); } s_lifeTimeManager.LifeTimeStrategy = ltStrategy; s_lifeTimeManager.objectDied += new ObjectDiedEventHandler(objectDied); for (int i = 0; i < threadShortDataCount + threadMediumDataCount; ++i) { bool pinned = false; if (threadPercentPinned != 0) { pinned = (i % ((int)(1 / threadPercentPinned)) == 0); } bool weak = false; if (threadPercentWeak != 0) { weak = (i % ((int)(1 / threadPercentWeak)) == 0); } ObjectWrapper oWrapper = new ObjectWrapper(threadRunFinalizer, pinned, weak); if (i < threadShortDataCount) { oWrapper.DataSize = threadShortDataSize; oWrapper.LifeTime = LifeTimeENUM.Short; } else { oWrapper.DataSize = threadMediumDataSize; oWrapper.LifeTime = LifeTimeENUM.Medium; } s_lifeTimeManager.AddObject(oWrapper, i); } lock (s_objLock) { Console.WriteLine("Thread {0} Running With Configuration: ", System.Threading.Thread.CurrentThread.ManagedThreadId); Console.WriteLine("=============================="); Console.WriteLine("[Thread] Medium Lifetime " + threadMediumLifeTime); Console.WriteLine("[Thread] Short Lifetime " + threadShortLifeTime); Console.WriteLine("[Thread] Medium Data Size " + threadMediumDataSize); Console.WriteLine("[Thread] Short Data Size " + threadShortDataSize); Console.WriteLine("[Thread] Medium Data Count " + threadMediumDataCount); Console.WriteLine("[Thread] Short Data Count " + threadShortDataCount); Console.WriteLine("[Thread] % Pinned " + threadPercentPinned); Console.WriteLine("[Thread] % Weak " + threadPercentWeak); Console.WriteLine("[Thread] RunFinalizers " + threadRunFinalizer); Console.WriteLine("[Thread] Strategy " + threadStrategy); Console.WriteLine("[Thread] Object Graph " + threadObjectGraph); Console.WriteLine("=============================="); } for (int i = 0; i < s_countIters; ++i) { // Run the test. s_lifeTimeManager.Run(); if (s_outputFrequency > 0) { lock (s_objLock) { s_currentIterations++; if (s_currentIterations % s_outputFrequency == 0) { Console.WriteLine("Iterations = {0}", s_currentIterations); Console.WriteLine("AllocatedMemory = {0} bytes", GC.GetTotalMemory(false)); //get the number of collections and the elapsed time for this group of iterations int[] collectionCount = new int[3]; for (int j = 0; j < 3; j++) { collectionCount[j] = GC.CollectionCount(j); } int[] newCollections = new int[3]; for (int j = 0; j < 3; j++) { newCollections[j] = collectionCount[j] - s_currentCollections[j]; } //update the running count of collections for (int j = 0; j < 3; j++) { s_currentCollections[j] = collectionCount[j]; } Console.WriteLine("Gen 0 Collections = {0}", newCollections[0]); Console.WriteLine("Gen 1 Collections = {0}", newCollections[1]); Console.WriteLine("Gen 2 Collections = {0}", newCollections[2]); s_stopWatch.Stop(); Console.Write("Elapsed time: "); System.TimeSpan tSpan = s_stopWatch.Elapsed; if (tSpan.Days > 0) { Console.Write("{0} days, ", tSpan.Days); } if (tSpan.Hours > 0) { Console.Write("{0} hours, ", tSpan.Hours); } if (tSpan.Minutes > 0) { Console.Write("{0} minutes, ", tSpan.Minutes); } Console.Write("{0} seconds, ", tSpan.Seconds); Console.Write("{0} milliseconds", tSpan.Milliseconds); s_totalTime += tSpan; s_stopWatch.Reset(); s_stopWatch.Start(); Console.Write(" (Total time: "); if (s_totalTime.Days > 0) { Console.Write("{0} days, ", s_totalTime.Days); } if (s_totalTime.Hours > 0) { Console.Write("{0} hours, ", s_totalTime.Hours); } if (s_totalTime.Minutes > 0) { Console.Write("{0} minutes, ", s_totalTime.Minutes); } Console.Write("{0} seconds, ", s_totalTime.Seconds); Console.WriteLine("{0} milliseconds)", s_totalTime.Milliseconds); Console.WriteLine("----------------------------------"); } } } } }
public static void RunTest(object threadInfoObj) { // Allocate the objects. lifeTimeManager = new ObjectLifeTimeManager(); LifeTimeStrategy ltStrategy; int threadMediumLifeTime = mediumLifeTime; int threadShortLifeTime = shortLifeTime; int threadMediumDataSize = mediumDataSize; int threadShortDataSize = shortDataSize; int threadMediumDataCount = mediumDataCount; int threadShortDataCount = shortDataCount; float threadPercentPinned = percentPinned; float threadPercentWeak = percentWeak; bool threadRunFinalizer = runFinalizer; string threadStrategy = strategy; string threadObjectGraph = objectGraph; if (threadObjectGraph.ToLower() == "tree") { lifeTimeManager.SetObjectContainer(new BinaryTreeObjectContainer<LifeTime>()); } else { lifeTimeManager.SetObjectContainer(new ArrayObjectContainer<LifeTime>()); } lifeTimeManager.Init(threadShortDataCount + threadMediumDataCount); if (threadStrategy.ToLower()=="random") { ltStrategy = new RandomLifeTimeStrategy(threadMediumLifeTime, threadShortLifeTime, threadMediumDataCount, threadShortDataCount); } else { // may be we need to specify the elapsed time. ltStrategy = new TimeBasedLifeTimeStrategy(); } lifeTimeManager.LifeTimeStrategy = ltStrategy; lifeTimeManager.objectDied += new ObjectDiedEventHandler(objectDied); for (int i=0; i < threadShortDataCount + threadMediumDataCount; ++i) { bool pinned = false; if (threadPercentPinned!=0) { pinned = (i % ((int)(1/threadPercentPinned))==0); } bool weak = false; if (threadPercentWeak!=0) { weak = (i % ((int)(1/threadPercentWeak))==0); } ObjectWrapper oWrapper = new ObjectWrapper(threadRunFinalizer, pinned, weak); if (i < threadShortDataCount) { oWrapper.DataSize = threadShortDataSize; oWrapper.LifeTime = LifeTimeENUM.Short; } else { oWrapper.DataSize = threadMediumDataSize; oWrapper.LifeTime = LifeTimeENUM.Medium; } lifeTimeManager.AddObject(oWrapper, i); } for (int i = 0; i < countIters; ++i) { // Run the test. lifeTimeManager.Run(); } }
public static void RunTest(object threadInfoObj) { // Allocate the objects. lifeTimeManager = new ObjectLifeTimeManager(); LifeTimeStrategy ltStrategy; int threadMediumLifeTime = mediumLifeTime; int threadShortLifeTime = shortLifeTime; int threadMediumDataSize = mediumDataSize; int threadShortDataSize = shortDataSize; int threadMediumDataCount = mediumDataCount; int threadShortDataCount = shortDataCount; float threadPercentPinned = percentPinned; float threadPercentWeak = percentWeak; bool threadRunFinalizer = runFinalizer; string threadStrategy = strategy; string threadObjectGraph = objectGraph; if (threadObjectGraph.ToLower() == "tree") { lifeTimeManager.SetObjectContainer(new BinaryTreeObjectContainer <LifeTime>()); } else { lifeTimeManager.SetObjectContainer(new ArrayObjectContainer <LifeTime>()); } lifeTimeManager.Init(threadShortDataCount + threadMediumDataCount); if (threadStrategy.ToLower() == "random") { ltStrategy = new RandomLifeTimeStrategy(threadMediumLifeTime, threadShortLifeTime, threadMediumDataCount, threadShortDataCount); } else { // may be we need to specify the elapsed time. ltStrategy = new TimeBasedLifeTimeStrategy(); } lifeTimeManager.LifeTimeStrategy = ltStrategy; lifeTimeManager.objectDied += new ObjectDiedEventHandler(objectDied); for (int i = 0; i < threadShortDataCount + threadMediumDataCount; ++i) { bool pinned = false; if (threadPercentPinned != 0) { pinned = (i % ((int)(1 / threadPercentPinned)) == 0); } bool weak = false; if (threadPercentWeak != 0) { weak = (i % ((int)(1 / threadPercentWeak)) == 0); } ObjectWrapper oWrapper = new ObjectWrapper(threadRunFinalizer, pinned, weak); if (i < threadShortDataCount) { oWrapper.DataSize = threadShortDataSize; oWrapper.LifeTime = LifeTimeENUM.Short; } else { oWrapper.DataSize = threadMediumDataSize; oWrapper.LifeTime = LifeTimeENUM.Medium; } lifeTimeManager.AddObject(oWrapper, i); } for (int i = 0; i < countIters; ++i) { // Run the test. lifeTimeManager.Run(); } }