Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ZIP Benchmark

0.00/5 (No votes)
7 Apr 2016 1  
A simple zip benchmark

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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here