Пример #1
0
        // Writes batches of Empty records to the file. Records have timestamps with consecutive ticks starting from 1.
        static async Task WriteBatch(string fname, long batches, long recsPerBatch)
        {
            Debug.Assert(batches >= 0);
            Debug.Assert(recsPerBatch > 0);
            using (var writer = new EmptyWriter(fname)) {
                Stopwatch stopwatch = Stopwatch.StartNew();
                for (long i = 0; i != batches; ++i)
                {
                    await writer.WriteBatchAsync(Batch());

                    IEnumerable <Event <Empty> > Batch()
                    {
                        for (long j = 0; j != recsPerBatch; ++j)
                        {
                            yield return(new Event <Empty>(new DateTime(i * recsPerBatch + j + 1, DateTimeKind.Utc), new Empty()));
                        }
                    }
                }
                await writer.FlushAsync(flushToDisk : false);

                double seconds = stopwatch.Elapsed.TotalSeconds;
                long   bytes   = new FileInfo(fname).Length;
                long   records = batches * recsPerBatch;
                Console.WriteLine(
                    "  WriteBatch(batches: {0:N0}, recsPerBatch: {1:N0}): " +
                    "{2:N0} records, {3:N0} bytes, {4:N0} records/sec, {5:N0} bytes/sec.",
                    batches, recsPerBatch, records, bytes, records / seconds, bytes / seconds);
            }
        }
Пример #2
0
        // Writes individual Empty records to the file. Records have timestamps with consecutive ticks starting from 1.
        static async Task Write(string fname, long records)
        {
            Debug.Assert(records >= 0);
            using (var writer = new EmptyWriter(fname)) {
                Stopwatch stopwatch = Stopwatch.StartNew();
                for (long i = 0; i != records; ++i)
                {
                    await writer.WriteAsync(new Event <Empty>(new DateTime(i + 1, DateTimeKind.Utc), new Empty()));
                }
                await writer.FlushAsync(flushToDisk : false);

                double seconds = stopwatch.Elapsed.TotalSeconds;
                long   bytes   = new FileInfo(fname).Length;
                Console.WriteLine("  Write(records: {0:N0}): {1:N0} bytes, {2:N0} records/sec, {3:N0} bytes/sec.",
                                  records, bytes, records / seconds, bytes / seconds);
            }
        }