public void TestSumParallel() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); //var array = Enumerable.Range(0, short.MaxValue).ToArray(); var fastaFile = Utils.GetTestFile(methodName, Path.Combine(Utils.DEFAULT_TEST_FILE_FOLDER, @"MSPathFinderT\ID_002216_235ACCEA.fasta")); var db = new FastaDatabase(fastaFile.FullName); db.Read(); //var indexedDb = new IndexedDatabase(db); //indexedDb.Read(); //var peptides = indexedDb.AnnotationsAndOffsetsNoEnzyme(7, 30); var charArray = db.Characters().Select(c => (int)c).ToList(); // Test methods. var defaultSum = SumAsParallel(charArray); var parallelSum = SumAsParallel(charArray); Console.WriteLine("Default sum {0}", defaultSum); Console.WriteLine("Parallel sum {0}", parallelSum); Assert.AreEqual(parallelSum, defaultSum); const int m = 100; var s1 = Stopwatch.StartNew(); for (var i = 0; i < m; i++) { SumDefault(charArray); } s1.Stop(); var s2 = Stopwatch.StartNew(); for (var i = 0; i < m; i++) { SumAsParallel(charArray); } s2.Stop(); Console.WriteLine("{0:F2} msec/sum, on average for default", s1.Elapsed.TotalMilliseconds / m); Console.WriteLine("{0:F2} msec/sum, on average for parallel", s2.Elapsed.TotalMilliseconds / m); }
public void TestSequenceEnumerationParallel2() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); var sw = new System.Diagnostics.Stopwatch(); var fastaFile = Utils.GetTestFile(methodName, Path.Combine(Utils.DEFAULT_TEST_FILE_FOLDER, @"MSPathFinderT\ID_002216_235ACCEA.fasta")); var db = new FastaDatabase(fastaFile.FullName); db.Read(); var indexedDb = new IndexedDatabase(db); var arr = db.Characters().ToArray(); sw.Start(); //var annotationsAndOffsets = indexedDb.AnnotationsAndOffsetsNoEnzyme(7, 30); // var num = annotationsAndOffsets.AsParallel().LongCount(annotationsAndOffset => annotationsAndOffset.Annotation.IndexOf('W') >= 0); //var num = annotationsAndOffsets.LongCount(annotationsAndOffset => annotationsAndOffset.Annotation.IndexOf('W') >= 0); //var num = arr.AsParallel().Where(c => c == 'W').LongCount(); var num = 0; var sum = 0L; //foreach (var c in arr) for (var a = 0; a < arr.Length; a++) { var c = arr[a]; for (var i = 0; i < c * 10000; i++) { sum += i; } // Interlocked.Increment(ref num); if (++num == 1000) { break; } } Console.WriteLine("NumPeptides: {0}", sum); sw.Stop(); Console.WriteLine(@"{0:f4} sec", sw.Elapsed.TotalSeconds); }
public void TestSumParallel() { var methodName = MethodBase.GetCurrentMethod().Name; TestUtils.ShowStarting(methodName); //var array = Enumerable.Range(0, short.MaxValue).ToArray(); const string dbFile = @"\\proto-2\UnitTest_Files\InformedProteomics_TestFiles\MSPathFinderT\ID_002216_235ACCEA.fasta"; var db = new FastaDatabase(dbFile); db.Read(); //var indexedDb = new IndexedDatabase(db); //indexedDb.Read(); //var peptides = indexedDb.AnnotationsAndOffsetsNoEnzyme(7, 30); var charArray = db.Characters().Select(c => (int)c); // Test methods. Console.WriteLine(SumAsParallel(charArray)); Console.WriteLine(SumDefault(charArray)); const int m = 100; var s1 = Stopwatch.StartNew(); for (var i = 0; i < m; i++) { SumDefault(charArray); } s1.Stop(); var s2 = Stopwatch.StartNew(); for (var i = 0; i < m; i++) { SumAsParallel(charArray); } s2.Stop(); Console.WriteLine((s1.Elapsed.TotalMilliseconds * 1000000 / m).ToString("0.00 ns")); Console.WriteLine((s2.Elapsed.TotalMilliseconds * 1000000 / m).ToString("0.00 ns")); Console.Read(); }