private static void BenchmarkWithThreads(int totalEquationCount, int threadCount, ThreadPriority priority = ThreadPriority.Normal)
{
if (totalEquationCount % threadCount != 0) throw new Exception();
Console.Write("Время на решение с потоками: ");
int itemsPerThread = totalEquationCount / threadCount; // Кол-во уравнений для каждого потока
Stopwatch watch = Stopwatch.StartNew();
Thread[] solveThreads = new Thread[threadCount];
for (int i = 0, offset = 0; i < solveThreads.Length; i++, offset += itemsPerThread)
{
solveThreads[i] = new Thread(SolveThread)
{
Name = String.Format("Решатель уравнений #{0}", i + 1),
Priority = priority
};
solveThreads[i].Start(itemsPerThread);
}
foreach (Thread solveThread in solveThreads)
{
solveThread.Join();
}
watch.Stop();
Console.WriteLine("{0:F4} сек. Кол-во потоков: {1}. Приоритет: {2}", watch.Elapsed.TotalSeconds, threadCount, PriorityToString(priority));
}