本文整理汇总了C#中PerfUtils类的典型用法代码示例。如果您正苦于以下问题:C# PerfUtils类的具体用法?C# PerfUtils怎么用?C# PerfUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PerfUtils类属于命名空间,在下文中一共展示了PerfUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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]);
}
}
示例2: CreateList
/// <summary>
/// Creates a list containing a number of elements equal to the specified size
/// </summary>
public static List<object> CreateList(PerfUtils utils, int size)
{
List<object> list = new List<object>();
for (int i = 0; i < size; i++)
list.Add(utils.CreateString(100));
return list;
}
示例3: ExpandEnvironmentVariables
public void ExpandEnvironmentVariables()
{
PerfUtils utils = new PerfUtils();
string env = utils.CreateString(15);
string inputEnv = "%" + env + "%";
try
{
// setup the environment variable so we can read it
Environment.SetEnvironmentVariable(env, "value");
// read the valid environment variable
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 40000; i++)
{
Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
}
}
finally
{
// clear the variable that we set
Environment.SetEnvironmentVariable(env, null);
}
}
示例4: ByteArraysToCompress
// Creates byte arrays that contain random data to be compressed
public static IEnumerable<object[]> ByteArraysToCompress()
{
if (_byteArraysToCompress == null)
{
PerfUtils utils = new PerfUtils();
_byteArraysToCompress = new List<object[]>();
// Regular, semi well formed data
_byteArraysToCompress.Add(new object[] { Text.Encoding.UTF8.GetBytes(utils.CreateString(100000000)) });
// Crypto random data
{
byte[] bytes = new byte[100000000];
var rand = RandomNumberGenerator.Create();
rand.GetBytes(bytes);
_byteArraysToCompress.Add(new object[] { bytes });
}
// Highly repeated data
{
byte[] bytes = new byte[101000000];
byte[] small = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
for (int i = 0; i < 1000; i++)
small.CopyTo(bytes, 100000 * i);
_byteArraysToCompress.Add(new object[] { bytes });
}
}
return _byteArraysToCompress;
}
示例5: 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;
}
示例6: CreateHashtable
public static Hashtable CreateHashtable(int size)
{
Hashtable ht = new Hashtable();
PerfUtils utils = new PerfUtils();
for (int i = 0; i < size; i++)
ht.Add(utils.CreateString(50), utils.CreateString(50));
return ht;
}
示例7: GetChars
public void GetChars(int size)
{
PerfUtils utils = new PerfUtils();
string testString = utils.CreateString(size);
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
testString.ToCharArray();
}
示例8: Concat_str_str
public void Concat_str_str(int size)
{
PerfUtils utils = new PerfUtils();
string testString1 = utils.CreateString(size);
string testString2 = utils.CreateString(size);
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
string.Concat(testString1, testString2);
}
示例9: Contains
public void Contains(int size)
{
PerfUtils utils = new PerfUtils();
string testString = utils.CreateString(size);
string subString = testString.Substring(testString.Length / 2, testString.Length / 4);
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
testString.Contains(subString);
}
示例10: TestData
/// <summary>
/// Yields several Lists containing increasing amounts of strings
/// can be used as MemberData input to performance tests for Dictionary
/// </summary>
/// <remarks>Any changes made to the returned collections MUST be undone. Collections
/// used as MemberData are cached and reused in other perf tests.
/// </remarks>
public static List<object[]> TestData()
{
if (_testData == null)
{
PerfUtils utils = new PerfUtils();
_testData = new List<object[]>();
_testData.Add(new object[] { CreateList(utils, 1000) });
_testData.Add(new object[] { CreateList(utils, 10000) });
_testData.Add(new object[] { CreateList(utils, 100000) });
}
return _testData;
}
示例11: CreateDictionary
/// <summary>
/// Creates a Dictionary of string-string with the specified number of pairs
/// </summary>
public static Dictionary<string, string> CreateDictionary(PerfUtils utils, int size)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
while (dict.Count < size)
{
string key = utils.CreateString(50);
while (dict.ContainsKey(key))
key = utils.CreateString(50);
dict.Add(key, utils.CreateString(50));
}
return dict;
}
示例12: 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);
}
}
示例13: ctor_string
public void ctor_string(int length)
{
PerfUtils utils = new PerfUtils();
string input = utils.CreateString(length);
StringBuilder builder;
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
{
builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
}
}
示例14: GetBytes_str
public void GetBytes_str(int size)
{
Encoding enc = Encoding.UTF8;
PerfUtils utils = new PerfUtils();
string toEncode = utils.CreateString(size);
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < 100; i++)
{
enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
}
}
示例15: GetChars
public void GetChars(int size, string encName)
{
const int innerIterations = 100;
Encoding enc = Encoding.GetEncoding(encName);
PerfUtils utils = new PerfUtils();
byte[] bytes = enc.GetBytes(utils.CreateString(size));
foreach (var iteration in Benchmark.Iterations)
using (iteration.StartMeasurement())
for (int i = 0; i < innerIterations; i++)
{
enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
}
}