예제 #1
0
        // Reads all Empty records from the specified file. Returns the number of records read.
        static async Task <long> ReadAll(string fname)
        {
            using (var reader = new EmptyReader(fname)) {
                long      records   = 0;
                Stopwatch stopwatch = Stopwatch.StartNew();
                await reader.ReadAfter(DateTime.MinValue).ForEachAsync((IEnumerable <Event <Empty> > buf) => {
                    records += buf.Count();
                    return(Task.CompletedTask);
                });

                double seconds = stopwatch.Elapsed.TotalSeconds;
                long   bytes   = new FileInfo(fname).Length;
                Console.WriteLine("  ReadAll: {0:N0} records, {1:N0} bytes, {2:N0} records/sec, {3:N0} bytes/sec.",
                                  records, bytes, records / seconds, bytes / seconds);
                return(records);
            }
        }
예제 #2
0
        // Seeks to random timestamps in the file for the specified amount of time. The timestamps
        // to seek are uniformly distributed in [0, maxTicks].
        static async Task SeekMany(string fname, long maxTicks, double seconds)
        {
            if (maxTicks >= int.MaxValue)
            {
                throw new Exception("Sorry, not implemented");
            }
            var       rng       = new Random();
            long      seeks     = 0;
            Stopwatch stopwatch = Stopwatch.StartNew();

            do
            {
                ++seeks;
                var t = new DateTime(rng.Next((int)maxTicks + 1), DateTimeKind.Utc);
                // Create a new reader for every seek to avoid the possibility of caching in the reader.
                using (var reader = new EmptyReader(fname)) {
                    // Note that this not only seeks but also reads and decompresses the content of the
                    // first chunk.
                    await reader.ReadAfter(t).GetAsyncEnumerator().MoveNextAsync(CancellationToken.None);
                }
            } while (stopwatch.Elapsed < TimeSpan.FromSeconds(seconds));
            seconds = stopwatch.Elapsed.TotalSeconds;
            Console.WriteLine("  SeekMany: {0:N0} seeks, {1:N1} seeks/sec.", seeks, seeks / seconds);
        }