Created
July 30, 2014 21:06
-
-
Save RyuaNerin/25dd8ae640fb46555375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace pConsole | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
long start; | |
long end; | |
long startMem; | |
long endMem; | |
int now; | |
int count = 0x2FFFFFFF; | |
////////////////////////////////////////////////////////////////////////// | |
start = DateTime.UtcNow.Ticks; | |
MemoryStream stream = new MemoryStream(); | |
for (now = 0; now < count; now++) | |
stream.WriteByte(0x00); | |
end = DateTime.UtcNow.Ticks; | |
GC.Collect(); | |
startMem = System.GC.GetTotalMemory(true); | |
stream.Dispose(); | |
stream = null; | |
GC.Collect(); | |
endMem = System.GC.GetTotalMemory(true); | |
Console.WriteLine("MemoryStream"); | |
Console.WriteLine("Total {0:# ##0.000000} sec", TimeSpan.FromTicks(end - start).TotalSeconds); | |
Console.WriteLine("Memory {0} Bytes", (startMem - endMem)); | |
////////////////////////////////////////////////////////////////////////// | |
Console.WriteLine(); | |
Console.WriteLine(); | |
////////////////////////////////////////////////////////////////////////// | |
start = DateTime.UtcNow.Ticks; | |
List<byte> lst = new List<byte>(); | |
for (now = 0; now < count; now++) | |
lst.Add(0x00); | |
end = DateTime.UtcNow.Ticks; | |
GC.Collect(); | |
startMem = System.GC.GetTotalMemory(true); | |
lst = null; | |
GC.Collect(); | |
endMem = System.GC.GetTotalMemory(true); | |
Console.WriteLine("List<byte>"); | |
Console.WriteLine("Total {0:# ##0.000000} sec", TimeSpan.FromTicks(end - start).TotalSeconds); | |
Console.WriteLine("Memory {0} Bytes", (startMem - endMem)); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment