Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- namespace CSConsole
- {
- public static class Program
- {
- public static void Main(string[] args)
- {
- Stopwatch sw = new Stopwatch();
- int[] array1 = new int[1024 * 1024];
- object[] array2 = new object[array1.Length];
- int[] array3 = new int[array1.Length];
- Random random = new Random();
- for (int index = 0; index < array1.Length; index++)
- {
- array1[index] = random.Next();
- }
- sw.Start();
- for (int loop = 0; loop < 100; loop++)
- {
- for (int index = 0; index < array1.Length; index++)
- {
- array2[index] = array1[index];
- }
- }
- sw.Stop();
- Console.WriteLine("Boxing: {0}", sw.Elapsed);
- sw.Reset();
- sw.Start();
- for (int loop = 0; loop < 100; loop++)
- {
- for (int index = 0; index < array1.Length; index++)
- {
- array1[index] = (int)array2[index];
- }
- }
- sw.Stop();
- Console.WriteLine("Unboxing: {0}", sw.Elapsed);
- sw.Reset();
- sw.Start();
- for (int loop = 0; loop < 100; loop++)
- {
- for (int index = 0; index < array1.Length; index++)
- {
- array3[index] = array1[index];
- }
- }
- sw.Stop();
- Console.WriteLine("Copying: {0}", sw.Elapsed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement