本文整理汇总了C#中PerfUtils.CreateString方法的典型用法代码示例。如果您正苦于以下问题:C# PerfUtils.CreateString方法的具体用法?C# PerfUtils.CreateString怎么用?C# PerfUtils.CreateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerfUtils
的用法示例。
在下文中一共展示了PerfUtils.CreateString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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;
}
示例8: 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();
}
示例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: 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);
}
}
示例11: 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);
}
}
示例12: 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);
}
}
示例13: 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
}
}
示例14: 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);
}
}
示例15: 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);
}