예제 #1
0
        public static async Task PerfCompareNonStreamingWithStreamingAsync()
        {
            Console.Clear();
            await Console.Out.WriteLineAsync("========================================").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("Running Perf Comparison of Streaming API").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("========================================").ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            const int totalObjects = 10000;
            var       file         = await SampleGeneratingHelpers.GenerateRandomDataAsync(totalObjects).ConfigureAwait(false);

            await RunWithoutStreamingApiAsync(file, totalObjects).ConfigureAwait(false);
            await RunWithStreamingApiAsync(file, totalObjects).ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            await Console.Out.WriteLineAsync("============================================").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("Done... please enter to run next simulation.").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("============================================").ConfigureAwait(false);

            Console.ReadLine();
        }
예제 #2
0
        public static async Task RunHoistedNUnHoistedStreams()
        {
            Console.Clear();
            await Console.Out.WriteLineAsync("==========================================").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("Running Nested Streams & Hoisted Generator").ConfigureAwait(false);

            await Console.Out.WriteLineAsync("==========================================").ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            //Creating sample file
            const int totalObjects = 100;
            var       file         = await SampleGeneratingHelpers.GenerateRandomDataAsync(totalObjects).ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            //Deserializing with nested using block
            await Console.Out.WriteLineAsync("===> Deserializing object array with Nested using blocks <===").ConfigureAwait(false);

            var objs = GetDataFromCompressedJson <List <MyTestData> >(file);
            await Console.Out.WriteLineAsync($"Total of {objs.Count} objects deserialized from file.").ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            await Console.Out.WriteLineAsync().ConfigureAwait(false);

            await Console.Out.WriteLineAsync("===> Deserializing object array with Hoisted Stream Generators <===").ConfigureAwait(false);

            //NOTE: For DEMO purpose we are not taking care of stream dispose and other optimizations we can add.
            //do NOT use this code in production instead check the https://github.com/samaysar/dotdotnet for actual implementation.
            objs = file.PullData()
                   .ThenDecompress()
                   .ThenDecode()
                   .ThenDeserializeJson <List <MyTestData> >();
            await Console.Out.WriteLineAsync($"Total of {objs.Count} objects deserialized from file.").ConfigureAwait(false);

            Console.ReadLine();
        }