Created
August 10, 2014 22:19
-
-
Save RyuaNerin/3ce3b6981be444fcbf94 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.Security.Cryptography; | |
using System.Text; | |
namespace pConsole | |
{ | |
class Program | |
{ | |
static Random rnd = new Random(DateTime.Now.Millisecond); | |
static void Main(string[] args) | |
{ | |
string k; | |
int[] sizes = { 128 * 1024, 256 * 1024, 512 * 1024, 1 * 1024 * 1024, 128 * 1024 * 1024, 256 * 1024 * 1024, 512 * 1024 * 1024}; | |
Console.WriteLine(" ----------------------------------------------------------------------------"); | |
Console.WriteLine(" | Algorithm | 128 kb | 256 kb | 512 kb | 1 mb | 128 mb | 256 mb | 512 mb |"); | |
Console.WriteLine(" ----------------------------------------------------------------------------"); | |
Hash(sizes, "md5", MD5.Create()); | |
Hash(sizes, "sha-1", SHA1.Create()); | |
Hash(sizes, "sha-256", SHA256.Create()); | |
Hash(sizes, "sha-384", SHA384.Create()); | |
Hash(sizes, "sha-512", SHA512.Create()); | |
Console.WriteLine(" ----------------------------------------------------------------------------"); | |
Console.ReadKey(); | |
Console.ReadKey(); | |
Console.ReadKey(); | |
} | |
static void Hash(int[] buffSize, string algo, HashAlgorithm hash) | |
{ | |
long startTick, endTick; | |
long ticks; | |
int i = 0; | |
Console.Write(" | {0, 9} |", algo); | |
using (hash) | |
{ | |
foreach (int size in buffSize) | |
{ | |
byte[] buff = new byte[size]; | |
rnd.NextBytes(buff); | |
ticks = 0; | |
for (i = 0; i < 5; i++) | |
{ | |
startTick = DateTime.UtcNow.Ticks; | |
hash.ComputeHash(buff); | |
endTick = DateTime.UtcNow.Ticks; | |
ticks += endTick - startTick; | |
} | |
Console.Write(" {0,6:#0.0} |", TimeSpan.FromTicks(ticks).TotalMilliseconds / 5); | |
} | |
Console.WriteLine(); | |
GC.Collect(); | |
hash.Clear(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment