-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
139 lines (103 loc) · 4.04 KB
/
MainWindow.xaml.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Threading;
using System.Windows.Media.Animation;
namespace Benchmark_Multi
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// ------------ Options ------------
private int maxTurns = 800;
private int incrementTop = 100000000;
private int searchValueString = 500000;
private int logicalProcessors = Environment.ProcessorCount;
private double swBenchIncrement = 0;
private double swBenchStringSearch = 0;
private bool benchIsRunning = false;
public MainWindow()
{
InitializeComponent();
Trace.WriteLine("Number Of Logical Processors: " + logicalProcessors.ToString());
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
/* ProgressBar progbar = new ProgressBar();
progbar.IsIndeterminate = true;
progbar.Orientation = Orientation.Horizontal;
Duration duration = new Duration(TimeSpan.FromSeconds(3));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);*/
if (!benchIsRunning)
{
benchIsRunning = true;
lbl_message.Content = "Benchmark 1 of 2. Please Wait";
await SimulateProgressBar(pBar0);
BenchIncrement();
await Task.Delay(3000);
await SimulateProgressBar(pBar0);
BenchStringSearch();
}
else
{
lbl_message.Content = "Benchmark was startet already, please wait!";
}
}
public static async Task SimulateProgressBar(ProgressBar pBar)
{
pBar.Value = 0;
for (int i = 0; i < 101; i++)
{
await Task.Delay(40);
pBar.Value += i;
}
}
private void BenchIncrement()
{
Benchmark bench = new Benchmark(maxTurns, incrementTop, searchValueString, logicalProcessors);
bench.StartBenchIncrement();
Thread.Sleep(100);
var SwIncrement = Stopwatch.StartNew();
while (bench.GetTurnsAllThreads() < maxTurns)
{
Thread.Sleep(1);
}
SwIncrement.Stop();
lbl_message.Content = "Benchmark 2 of 2. Please Wait";
swBenchIncrement = Math.Round(SwIncrement.Elapsed.TotalMilliseconds, 2);
lbl_result.Content = "Bench 1: " + swBenchIncrement + "ms";
// lbl_result.Content = "Time: " + SwIncrement.Elapsed.TotalMilliseconds / (double)maxTurns + "ms";
}
private void BenchStringSearch()
{
Benchmark bench = new Benchmark(maxTurns, incrementTop, searchValueString, logicalProcessors);
bench.StartBenchStringSearch();
Thread.Sleep(100);
var Sw = Stopwatch.StartNew();
while (bench.GetTurnsAllThreads() < maxTurns)
{
Thread.Sleep(1);
}
Sw.Stop();
lbl_message.Content = "Benchmark Complete";
swBenchStringSearch = Math.Round(Sw.Elapsed.TotalMilliseconds, 2);
lbl_result.Content = "Benchmark Total: " + (swBenchStringSearch + swBenchIncrement) + "ms" + " Bench 1: " + swBenchIncrement + "ms" + " Bench 2: " + swBenchStringSearch + "ms";
benchIsRunning = false;
}
}
}