本文整理汇总了C#中PerfUtils类的典型用法代码示例。如果您正苦于以下问题:C# PerfUtils类的具体用法?C# PerfUtils怎么用?C# PerfUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PerfUtils类属于命名空间,在下文中一共展示了PerfUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]);
}
}
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:27,代码来源:Perf.GZipStream.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:10,代码来源:Perf.List.cs
示例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);
}
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:28,代码来源:Perf.Environment.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:30,代码来源:Perf.DeflateStream.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:30,代码来源:Perf.DeflateStream.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:Perf.HashTable.cs
示例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();
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:9,代码来源:Perf.String.cs
示例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);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:Perf.String.cs
示例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);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:Perf.String.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:19,代码来源:Perf.List.cs
示例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;
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:15,代码来源:Perf.Dictionary.cs
示例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);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:Perf.Path.cs
示例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);
}
}
开发者ID:eerhardt,项目名称:corefx,代码行数:14,代码来源:Perf.StringBuilder.cs
示例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);
}
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:14,代码来源:Perf.Encoding.cs
示例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);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:Perf.Encoding.cs
示例16: Append
public void Append(int length)
{
PerfUtils utils = new PerfUtils();
foreach (var iteration in Benchmark.Iterations)
{
// Setup - Create a string of the specified length
string builtString = utils.CreateString(length);
StringBuilder empty = new StringBuilder();
// Actual perf testing
using (iteration.StartMeasurement())
for (int i = 0; i < 10000; i++)
empty.Append(builtString); // Appends a string of length "length" to an increasingly large StringBuilder
}
}
开发者ID:eerhardt,项目名称:corefx,代码行数:15,代码来源:Perf.StringBuilder.cs
示例17: 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);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:Perf.Path.cs
示例18: 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;
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:40,代码来源:Perf.DeflateStream.cs
示例19: GetItem
public void GetItem(Hashtable table)
{
// Setup - utils needs a specific seed to prevent key collision with TestData
object result;
PerfUtils utils = new PerfUtils(983452);
string key = utils.CreateString(50);
table.Add(key, "value");
foreach (var iteration in Benchmark.Iterations)
{
using (iteration.StartMeasurement())
{
for (int i = 0; i < 40000; i++)
{
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
result = table[key]; result = table[key]; result = table[key]; result = table[key];
}
}
}
table.Remove(key);
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:22,代码来源:Perf.HashTable.cs
示例20: op_Equality
public void op_Equality(int size)
{
PerfUtils utils = new PerfUtils();
bool result;
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++)
{
result = testString1 == testString2; result = testString1 == testString2;
result = testString1 == testString2; result = testString1 == testString2;
result = testString1 == testString2; result = testString1 == testString2;
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:Perf.String.cs
注:本文中的PerfUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论