public static List <TimeSpan> ExecuteBencmark(int n) { var times = new List <TimeSpan>(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var stud = new List <Stud>(); for (int i = 0; i < n; i++) { stud.Add(new Stud($"Vardas{i} Pavarde{i} x5")); } times.Add(sw.Elapsed); sw.Restart(); var v = new List <Stud>(); var k = new List <Stud>(); for (int i = 0; i < n; i++) { if (stud[i].GetMean() < 5) { v.Add(stud[i]); } else { k.Add(stud[i]); } } times.Add(sw.Elapsed); sw.Restart(); v = Studentai.OrderStudents(v).ToList(); k = Studentai.OrderStudents(k).ToList(); times.Add(sw.Elapsed); sw.Restart(); string path = System.IO.Path.GetTempFileName(); Studentai.WriteStudents(path, v); System.IO.File.Delete(path); times.Add(sw.Elapsed); sw.Restart(); path = System.IO.Path.GetTempFileName(); Studentai.WriteStudents(path, k); System.IO.File.Delete(path); times.Add(sw.Elapsed); return(times); }
public static List <TimeSpan> TestListDel(int size) { var times = new List <TimeSpan>(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var container = new List <Stud>(); for (int i = 0; i < size; i++) { container.Add(new Stud($"Vardas{i} Pavarde{i} x5")); } times.Add(sw.Elapsed); sw.Restart(); var a = new List <Stud>(); var b = new List <Stud>(); for (int i = size - 1; i >= 0; i--) { if (container[i].GetMean() < 5) { a.Add(container[i]); } else { b.Add(container[i]); } container.RemoveAt(i); } times.Add(sw.Elapsed); sw.Restart(); a = Studentai.OrderStudents(a).ToList(); b = Studentai.OrderStudents(b).ToList(); times.Add(sw.Elapsed); sw.Restart(); string path = System.IO.Path.GetTempFileName(); Studentai.WriteStudents(path, container); System.IO.File.Delete(path); times.Add(sw.Elapsed); sw.Restart(); return(times); }
public static List <TimeSpan> TestLinkedListLast(int size) { var times = new List <TimeSpan>(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); var container = new LinkedList <Stud>(); for (int i = 0; i < size; i++) { container.AddLast(new Stud($"Vardas{i} Pavarde{i} x5")); } times.Add(sw.Elapsed); sw.Restart(); var a = new LinkedList <Stud>(); var b = new LinkedList <Stud>(); for (int i = 0; i < size; i++) { var element = container.Last(); if (element.GetMean() < 5) { a.AddLast(element); } else { b.AddLast(element); } container.RemoveLast(); } times.Add(sw.Elapsed); sw.Restart(); a = new LinkedList <Stud>(Studentai.OrderStudents(a)); b = new LinkedList <Stud>(Studentai.OrderStudents(b)); times.Add(sw.Elapsed); sw.Restart(); string path = System.IO.Path.GetTempFileName(); Studentai.WriteStudents(path, container); System.IO.File.Delete(path); times.Add(sw.Elapsed); return(times); }