コード例 #1
0
ファイル: Program.cs プロジェクト: parrottsquawk/School
        public static void RunBinaryTestOnce(BitArray text, BitArray pattern, int times = 10000)
        {
            Console.WriteLine("T: " + BitArrayToString(text));
              Console.WriteLine("P: " + BitArrayToString(pattern));
              Console.WriteLine();

              SuffixArrayBin sa = new SuffixArrayBin(text);
              BurrowsWheelerTransformBin bwt = new BurrowsWheelerTransformBin(sa);
              int answer = 0;

              // BWT
              Stopwatch sw = Stopwatch.StartNew();
              for (int i = 0; i < times; i++) {
            answer = bwt.CountOccurrences(pattern);
              }
              double time = ((double)sw.ElapsedMilliseconds) / times;
              Console.WriteLine("BWT:\n====");
              Console.WriteLine("     Time: " + time + " ms");
              Console.WriteLine("  Matches: " + answer.ToString());
              Console.WriteLine();

              // Brute Force
              Stopwatch sw2 = Stopwatch.StartNew();
              for (int i = 0; i < times; i++) {
            answer = BruteForce.Run(text, pattern);
              }
              double time2 = ((double)sw2.ElapsedMilliseconds) / times;
              Console.WriteLine("BF:\n====");
              Console.WriteLine("     Time: " + time2 + " ms");
              Console.WriteLine("  Matches: " + answer.ToString());
              Console.WriteLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: parrottsquawk/School
        public static void RunBinaryTestFiles()
        {
            const string DirectoryString = @"..\..";
              var gen = new Random();
              var files = Directory.EnumerateFiles(DirectoryString + @"\GenFiles\", "*").Where(u => u.Contains(@"GenFiles\B_"));
              StringBuilder output = new StringBuilder();
              int fileNum = 0;
              foreach (var file in files) {
            var ob = new StatObj { FileName = file };
            var commandLineInterpreter = new CommandInterpreter() { Encoding = Encoding.Default, Path = ob.FileName };
            var fileReader = new BinaryFileReader(commandLineInterpreter);
            var sa = new SuffixArrayBin(fileReader.Data);
            var bwt = new BurrowsWheelerTransformBin(sa);
            for (var i = 1; i < Math.Min(20, ob.FileSize / 2); i++) {
              ob.PatternSize = i;
              BitArray pattern = fileReader.Data.Substring(
              (int)(
                  (ob.FileSize - ob.PatternSize) * gen.NextDouble()
                  ), ob.PatternSize
              );

              // Settings and timers
              //===============================================================
              int times = 100;
              Stopwatch sw;
              //===============================================================

              // BWT
              //===============================================================
              StatObj bwtStat = ob;
              bwtStat.EndTimeTicks = 0;
              bwtStat.Results = 0;
              bwtStat.RuntimeTicks = 0;
              bwtStat.StartTimeTicks = 0;

              sw = Stopwatch.StartNew();
              for (int t = 0; t < times; t++) {
            bwtStat.Results = bwt.CountOccurrences(pattern);
              }
              sw.Stop();

              bwtStat.RuntimeTicks = sw.ElapsedMilliseconds;
              //===============================================================

              // BF
              //===============================================================
              StatObj bfStat = ob;
              bfStat.EndTimeTicks = 0;
              bfStat.Results = 0;
              bfStat.RuntimeTicks = 0;
              bfStat.StartTimeTicks = 0;

              sw = Stopwatch.StartNew();
              for (int t = 0; t < times; t++) {
            bfStat.Results = BruteForce.Run(fileReader.Data, pattern);
              }
              sw.Stop();

              bfStat.RuntimeTicks = sw.ElapsedMilliseconds;
              //===============================================================

              // Print Results
              //===============================================================
              int m = ob.PatternSize;
              int n = ob.FileSize;

              output.AppendLine(String.Format("BWT,{0},{1},{2},{3},{4}", bwtStat.RuntimeTicks, m, n, bwtStat.Results, "Binary"));
              output.AppendLine(String.Format("BruteForce,{0},{1},{2},{3},{4}", bfStat.RuntimeTicks, m, n, bfStat.Results, "Binary"));
              //===============================================================
            }
            fileNum++;
            Console.WriteLine(((((double)fileNum) / files.ToArray<string>().Length) * 100).ToString() + " %");
              }
              using (StreamWriter writer = new StreamWriter(DirectoryString + @"\GenFiles\BinaryResults.csv")) {
            writer.Write(output.ToString());
              }
        }