34
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading;
6
using System.Threading.Tasks;
7
8
public class Program
9
{
10
public static void Main(string[] args)
11
{
12
List<int> list = new List<int>();
13
list.AddRange(new int[] {1034, 1200, 1300, 1400, 1234 });
14
15
// create a bunch of threads
16
List<Thread> threads = new List<Thread>();
17
list.ForEach(x => threads.Add(new Thread(() => ThreadMethod(x))));
18
19
// start them
20
threads.ForEach(x => x.Start());
21
22
// wait for them to finish
23
threads.ForEach(x => x.Join());
24
25
// this will not print untill all threads have completed
26
Console.WriteLine("End");
27
}
28
29
private static void ThreadMethod(int i)
30
{
31
Thread.Sleep(i);
32
Console.WriteLine("Thread: " + i);
33
}
34
}
Cached Result
Average time for Sort: 6.75 ms
Average time for ChaosMonkey: 13.75 ms
Average time for CountingSort: 12 ms
Average time for Mo B. Max-Heap: 3.5 ms
Average time for Mo B. Alternative (Quickselect): 3.5 ms
>
Average time for ChaosMonkey: 13.75 ms
Average time for CountingSort: 12 ms
Average time for Mo B. Max-Heap: 3.5 ms
Average time for Mo B. Alternative (Quickselect): 3.5 ms