Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ICollection<T>.Add(T) - Performance Test
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Diagnostics; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here var collection = new List<Guid>(); for(var i = 0; i<100000; i++){ collection.Add(Guid.NewGuid()); } string listTime = TestAddSpeed(collection, new List<Guid>()); string hashTime = TestAddSpeed(collection, new HashSet<Guid>()); string collTime = TestAddSpeed(collection, new Collection<Guid>()); string ssTime = TestAddSpeed(collection, new SortedSet<Guid>()); string llTime = TestAddSpeed(collection, new LinkedList<Guid>()); string arrayTime = TestNewArray(collection); Console.WriteLine(string.Format("Hash: {0}", hashTime)); Console.WriteLine(string.Format("List: {0}", listTime)); Console.WriteLine(string.Format("Collection: {0}", collTime)); Console.WriteLine(string.Format("SortedSet: {0}", ssTime)); Console.WriteLine(string.Format("LinkedList: {0}", llTime)); Console.WriteLine(string.Format("Array : {0}", arrayTime)); } private static string TestNewArray(IList<Guid> collection) { var stopwatch = new Stopwatch(); stopwatch.Start(); var arr = new Guid[collection.Count]; for(var i = 0; i< collection.Count-1; i++) { arr[i] = collection[i]; } stopwatch.Stop(); return stopwatch.Elapsed.ToString(); } private static string TestAddSpeed<T>(IList<Guid> collection, T run) where T:ICollection<Guid> { var stopwatch = new Stopwatch(); stopwatch.Start(); for(var i = 0; i < collection.Count-1; i++){ run.Add(collection[i]); } stopwatch.Stop(); run.Clear(); run = default(T); return stopwatch.Elapsed.ToString(); } } }
run
|
edit
|
history
|
help
0
shut down
Main 4-3
Fórum ➡ Prime numbers implemented using LINQ statements AND using FOR loop ♦
ElaineBrown
linear search
IEquatable revised book
Fibonacci Series
Remove xmlns and select signle node
My_Response
de Decimal a Binario