Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (58 loc) · 2.16 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Diagnostics;
using BadThreadPool;
namespace ThreadPoolTest
{
internal class Program
{
static void Main()
{
PiCalculatorTest piCalc = new();
const int testAmount = int.MaxValue >> 1 >> 1 >> 1 >> 1 >> 1;
List<ThreadTaskRequest> getReturns = new();
Stopwatch watch = new();
watch.Start();
ThreadPoolClass threadPool = new();
Console.WriteLine(testAmount);
threadPool.InitializePool();
threadPool.IgniteThreadPool();
for (uint i = 0; i < testAmount; i++)
{
threadPool.AddRequest(piCalc.Calc_Pi);
}
while (!threadPool.AllThreadsIdle())
{
}
watch.Stop();
double mtTime = watch.ElapsedMilliseconds * 0.001;
Console.WriteLine("Completed, Time in seconds {0}", mtTime);
watch.Restart();
for (uint i = 0; i < testAmount; i++)
{
getReturns.Add(threadPool.AddRequest(piCalc.Calc_Pi, piCalc.Test_Threading_callback));
}
while (!threadPool.AllThreadsIdle())
{
}
watch.Stop();
Console.WriteLine("Completed, Time in seconds {0}", watch.ElapsedMilliseconds * 0.001);
Console.WriteLine("Shutting down");
threadPool.ShutDownHandler();
Console.WriteLine("Single Threaded Test!");
watch.Reset();
watch.Start();
for (uint i = 0; i < testAmount; i++)
{
piCalc.Calc_Pi();
}
Console.WriteLine("Completed, Time in seconds {0}", watch.ElapsedMilliseconds * 0.001);
Console.WriteLine("Single core performance was: {0}% slower", CalculatePercentDifference(watch.ElapsedMilliseconds * 0.001, mtTime));
Console.WriteLine(getReturns[0].Result);
}
static int CalculatePercentDifference(double a, double b)
{
return (int)((a - b) / Math.Abs(b) *100);
}
}
}