protected override TimeSpan DoBenchmarkAlgorithm(FileStream stream, Action<byte[], int, int> work, BenchmarkFlags flags, CancellationToken cancellationToken)
 {
     var sequenceReadTimeTotal = new TimeSpan(0);
     byte[] buffer = AssemblyUtility.GetData(BlockSize, flags.HasFlag(BenchmarkFlags.Compressible));
     for (int i = 0; i < BlockCount; i++)
     {
         cancellationToken.ThrowIfCancellationRequested();   //可以取消
         sequenceReadTimeTotal += AssemblyUtility.GetTime(() => work(buffer, 0, buffer.Length));
     }
     return sequenceReadTimeTotal;
 }
        protected override TimeSpan DoBenchmarkAlgorithm(FileStream stream, Action<byte[], int, int> work, BenchmarkFlags flags, CancellationToken cancellationToken)
        {
            var random = new Random();
            TimeSpan timeTotal = default(TimeSpan);
            for (int j = 0; j < BlockCount / this.outstandingThreadsCount; j++)
            {
                cancellationToken.ThrowIfCancellationRequested();   //可以取消

                var randomArray = AssemblyUtility.GetData(BlockSize, flags.HasFlag(BenchmarkFlags.Compressible));
                long posision = BlockSize * random.Next(BlockCount);
                timeTotal += AssemblyUtility.GetTime(() =>
                {
                    stream.Seek(posision, SeekOrigin.Begin);
                    work(randomArray, 0, randomArray.Length);
                });
            }
            return timeTotal;
        }
 public override IOSpeed GetTestResult(PartitionInfo partition, BenchmarkType type, BenchmarkFlags flags, CancellationToken cancellationToken)
 {
     var randomBenchmarkTimes = new TimeSpan[this.outstandingThreadsCount];
     BenchmarkFile.OpenFileHandle(partition, type,
         handle =>
         {
             Parallel.For(0, this.outstandingThreadsCount, i =>
             {
                 using (FileStream stream = new FileStream(handle, FileAccess.Read, BlockSize))
                 {
                     Action<byte[], int, int> work = Utility.GetReadOrWriteAction(type, stream);
                     randomBenchmarkTimes[i] = DoBenchmarkAlgorithm(stream, work, flags, cancellationToken);
                 }
             });
         });
     var totalTimes = randomBenchmarkTimes.Aggregate((a, b) => a + b);
     return new IOSpeed(time: totalTimes, ioCount: BlockCount, bytes: BlockCount * BlockSize);
 }
        protected override TimeSpan DoBenchmarkAlgorithm(FileStream stream, Action<byte[], int, int> work, BenchmarkFlags flags, CancellationToken cancellationToken)
        {
            var randomBenchmarkTimeTotal = new TimeSpan(0);
            for (int i = 0; i < BlockCount; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();   //可以取消

                var randomArray = AssemblyUtility.GetData(BlockSize, flags.HasFlag(BenchmarkFlags.Compressible));
                long posision = BlockSize * this.RandomGen.Next(BlockCount);
                randomBenchmarkTimeTotal += AssemblyUtility.GetTime(() =>
                {
                    stream.Seek(posision, SeekOrigin.Begin);
                    work(randomArray, 0, randomArray.Length);
                });

                var blockCountIn60S = (double)i / randomBenchmarkTimeTotal.Ticks * 60;
                this.BlockCountValue = (int)Min(this.BlockCountValue, Max(Max(i, EvalutionCount), blockCountIn60S));
            }
            return randomBenchmarkTimeTotal;
        }
示例#5
0
 /// <summary>
 /// 根据核心测试算法返回的时间计算结果。
 /// </summary>
 /// <param name="partition">测试分区</param>
 /// <param name="arg">测试类型</param>
 /// <param name="flags">测试所需参数</param>
 /// <param name="cancellationToken">用以取消工作的取消标记</param>
 /// <returns></returns>
 public virtual IOSpeed GetTestResult(PartitionInfo partition, BenchmarkType type, BenchmarkFlags flags, CancellationToken cancellationToken)
 {
     TimeSpan result = new TimeSpan();
     BenchmarkFile.OpenFileStream(partition, type, BlockSize,
         stream =>
         {
             Action<byte[], int, int> work = GetReadOrWriteAction(type, stream);
             result = DoBenchmarkAlgorithm(stream, work, flags, cancellationToken);
         });
     return new IOSpeed(time: result, ioCount: BlockCount, bytes: BlockCount * BlockSize);
 }
示例#6
0
 /// <summary>
 /// 测试核心算法
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="work"></param>
 /// <param name="flags"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 protected abstract TimeSpan DoBenchmarkAlgorithm(FileStream stream, Action<byte[], int, int> work, BenchmarkFlags flags, CancellationToken cancellationToken);