Beispiel #1
0
        private TestResult BlockTest(BenchmarkWay wayToGo)
        {
            var result = new TestResult();
            var fileSize = (int) FileSize;
            var blockSize = (int) wayToGo;

            byte[] testFile = new byte[blockSize].FillWithRandomValues();
            var iterAmount = (int) Math.Ceiling((double) fileSize / blockSize);
            string randomFileName = GetFileName(LocalDisk);
            _createdFiles.Add(LocalDisk + randomFileName);

            /* Write test */
            _watch.Reset();
            _watch.Start();
            using (var fStream = new FileStream(LocalDisk + randomFileName, FileMode.Create, FileAccess.Write, FileShare.None, blockSize, FileOptions.WriteThrough | FileFlagNoBuffering))
            {
                while (iterAmount > 0)
                {
                    fStream.Write(testFile, 0, blockSize);

                    --iterAmount;
                }
            }
            _watch.Stop();
            result.WriteSpeedMBps = (double) fileSize / _watch.ElapsedMilliseconds / 1024 / 1024 * 1000;

            /* Read test */
            iterAmount = (int) Math.Ceiling((double) fileSize / blockSize);
            _watch.Reset();
            _watch.Start();
            using (var fStream = new FileStream(LocalDisk + randomFileName, FileMode.Open, FileAccess.Read, FileShare.None, blockSize, FileOptions.WriteThrough | FileFlagNoBuffering))
            {
                while (iterAmount > 0)
                {
                    fStream.Read(testFile, 0, blockSize);

                    --iterAmount;
                }
            }
            _watch.Stop();
            result.ReadSpeedMBps = (double) fileSize / _watch.ElapsedMilliseconds / 1024 / 1024 * 1000;

            /* Delete created file*/
            Clear();

            return result;
        }
Beispiel #2
0
        private TestResult SequentialTest()
        {
            var result = new TestResult();
            var fileSize = (int) FileSize;

            byte[] testFile = new byte[fileSize].FillWithRandomValues();
            /* Create file */
            string randomFileName = GetFileName(LocalDisk);
            _createdFiles.Add(LocalDisk + randomFileName);

            /* Write test */
            _watch.Reset();
            _watch.Start();
            using (var fStream = new FileStream(LocalDisk + randomFileName, FileMode.Create, FileAccess.Write, FileShare.None, 1024 * 1024, FileOptions.WriteThrough | FileFlagNoBuffering))
            {
                fStream.Write(testFile, 0, fileSize);
            }
            _watch.Stop();
            result.WriteSpeedMBps = (double) fileSize/_watch.ElapsedMilliseconds / 1024 / 1024 * 1000;

            /* Read test */
            _watch.Reset();
            _watch.Start();
            using (var fStream = new FileStream(LocalDisk + randomFileName, FileMode.Open, FileAccess.Read, FileShare.None, 1024 * 1024, FileOptions.WriteThrough | FileFlagNoBuffering))
            {
                fStream.Read(testFile, 0, fileSize);
            }
            _watch.Stop();
            result.ReadSpeedMBps = (double) fileSize / _watch.ElapsedMilliseconds / 1024/ 1024 * 1000;

            /* Delete created file*/
            Clear();

            return result;
        }