本文整理汇总了C#中PerfUtils.GetTestFilePath方法的典型用法代码示例。如果您正苦于以下问题:C# PerfUtils.GetTestFilePath方法的具体用法?C# PerfUtils.GetTestFilePath怎么用?C# PerfUtils.GetTestFilePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerfUtils
的用法示例。
在下文中一共展示了PerfUtils.GetTestFilePath方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompressedFiles
/// <summary>
/// Yields an Enumerable list of paths to GZTestData files
/// </summary>
public static IEnumerable<object[]> CompressedFiles()
{
if (_compressedFiles == null)
{
PerfUtils utils = new PerfUtils();
_compressedFiles = new List<object[]>();
// Crypto random data
byte[] bytes = new byte[100000000];
var rand = RandomNumberGenerator.Create();
rand.GetBytes(bytes);
string filePath = utils.GetTestFilePath() + ".gz";
using (FileStream output = File.Create(filePath))
using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
zip.Write(bytes, 0, bytes.Length);
_compressedFiles.Add(new object[] { filePath });
// Create a compressed file with repeated segments
bytes = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
filePath = utils.GetTestFilePath() + ".gz";
using (FileStream output = File.Create(filePath))
using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
for (int i = 0; i < 1000; i++)
zip.Write(bytes, 0, bytes.Length);
_compressedFiles.Add(new object[] { filePath });
}
return _compressedFiles;
}
示例2: Compress_Canterbury
public void Compress_Canterbury(int innerIterations, string fileName, CompressionLevel compressLevel)
{
byte[] bytes = File.ReadAllBytes(Path.Combine("GZTestData", "Canterbury", fileName));
PerfUtils utils = new PerfUtils();
FileStream[] filestreams = new FileStream[innerIterations];
GZipStream[] gzips = new GZipStream[innerIterations];
string[] paths = new string[innerIterations];
foreach (var iteration in Benchmark.Iterations)
{
for (int i = 0; i < innerIterations; i++)
{
paths[i] = utils.GetTestFilePath();
filestreams[i] = File.Create(paths[i]);
}
using (iteration.StartMeasurement())
for (int i = 0; i < innerIterations; i++)
{
gzips[i] = new GZipStream(filestreams[i], compressLevel);
gzips[i].Write(bytes, 0, bytes.Length);
gzips[i].Flush();
gzips[i].Dispose();
filestreams[i].Dispose();
}
for (int i = 0; i < innerIterations; i++)
File.Delete(paths[i]);
}
}
示例3: GetDirectoryName
public void GetDirectoryName()
{
PerfUtils utils = new PerfUtils();
string testPath = utils.GetTestFilePath();
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 20000; i++)
{
Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath); Path.GetDirectoryName(testPath);
}
}
示例4: Combine
public void Combine(int innerIterations)
{
PerfUtils utils = new PerfUtils();
string testPath1 = utils.GetTestFilePath();
string testPath2 = utils.CreateString(10);
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < innerIterations; i++)
{
Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
}
}
示例5: CreateCompressedFile
/// <returns></returns>
private static string CreateCompressedFile(CompressionType type)
{
const int fileSize = 100000000;
PerfUtils utils = new PerfUtils();
string filePath = utils.GetTestFilePath() + ".gz";
switch (type)
{
case CompressionType.CryptoRandom:
using (RandomNumberGenerator rand = RandomNumberGenerator.Create())
{
byte[] bytes = new byte[fileSize];
rand.GetBytes(bytes);
using (FileStream output = File.Create(filePath))
using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
zip.Write(bytes, 0, bytes.Length);
}
break;
case CompressionType.RepeatedSegments:
{
byte[] bytes = new byte[fileSize / 1000];
new Random(128453).NextBytes(bytes);
using (FileStream output = File.Create(filePath))
using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
for (int i = 0; i < 1000; i++)
zip.Write(bytes, 0, bytes.Length);
}
break;
case CompressionType.NormalData:
{
byte[] bytes = new byte[fileSize];
new Random(128453).NextBytes(bytes);
using (FileStream output = File.Create(filePath))
using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
zip.Write(bytes, 0, bytes.Length);
}
break;
}
return filePath;
}
示例6: Compress
public void Compress(CompressionType type)
{
byte[] bytes = CreateBytesToCompress(type);
PerfUtils utils = new PerfUtils();
foreach (var iteration in Benchmark.Iterations)
{
string filePath = utils.GetTestFilePath();
using (FileStream output = File.Create(filePath))
using (DeflateStream zip = new DeflateStream(output, CompressionMode.Compress))
using (iteration.StartMeasurement())
{
zip.Write(bytes, 0, bytes.Length);
}
File.Delete(filePath);
}
}