Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- System.Diagnostics.Stopwatch sw1 = new System.Diagnostics.Stopwatch();
- sw1.Start();
- StackAllocation();
- Console.WriteLine(sw1.ElapsedTicks);
- System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch();
- sw2.Start();
- HeapAllocation();
- Console.WriteLine(sw2.ElapsedTicks);
- }
- static unsafe void StackAllocation()
- {
- for (int i = 0; i < 100; i++)
- {
- int* p = stackalloc int[100];
- }
- }
- static void HeapAllocation()
- {
- for (int i = 0; i < 100; i++)
- {
- int[] a = new int[100];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement