public async Task Performance(IDigraphsLookup implementation) { const int warmups = 1000; const int runs = 1000; var digraphs = new[] { "ab", "ad", "af", "ag", "ar" }; var bookPath = GetBookPath("Frankenstein"); using (var stream = new MemoryStream(await File.ReadAllBytesAsync(bookPath))) { // Health Check LookupResult[] result; using (var copy = new MemoryStream(stream.ToArray())) { result = await implementation.LookupAsync(copy, digraphs); } CollectionAssert.AreEquivalent(new[] { new LookupResult("ab", 668), new LookupResult("ad", 1282), new LookupResult("af", 246), new LookupResult("ag", 659), new LookupResult("ar", 2593) }, result); // Warmup for (var i = 0; i < warmups; i++) { using (var copy = new MemoryStream(stream.ToArray())) { await implementation.LookupAsync(copy, digraphs); } } // Run var watch = new Stopwatch(); var times = new long[runs]; for (var i = 0; i < runs; i++) { using (var copy = new MemoryStream(stream.ToArray())) { GC.Collect(); watch.Restart(); await implementation.LookupAsync(copy, digraphs); watch.Stop(); } times[i] = watch.ElapsedMilliseconds; } WriteTimings(implementation.GetType().Name, times); } }
public async Task FindOneDigraph(IDigraphsLookup implementation) { LookupResult[] result; using (var stream = GivenStream("ab")) { result = await implementation.LookupAsync(stream, "ab"); } CollectionAssert.AreEquivalent(new[] { new LookupResult("ab", 1) }, result); }
public async Task EmptyTextAlwaysReturnZeroes(IDigraphsLookup implementation) { LookupResult[] result; using (var stream = GivenStream("")) { result = await implementation.LookupAsync(stream, "ab", "ad", "af"); } CollectionAssert.AreEquivalent(new[] { new LookupResult("ab", 0), new LookupResult("ad", 0), new LookupResult("af", 0) }, result); }