// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Xml; namespace E { public class Program { private const string GOOD = @"C:\test1.xml"; private const string BAD = @"C:\test2.xml"; private const string REAL = @"C:\test3.xml"; private const string WORST = @"C:\test4.xml"; public static void Test1() { StreamWriter sw = new StreamWriter(GOOD); sw.WriteLine(""); for(int i = 0; i < 1000; i++) { sw.WriteLine(""); for(int j = 0; j < 100; j++) { sw.WriteLine("bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla"); } sw.WriteLine(""); } sw.WriteLine(""); sw.Close(); long len = (new FileInfo(GOOD)).Length; Console.WriteLine(len); long mem1 = GC.GetTotalMemory(true); XmlDocument doc = new XmlDocument(); doc.Load(GOOD); long mem2 = GC.GetTotalMemory(true); Console.WriteLine(mem2 - mem1); Console.WriteLine((mem2 - mem1) * 1.0 / len); } public static void Test2() { StreamWriter sw = new StreamWriter(BAD); sw.WriteLine(""); for(int i = 0; i < 1000; i++) { for(int j = 0; j < 100; j++) { sw.WriteLine("bla bla"); } } sw.WriteLine(""); sw.Close(); long len = (new FileInfo(BAD)).Length; Console.WriteLine(len); long mem1 = GC.GetTotalMemory(true); XmlDocument doc = new XmlDocument(); doc.Load(BAD); long mem2 = GC.GetTotalMemory(true); Console.WriteLine(mem2 - mem1); Console.WriteLine((mem2 - mem1) * 1.0 / len); } public static void Test3() { StreamWriter sw = new StreamWriter(REAL); sw.WriteLine(""); for(int i = 0; i < 100000; i++) { sw.WriteLine(" "); sw.WriteLine(" dbtest"); sw.WriteLine(" 127.0.0.1"); sw.WriteLine(" 5432"); sw.WriteLine(" myuser"); sw.WriteLine(" mypwd"); sw.WriteLine(" "); } sw.WriteLine(""); sw.Close(); long len = (new FileInfo(REAL)).Length; Console.WriteLine(len); long mem1 = GC.GetTotalMemory(true); XmlDocument doc = new XmlDocument(); doc.Load(REAL); long mem2 = GC.GetTotalMemory(true); Console.WriteLine(mem2 - mem1); Console.WriteLine((mem2 - mem1) * 1.0 / len); } public static void Test4() { StreamWriter sw = new StreamWriter(WORST); sw.WriteLine(""); for(int i = 0; i < 1000; i++) { for(int j = 0; j < 200; j++) { sw.WriteLine("b"); } } sw.WriteLine(""); sw.Close(); long len = (new FileInfo(WORST)).Length; Console.WriteLine(len); long mem1 = GC.GetTotalMemory(true); XmlDocument doc = new XmlDocument(); doc.Load(WORST); long mem2 = GC.GetTotalMemory(true); Console.WriteLine(mem2 - mem1); Console.WriteLine((mem2 - mem1) * 1.0 / len); } public static void Main(string[] args) { Test1(); Test2(); Test3(); Test4(); } } }