Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created September 13, 2017 05:57
Show Gist options
  • Save gerrard00/1a2584adcc84163f4d8cc69e40022092 to your computer and use it in GitHub Desktop.
Save gerrard00/1a2584adcc84163f4d8cc69e40022092 to your computer and use it in GitHub Desktop.
Xml Compression tests
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace Test
{
class Test
{
static void Main()
{
var stopWatch = new Stopwatch();
stopWatch.Start();
using(var inputStream = File.OpenRead(@"c:\junk\supp2017.xml"))
{
var doc = new XmlDocument();
doc.Load(inputStream);
}
stopWatch.Stop();
Console.WriteLine("Loading xml {0}", stopWatch.Elapsed.TotalMilliseconds);
Console.WriteLine("Done");
}
}
}
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Xml;
namespace Test
{
class Test
{
static void Main()
{
var stopWatch = new Stopwatch();
stopWatch.Start();
using(var inputStream = File.OpenRead(@"c:\junk\supp2017.xml.cmp"))
{
using (DeflateStream decompressingStream = new DeflateStream(inputStream, CompressionMode.Decompress))
{
var doc = new XmlDocument();
doc.Load(decompressingStream);
}
}
stopWatch.Stop();
Console.WriteLine("Loading xml {0}", stopWatch.Elapsed.TotalMilliseconds);
Console.WriteLine("Done");
}
}
}
@robert4
Copy link

robert4 commented Sep 14, 2017

You convinced me that XmlDocument.Load() is slow enough to be on par with the extremely slow disk I/O (especially for GB-sized documents), but still isn't slow enough to render compression worthless as you stated. So your reasoning is not completely wrong – I'm willing to remove the downvote from your answer. But this can be done only after editing it because 2+ days has elapsed. Thank you for the constructive discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment