static void Main () { var testTimeout = new TestTimeout (); testTimeout.Start (); for (int i = 0; i < Math.Max (1, Environment.ProcessorCount / 2); ++i) { // for (int i = 0; i < 4; ++i) { var t = new Thread (BackgroundNoise); t.IsBackground = true; t.Start (); } const int TOTAL_ITERATIONS = 100; for (int i = 0; i < TOTAL_ITERATIONS; ++i) { var ad = AppDomain.CreateDomain ("domain_" + i); ad.DoCallBack (new CrossAppDomainDelegate (AllocStuff)); AppDomain.Unload (ad); Console.Write ("."); if (i > 0 && i % 20 == 0) Console.WriteLine (); if (!testTimeout.HaveTimeLeft ()) { var finishTime = DateTime.UtcNow; var ranFor = finishTime - testTimeout.StartTime; Console.WriteLine ("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor, i+1, TOTAL_ITERATIONS); } } Console.WriteLine ("\ndone"); }
static void Main() { for (int i = 0; i < Math.Max(1, Environment.ProcessorCount / 2); ++i) { // for (int i = 0; i < 4; ++i) { var t = new Thread(BackgroundNoise); t.IsBackground = true; t.Start(); } int iterations = 0; for (TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 120 : 5)); timeout.HaveTimeLeft;) { var ad = AppDomain.CreateDomain("domain_" + iterations); ad.DoCallBack(new CrossAppDomainDelegate(AllocStuff)); AppDomain.Unload(ad); Console.Write("."); if ((++iterations) % 20 == 0) { Console.WriteLine(); } } Console.WriteLine($"\ndone {iterations} iterations"); }
static void Main(string[] args) { int iterations = 0; for (TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 120 : 5)); timeout.HaveTimeLeft;) { count = 0; List <Thread> threads = new List <Thread>(); List <System.Timers.Timer> timers = new List <System.Timers.Timer>(); for (int i = 0; i < num_threads; i++) { Thread t3 = new Thread(delegate() { UseMemory(); }); t3.Start(); System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 1000; timer.Start(); timers.Add(timer); } for (int i = 0; i < 4000; i++) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 500; timer.Start(); timers.Add(timer); } lock (count_lock) { while (count < num_threads) { Console.Write("."); Monitor.Wait(count_lock); } } foreach (var t in threads) { t.Join(); } Console.WriteLine(); iterations += 1; } Console.WriteLine($"done {iterations} iterations"); }
public static void Main() { int gcCount = 0; int joinCount = 0; TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 5)); Thread gcThread = new Thread(() => { while (timeout.HaveTimeLeft) { GC.Collect(); gcCount++; Thread.Sleep(1); } }); gcThread.Start(); // Create threads then join them for 1 seconds (120 for stress tests) nonstop while GCs occur once per ms while (timeout.HaveTimeLeft) { BlockingCollection <Thread> threads = new BlockingCollection <Thread> (new ConcurrentQueue <Thread> (), 128); Thread joinThread = new Thread(() => { for (int i = 0; ; ++i) { Thread t = threads.Take(); if (t == null) { break; } t.Join(); // Uncomment this and run with MONO_LOG_LEVEL=info MONO_LOG_MASK=gc // to see GC/join balance in real time //Console.Write ("*"); } }); joinThread.Start(); const int makeThreads = 10 * 1000; for (int i = 0; i < makeThreads; ++i) { Thread t = new Thread(() => { Thread.Yield(); }); t.Start(); threads.Add(t); } threads.Add(null); joinThread.Join(); joinCount += makeThreads; Console.WriteLine("Performed {0} GCs, created {1} threads. Finished? {2}", gcCount, joinCount, !timeout.HaveTimeLeft); } gcThread.Join(); }
static void CrossDomainTest(string name, CrossAppDomainDelegate dele) { TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 5)); Console.WriteLine("----Testing {0}----", name); for (int i = 0; timeout.HaveTimeLeft; ++i) { var ad = AppDomain.CreateDomain(string.Format("domain-{0}-{1}", name, i)); ad.DoCallBack(dele); AppDomain.Unload(ad); } }
public static void Main() { BlockingCollection <Thread> threads = new BlockingCollection <Thread> (128); Thread producer = new Thread(new ThreadStart(() => { DateTime start = DateTime.Now; for (TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 120 : 5)); timeout.HaveTimeLeft;) { Thread worker = new Thread(new ThreadStart(() => { HashSet <string> hashset = new HashSet <string> (); for (int i = 0; i < 50000; ++i) { hashset.Add(string.Concat(i, i)); if (i % 10 == 0) { Thread.Yield(); } } })); worker.Start(); threads.Add(worker); Console.WriteLine("Started thread {0} ({1} running concurrently)", worker.ManagedThreadId, threads.Count); } threads.CompleteAdding(); })); Thread consumer = new Thread(new ThreadStart(() => { while (!threads.IsCompleted) { Thread worker = threads.Take(); worker.Join(); Console.WriteLine("Joined thread {0}", worker.ManagedThreadId); } })); producer.Start(); consumer.Start(); producer.Join(); consumer.Join(); }
public static void Main() { list_size = 1 << 15; TestTimeout timeout = TestTimeout.Start(TimeSpan.FromSeconds(TestTimeout.IsStressTest ? 60 : 5)); for (int it1 = 1; it1 <= 10; it1++, list_size <<= 1) { PinList list = MakeList(list_size); Console.WriteLine("long list constructed {0}", it1); for (int it2 = 0; it2 < 5; it2++) { Benchmark(list, 10 * it1); GC.Collect(1); if (!timeout.HaveTimeLeft) { return; } } } }
static void Main() { var testTimeout = new TestTimeout(); testTimeout.Start(); for (int i = 0; i < Math.Max(1, Environment.ProcessorCount / 2); ++i) { // for (int i = 0; i < 4; ++i) { var t = new Thread(BackgroundNoise); t.IsBackground = true; t.Start(); } const int TOTAL_ITERATIONS = 100; for (int i = 0; i < TOTAL_ITERATIONS; ++i) { var ad = AppDomain.CreateDomain("domain_" + i); ad.DoCallBack(new CrossAppDomainDelegate(AllocStuff)); AppDomain.Unload(ad); Console.Write("."); if (i > 0 && i % 20 == 0) { Console.WriteLine(); } if (!testTimeout.HaveTimeLeft()) { var finishTime = DateTime.UtcNow; var ranFor = finishTime - testTimeout.StartTime; Console.WriteLine("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor, i + 1, TOTAL_ITERATIONS); } } Console.WriteLine("\ndone"); }
static void Main(string[] args) { var testTimeout = new TestTimeout(); testTimeout.Start(); const int TOTAL_ITERATIONS = 2; for (int j = 0; j < TOTAL_ITERATIONS; j++) { count = 0; List <Thread> threads = new List <Thread>(); List <System.Timers.Timer> timers = new List <System.Timers.Timer>(); for (int i = 0; i < num_threads; i++) { Thread t3 = new Thread(delegate() { UseMemory(); }); t3.Start(); System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 1000; timer.Start(); timers.Add(timer); } for (int i = 0; i < 4000; i++) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 500; timer.Start(); timers.Add(timer); } lock (count_lock) { while (count < num_threads) { Console.Write("."); Monitor.Wait(count_lock); } } foreach (var t in threads) { t.Join(); } Console.WriteLine(); if (!testTimeout.HaveTimeLeft()) { var finishTime = DateTime.UtcNow; var ranFor = finishTime - testTimeout.StartTime; Console.WriteLine("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor, j + 1, TOTAL_ITERATIONS); } } Console.WriteLine("done"); }
static void Main (string[] args) { var testTimeout = new TestTimeout (); testTimeout.Start (); const int TOTAL_ITERATIONS = 2; for (int j = 0; j < TOTAL_ITERATIONS; j++) { count = 0; List<Thread> threads = new List<Thread>(); List<System.Timers.Timer> timers = new List<System.Timers.Timer>(); for (int i = 0; i < num_threads; i++) { Thread t3 = new Thread (delegate () { UseMemory(); }); t3.Start (); System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 1000; timer.Start(); timers.Add(timer); } for (int i = 0; i < 4000; i++) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Elapsed += Timer_Elapsed; timer.AutoReset = false; timer.Interval = 500; timer.Start(); timers.Add(timer); } lock (count_lock) { while (count < num_threads) { Console.Write ("."); Monitor.Wait(count_lock); } } foreach (var t in threads) { t.Join(); } Console.WriteLine (); if (!testTimeout.HaveTimeLeft ()) { var finishTime = DateTime.UtcNow; var ranFor = finishTime - testTimeout.StartTime; Console.WriteLine ("Will run out of time soon. ran for {0}, finished {1}/{2} iterations", ranFor, j+1, TOTAL_ITERATIONS); } } Console.WriteLine ("done"); }