From ccf6f216c30afe387aece5ecfc828fba3a668323 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 12 Mar 2017 20:59:18 +0300 Subject: [PATCH] Additional debug info --- README.md | 8 +++++--- WhiteRabbit/Program.cs | 11 ++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 52824e2..3b3781d 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ That's why the given hashes are solved much sooner than it takes to check all an Single-threaded performance on Sandy Bridge @2.8GHz is as follows: -* If only phrases of at most 3 words are allowed, then it takes 2.5 seconds to find and check all anagrams; all relevant hashes are solved in first 0.4 seconds; +* If only phrases of at most 3 words are allowed, then it takes 2.5 seconds to find and check all 4560 anagrams; all relevant hashes are solved in first 0.4 seconds; -* If phrases of 4 words are allowed as well, then it takes 40 seconds to find and check all anagrams; all hashes are solved in first 3 seconds; +* If phrases of 4 words are allowed as well, then it takes 40 seconds to find and check all 7433016 anagrams; all hashes are solved in first 3 seconds; For comparison, certain other solutions available on GitHub seem to require 3 hours to find all 3-word anagrams (i.e. this solution is faster by a factor of 4000 in 3-word case). @@ -32,10 +32,12 @@ Anagrams generation is not parallelized, as even single-threaded performance for Multi-threaded performance with RyuJIT (.NET 4.6, 64-bit system) is as follows: -* If only phrases of at most 4 words are allowed, then it takes less than 10 seconds to find and check all anagrams; all hashes are solved in first 1 second. +* If only phrases of at most 4 words are allowed, then it takes less than 10 seconds to find and check all 7433016 anagrams; all hashes are solved in first 1 second. * If phrases of 5 words are allowed as well, then it takes around 18 minutes to find and check all anagrams; all hashes are solved in first 25 seconds. Most of time is spent on MD5 computations for correct anagrams, so there is not a lot to optimize further. * If phrases of 6 words are allowed as well, then "more difficult" hash is solved in 50 seconds, "easiest" in 3.5 minutes, and "hard" in 6 minutes. * If phrases of 7 words are allowed as well, then "more difficult" hash is solved in 6 minutes. + +Note that all measurements were done on a Release build; Debug build is significantly slower. diff --git a/WhiteRabbit/Program.cs b/WhiteRabbit/Program.cs index aa07566..8be319d 100644 --- a/WhiteRabbit/Program.cs +++ b/WhiteRabbit/Program.cs @@ -36,16 +36,21 @@ var processor = new StringsProcessor(Encoding.ASCII.GetBytes(SourcePhrase), MaxWordsInPhrase, ReadInput()); - Console.WriteLine($"Initialization complete; time spent: {stopwatch.Elapsed}"); + Console.WriteLine($"Initialization complete; time from start: {stopwatch.Elapsed}"); + +#if DEBUG + var totalAnagramsCount = processor.GeneratePhrases().Count(); + Console.WriteLine($"Total anagrams count: {totalAnagramsCount}; time from start: {stopwatch.Elapsed}"); +#endif processor.GeneratePhrases() .Select(phraseBytes => new { phraseBytes, hashVector = ComputeHashVector(phraseBytes) }) .Where(tuple => expectedHashesAsVectors.Contains(tuple.hashVector)) .Select(tuple => new { phrase = Encoding.ASCII.GetString(tuple.phraseBytes), hash = VectorToHexadecimalString(tuple.hashVector) }) - .ForAll(phraseInfo => Console.WriteLine($"Found phrase for {phraseInfo.hash}: {phraseInfo.phrase} (spent {stopwatch.Elapsed})")); + .ForAll(phraseInfo => Console.WriteLine($"Found phrase for {phraseInfo.hash}: {phraseInfo.phrase}; time from start is {stopwatch.Elapsed}")); stopwatch.Stop(); - Console.WriteLine($"Total time spent: {stopwatch.Elapsed}"); + Console.WriteLine($"Done; time from start: {stopwatch.Elapsed}"); } // Code taken from http://stackoverflow.com/a/321404/831314