Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- public static List<long> ArrayResults = new List<long>();
- public static List<long> ListResults = new List<long>();
- static void Main(string[] args)
- {
- for (int b = 0; b < 100; b++)
- {
- List<int> lst = new List<int>();
- for (int i = 0; i < 1000000; i++)
- {
- lst.Add(i);
- }
- int[] arr = new int[1000000];
- for (int i = 0; i < 1000000; i++)
- {
- arr[i] = i;
- }
- long CurrentArr = DateTimeOffset.Now.ToUnixTimeMilliseconds();
- for (int i = 0; i < 1000000; i++)
- {
- arr[i] = i - 1;
- }
- long LastArr = DateTimeOffset.Now.ToUnixTimeMilliseconds();
- long CurrentLst = DateTimeOffset.Now.ToUnixTimeMilliseconds();
- for (int i = 0; i < 1000000; i++)
- {
- lst[i] = i - 1;
- }
- long LastLst = DateTimeOffset.Now.ToUnixTimeMilliseconds();
- long DiffArr = LastArr - CurrentArr;
- long DiffLst = LastLst - CurrentLst;
- ArrayResults.Add(DiffArr);
- ListResults.Add(DiffLst);
- lst.Clear();
- }
- //Calculating overage
- long totalArr = 0;
- long totalLst = 0;
- for(int i = 0; i<ArrayResults.Count; i++)
- {
- totalArr += ArrayResults[i];
- totalLst += ListResults[i];
- }
- long avgArr = totalArr / ArrayResults.Count;
- long avgLst = totalLst / ListResults.Count;
- Console.WriteLine("---- 100x times test (AVERAGE RESULTS) ----");
- Console.WriteLine("Array 1m read+write: "+avgArr+"ms");
- Console.WriteLine("List 1m read+write: "+avgLst+"ms");
- Console.WriteLine("---------------TOTAL TIME TAKEN------------");
- Console.WriteLine("Array -> " + totalArr + "ms -> " + totalArr / 100 + " seconds.");
- Console.WriteLine("List -> " + totalLst + "ms -> " + totalLst / 100 + " seconds.");
- Console.WriteLine("-------------------------------------------");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement