Exemplo 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");
                }
            }
        }
Exemplo n.º 2
0
        public async ValueTask <int> TestFileStream()
        {
            int x = 0;

            for (int i = 0; i < LoopCount; i++)
            {
                using (var reader = new StreamReader(path, encoding))
                {
                    x += (await TestReaderTests.MeasureAndTime(reader)).Length;
                }
            }
            return(x);
        }
Exemplo n.º 3
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);
        }