Ejemplo n.º 1
0
        static async Task MemoryMappedDecode()
        {
            const string path = "t8.shakespeare.txt";

            Console.WriteLine();
            var fi = new FileInfo(path);

            if (!fi.Exists)
            {
                Console.WriteLine($"Input file not found: {path}");
                return;
            }
            const int REPEAT = 10;
            var       enc    = Encoding.ASCII;

            Console.WriteLine($"Reading: {fi.Name}, {fi.Length} bytes, encoding: {enc.EncodingName}");
            Console.WriteLine();
            Console.WriteLine("Using PipeTextReader/MemoryMappedPipeReader (no buffer)");
            for (int i = 0; i < REPEAT; i++)
            {
                var mmap = MemoryMappedPipeReader.Create(path);
                using (mmap as IDisposable)
                    using (var reader = PipeTextReader.Create(mmap, enc, bufferSize: 0))
                    {
                        var watch = Stopwatch.StartNew();
                        var s     = await TestReaderTests.MeasureAndTime(reader);

                        watch.Stop();
                        Console.WriteLine($"{s}; time taken: {watch.ElapsedMilliseconds}ms");
                    }
            }
            Console.WriteLine();
            Console.WriteLine("Using PipeTextReader/MemoryMappedPipeReader (leased buffer)");
            for (int i = 0; i < REPEAT; i++)
            {
                var mmap = MemoryMappedPipeReader.Create(path);
                using (mmap as IDisposable)
                    using (var reader = PipeTextReader.Create(mmap, enc))
                    {
                        var watch = Stopwatch.StartNew();
                        var s     = await TestReaderTests.MeasureAndTime(reader);

                        watch.Stop();
                        Console.WriteLine($"{s}; time taken: {watch.ElapsedMilliseconds}ms");
                    }
            }
            Console.WriteLine();
            Console.WriteLine("Using StreamReader/FileStream");
            for (int i = 0; i < REPEAT; i++)
            {
                using (var reader = new StreamReader(path, enc))
                {
                    var watch = Stopwatch.StartNew();
                    var s     = await TestReaderTests.MeasureAndTime(reader);

                    watch.Stop();
                    Console.WriteLine($"{s}; time taken: {watch.ElapsedMilliseconds}ms");
                }
            }
        }
Ejemplo n.º 2
0
        public async ValueTask <int> TestMemoryMappedPipe()
        {
            int x = 0;

            for (int i = 0; i < LoopCount; i++)
            {
                var mmap = MemoryMappedPipeReader.Create(path);
                using (mmap as IDisposable)
                    using (var reader = PipeTextReader.Create(mmap, encoding))
                    {
                        x += (await TestReaderTests.MeasureAndTime(reader)).Length;
                    }
            }
            return(x);
        }
Ejemplo n.º 3
0
        public async Task IgnoreUTF8BOM(string filePath, int chunkLength)
        {
            // arrange
            filePath = Path.Combine(TestCsvFilesFolderPath, filePath);

            if (new FileInfo(filePath).Length == 0)
            {
                // Pipelines.Sockets.Unofficial seems to fail here.
                return;
            }

            // act, assert
            await RunTestAsync(CreateSut, filePath, true).ConfigureAwait(true);

            CsvAsyncInputBase CreateSut()
            {
                var pipeReader = MemoryMappedPipeReader.Create(filePath, chunkLength);

                return(CsvAsyncInput.ForPipeReader(pipeReader)
                       .WithIgnoreUTF8ByteOrderMark(true));
            }
        }