private static async Task SpeedTestSingleThreadedSearchFile() { var tempPath = System.IO.Path.GetTempPath(); var fileName = System.IO.Path.Combine(tempPath, "Level1_1.trim"); var loadedWords = await System.IO.File.ReadAllLinesAsync("words.txt"); using (var blockCache = new ProtoBlockCache(10000)) { var loadedTable = new TableFile(fileName, blockCache); await loadedTable.LoadAsync(); // Check we can get the values back out var hash = new MurmurHash3(); var sw = Stopwatch.StartNew(); foreach (var word in loadedWords) { var utf8 = Encoding.UTF8.GetBytes(word); var h = hash.ComputeHash64(utf8); var result = await loadedTable.GetAsync(utf8, h); var resultAsString = Encoding.UTF8.GetString(result.Value.Span); } sw.Stop(); Console.WriteLine($"Total time taken {sw.ElapsedMilliseconds} time per key {(double)sw.ElapsedMilliseconds / loadedWords.Length}"); } }
public void GlobalSetup() { _cache = new ProtoBlockCache(10); var tempPath = System.IO.Path.GetTempPath(); var fileName = System.IO.Path.Combine(tempPath, "Level1_1.trim"); _file = new TableFile(fileName, _cache); _file.LoadAsync().Wait(); }
public async Task WriteAndReadAsyncBlockFile() { using var allocator = new NativeAllocator64(4096 * 20_000, 25); var memoryTable = new SkipList64(allocator); var loadedWords = CommonData.Words; foreach (var word in loadedWords) { if (string.IsNullOrEmpty(word)) { continue; } var utf8 = Encoding.UTF8.GetBytes(word); var value = Encoding.UTF8.GetBytes($"VALUE={word}"); Assert.True(memoryTable.Put(utf8, value)); } var tempPath = System.IO.Path.GetTempPath(); var fileName = System.IO.Path.Combine(tempPath, "Level1_1.trim"); System.IO.File.Delete(fileName); var fw = new TableFileWriter(fileName); await fw.SaveMemoryTable(memoryTable); using (var blockCache = new ProtoBlockCache(10000)) { var loadedTable = new TableFile(fileName, blockCache); await loadedTable.LoadAsync(); // Check we can get the values back out var hash = new MurmurHash3(); foreach (var word in loadedWords) { var utf8 = Encoding.UTF8.GetBytes(word); var h = hash.ComputeHash64(utf8); var result = await loadedTable.GetAsync(utf8, h); var resultAsString = Encoding.UTF8.GetString(result.Value.Span); result.Result.Should().Be(SearchResult.Found); resultAsString.Should().EndWith(word); } } }