summaryrefslogtreecommitdiff
path: root/week2/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'week2/Program.cs')
-rw-r--r--week2/Program.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/week2/Program.cs b/week2/Program.cs
new file mode 100644
index 0000000..feef98b
--- /dev/null
+++ b/week2/Program.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.Remoting.Channels;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ALGA {
+ class Program {
+ static void Main(string[] args) {
+ int items = 1000;
+ int repetitions = 1_000;
+
+ Stopwatch sw = new Stopwatch();
+ int swaps = 0, comparisons = 0;
+
+ for (int i = 0; i < repetitions; i++) {
+ SortList list = new SortList(items);
+
+ sw.Start();
+ Bubblesort.bubblesort(list);
+ sw.Stop();
+
+ swaps += list.Swaps;
+ comparisons += list.Comparisons;
+ }
+ Console.WriteLine("Unsorted:");
+ Console.WriteLine("\tExec: {0} ns", sw.ElapsedMilliseconds * 10e3 / repetitions);
+ Console.WriteLine("\tSwaps: {0} (avg)", swaps / repetitions);
+ Console.WriteLine("\tComparisons: {0} (avg)", comparisons / repetitions);
+ sw.Reset();
+ swaps = 0;
+ comparisons = 0;
+
+ for (int i = 0; i < repetitions; i++) {
+ SortList list = new SortList(items, true);
+
+ sw.Start();
+ Bubblesort.bubblesort(list);
+ sw.Stop();
+
+ swaps += list.Swaps;
+ comparisons += list.Comparisons;
+ }
+ Console.WriteLine("Sorted:");
+ Console.WriteLine("\tExec: {0} ns", sw.ElapsedMilliseconds * 10e3 / repetitions);
+ Console.WriteLine("\tSwaps: {0} (avg)", swaps / repetitions);
+ Console.WriteLine("\tComparisons: {0} (avg)", comparisons / repetitions);
+ Console.WriteLine("");
+
+ Console.WriteLine("({0} items, {0} repetitions)", items, repetitions);
+
+ Console.ReadLine();
+ }
+ }
+}
+