private static void Main()
        {
            _outputWriter.WriteLine("* Environment Architecture: {0}", Environment.Is64BitProcess ? "x64" : "x86");
            _outputWriter.NewLines();

            using (_outputWriter.Indent(2))
            {
                // guid output
                var guidSteps = new Dictionary <string, Tuple <HashAlgorithm, int> >
                {
                    { "Murmur 32 Managed", Tuple.Create(_managed32, _fastIterationCount) },
                    { "Murmur 32 Unanaged", Tuple.Create(_unmanaged32, _fastIterationCount) },
                    { "Murmur 128 Managed", Tuple.Create(_managed, _fastIterationCount) },
                    { "Murmur 128 Unmanaged", Tuple.Create(_unmanaged, _fastIterationCount) },
                    { "SHA1", Tuple.Create(_sha1, _slowIterationCount) },
                    { "MD5", Tuple.Create(_md5, _slowIterationCount) }
                };

                Run("Guid x 8", _sampleData.LongLength, a => a.ComputeHash(_sampleData), guidSteps);
                Run("Guid x 8 Partial", _sampleData.LongLength - 3, a => a.ComputeHash(_sampleData, 3, (int)(_sampleData.LongLength - 3)), guidSteps);

                // random data tests
                var randomSteps = new Dictionary <string, Tuple <HashAlgorithm, int> >
                {
                    { "Murmur 32 Managed", Tuple.Create(_managed32, 2999) },
                    { "Murmur 32 Unanaged", Tuple.Create(_unmanaged32, 2999) },
                    { "Murmur 128 Managed", Tuple.Create(_managed, 2999) },
                    { "Murmur 128 Unmanaged", Tuple.Create(_unmanaged, 2999) },
                    { "SHA1", Tuple.Create(_sha1, 2999) },
                    { "MD5", Tuple.Create(_md5, 2999) }
                };

                Run("Random", _randomData.LongLength, a => a.ComputeHash(_randomData), randomSteps);

                using (var stream = new MemoryStream(_randomData))
                {
                    Func <HashAlgorithm, byte[]> streamhasher = a =>
                    {
// ReSharper disable AccessToDisposedClosure
                        stream.Position = 0L;
                        return(a.ComputeHash(stream));
// ReSharper restore AccessToDisposedClosure
                    };

                    Run("Stream", stream.Length, streamhasher, randomSteps);
                }
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to exit.");
                Console.Read();
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            OutputWriter.WriteLine("* Environment Architecture: {0}", Environment.Is64BitProcess ? "x64" : "x86");
            OutputWriter.NewLines(1);

            using (OutputWriter.Indent(2))
            {
                // guid output
                var guidSteps = new Dictionary <string, Tuple <HashAlgorithm, int> >
                {
                    { "Murmur 32 Managed", Tuple.Create(Managed32, FAST_ITERATION_COUNT) },
                    { "Murmur 32 Unanaged", Tuple.Create(Unmanaged32, FAST_ITERATION_COUNT) },
                    { "Murmur 128 Managed", Tuple.Create(Managed, FAST_ITERATION_COUNT) },
                    { "Murmur 128 Unmanaged", Tuple.Create(Unmanaged, FAST_ITERATION_COUNT) },
                    { "SHA1", Tuple.Create(Sha1, SLOW_ITERATION_COUNT) },
                    { "MD5", Tuple.Create(Md5, SLOW_ITERATION_COUNT) }
                };

                Run(name: "Guid x 8", dataLength: SampleData.LongLength, hasher: a => a.ComputeHash(SampleData), steps: guidSteps);
                Run(name: "Guid x 8 Partial", dataLength: SampleData.LongLength - 3, hasher: a => a.ComputeHash(SampleData, 3, (int)(SampleData.LongLength - 3)), steps: guidSteps);

                // random data tests
                var randomSteps = new Dictionary <string, Tuple <HashAlgorithm, int> >
                {
                    { "Murmur 32 Managed", Tuple.Create(Managed32, 2999) },
                    { "Murmur 32 Unanaged", Tuple.Create(Unmanaged32, 2999) },
                    { "Murmur 128 Managed", Tuple.Create(Managed, 2999) },
                    { "Murmur 128 Unmanaged", Tuple.Create(Unmanaged, 2999) },
                    { "SHA1", Tuple.Create(Sha1, 2999) },
                    { "MD5", Tuple.Create(Md5, 2999) }
                };

                Run(name: "Random", dataLength: RandomData.LongLength, hasher: a => a.ComputeHash(RandomData), steps: randomSteps);

                using (var stream = new MemoryStream(RandomData))
                {
                    Func <HashAlgorithm, byte[]> streamhasher = a =>
                    {
                        stream.Position = 0L;
                        return(a.ComputeHash(stream));
                    };

                    Run(name: "Stream", dataLength: stream.Length, hasher: streamhasher, steps: randomSteps);
                }
            }

            if (Debugger.IsAttached)
            {
                Console.WriteLine("Press any key to exit.");
                Console.Read();
            }
        }