Introduction
this is not a Compression comparison, but it is to test your compression speed on your pc.
I created this program as a simple zip benchmark which can easily benchmark zips.
Background
This program uses ClosedXML (don't forget to include this in your project reference!) and DotNetZip.
This program is usefull,
a. if you want to test how much you can compress certain files
or
b if you want to test your computers compression speed.
Using the Code
This is the code for executing the benchmark:
static void Main(string[] args)
{
Console.WriteLine("Working...");
StreamWriter sw = new StreamWriter("log.txt");
XLWorkbook workbook = new XLWorkbook();
DataTable table = new DataTable();
table.Columns.Add("Name:", typeof(string));
table.Columns.Add("Uncompressed:", typeof(string));
table.Columns.Add("Compressed kb:", typeof(string));
table.Columns.Add("Compressed b:", typeof(string));
table.Columns.Add("Ratio:", typeof(string));
table.Columns.Add("% Compressed:", typeof(string));
table.Columns.Add("Kilobytes compress: ", typeof(double));
foreach (string s in Files())
{
Console.WriteLine("Zipping files...");
ZipFile zf = new ZipFile();
zf.AddFile("Files\\" + s);
zf.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
string sName = "Zip\\" + s.Split('.')[0] + ".zip";
zf.Save(sName);
Console.WriteLine("Done with zipping" + s + ".");
}
Console.Clear();
foreach (string s in Files())
{
Console.WriteLine("Adding results to log.txt/log.xlsx...");
string sName = "Zip\\" + s.Split('.')[0] + ".zip";
long UnComp = new FileInfo("Files\\" + s).Length / 1024;
long Comp = new FileInfo(sName).Length / 1024;
double UnCompB = (double)new FileInfo("Files\\" + s).Length;
double CompB = (double)new FileInfo(sName).Length;
sw.WriteLine(s + "= Uncompressed: " + (UnComp).ToString() +
"kb " + "Compressed: " + (Comp).ToString() + "kb /
" + CompB + "bytes " + " Ratio: " +
((UnCompB / CompB) / 10) + "%");
table.Rows.Add(s, (UnComp).ToString() + "kb",
(Comp).ToString() + "kb", CompB + "bytes",
((UnCompB / CompB)), ((CompB / UnCompB)) * 100 + "%",
(double)((UnCompB - CompB) / 1024));
Console.Clear();
}
Console.WriteLine("Working...");
Console.WriteLine("Saving log....");
workbook.Worksheets.Add(table, "Data");
workbook.SaveAs("log.xlsx");
sw.Close();
Console.WriteLine("Done.");
Console.WriteLine("Do you want too start log.xlsx? (y/n)");
switch (Console.ReadLine().ToLower())
{
case "y":
Process.Start("log.xlsx");
break;
}
Console.Clear();
Console.WriteLine("Do you want too start log.txt? (y/n)");
switch (Console.ReadLine().ToLower())
{
case "y":
Process.Start("log.txt");
break;
}
}
and this is the code for getting the files:
public static string[] Files()
{
List<string> Result = new List<string>();
foreach (string file in Directory.GetFiles("Files\\"))
{
var f = new FileInfo(file);
Result.Add(f.Name);
}
return Result.ToArray();
}
Put all the files you want to benchmark in the Files\\ folder.
ClosedXML (don't forget to include this in your project reference!)
Points of Interest
The code is not very complex, but I hope you will find it useful!