// 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; }
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; }
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); }
/// <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; }
/// <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; }
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); } }
/// <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; }
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(); }
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); }
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); } }
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(); } } }
public void Trim_WithWhitespace(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.Trim(); } } }
public void Trim_NothingToDo(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.Trim(); } } }
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); } }
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); } }
public void Contains(StringComparison comparisonType, 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, comparisonType); } } }
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 } }
public void Split(int size) { PerfUtils utils = new PerfUtils(); string testString = utils.CreateString(size); string existingValue = testString.Substring(testString.Length / 2, 1); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) { testString.Split(existingValue); } } }
public void StartsWith(int size) { PerfUtils utils = new PerfUtils(); string testString = utils.CreateString(size); string subString = testString.Substring(0, testString.Length / 4); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) { testString.StartsWith(subString); } } }
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); } }
public void Substring_int(int size) { PerfUtils utils = new PerfUtils(); int startIndex = size / 2; string testString = utils.CreateString(size); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) { testString.Substring(startIndex); } } }
public void GetFullPathForReallyLongPath(int innerIterations) { PerfUtils utils = new PerfUtils(); string testPath = utils.CreateString(length: 1000); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < innerIterations; i++) { Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); Path.GetFullPath(testPath); } } }
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); } } }
public void ChangeExtension(int innerIterations) { PerfUtils utils = new PerfUtils(); string testPath = utils.GetTestFilePath(); string extension = utils.CreateString(4); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < innerIterations; i++) { Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); Path.ChangeExtension(testPath, extension); } } }
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); } } }
public void GetLength(int size) { PerfUtils utils = new PerfUtils(); int result; string testString = utils.CreateString(size); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) { result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; } } }
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); } } }
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 } }
public void GetByteCount(int size, string encName) { const int innerIterations = 100; Encoding enc = Encoding.GetEncoding(encName); PerfUtils utils = new PerfUtils(); char[] chars = utils.CreateString(size).ToCharArray(); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < innerIterations; i++) { enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); } } }
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); } } }
public void AppendMemoryAsObject(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); object memoryObject = builtString.AsMemory(); // deliberately uses object to force use of memory.ToString() for comparison to AppendAsReadOnlyMemory StringBuilder empty = new StringBuilder(); // Actual perf testing using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { empty.Append(memoryObject); } } }
public void AppendMemoryAsMemory(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); ReadOnlyMemory <char> memory = builtString.AsMemory(); StringBuilder empty = new StringBuilder(); // Actual perf testing using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { empty.Append(memory); } // Appends a string of length "length" to an increasingly large StringBuilder } }
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); }
public void GetFullPathForTypicalLongPath() { PerfUtils utils = new PerfUtils(); string testPath = utils.CreateString(length: 500); // warmup for (int i = 0; i < 100; i++) { str = Path.GetFullPath(testPath); } foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); str = Path.GetFullPath(testPath); } } }
public void TryGetValue(int size) { Dictionary <string, string> dict = CreateDictionary(size); // Setup - utils needs a specific seed to prevent key collision with TestData string retrieved; PerfUtils utils = new PerfUtils(56334); string key = utils.CreateString(50); dict.Add(key, "value"); // Actual perf testing foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i <= 1000; i++) { dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); } } }
public void Combine() { PerfUtils utils = new PerfUtils(); string testPath1 = utils.GetTestFilePath(); string testPath2 = utils.CreateString(10); // warmup for (int i = 0; i < 100; i++) { str = Path.Combine(testPath1, testPath2); } foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); str = Path.Combine(testPath1, testPath2); } } }
public void ContainsKey(int size) { Dictionary <string, string> dict = CreateDictionary(size); // Setup - utils needs a specific seed to prevent key collision with TestData PerfUtils utils = new PerfUtils(152891); string key = utils.CreateString(50); dict.Add(key, "value"); // Actual perf testing foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i <= 10000; i++) { dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); } } }
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"); // warmup for (int i = 0; i < 100; i++) { str = Environment.ExpandEnvironmentVariables(inputEnv); } // read the valid environment variable foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) for (int i = 0; i < Benchmark.InnerIterationCount; i++) { str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); str = Environment.ExpandEnvironmentVariables(inputEnv); } } } finally { // clear the variable that we set Environment.SetEnvironmentVariable(env, null); } }
public void GetItem(int size) { Hashtable table = CreateHashtable(size); // 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]; } } } }
public void Substring_int_int(int size) { PerfUtils utils = new PerfUtils(); int startIndex = size / 2; int length = size / 4; string testString = utils.CreateString(size); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) testString.Substring(startIndex, length); }
public void Format(int numberOfObjects) { PerfUtils utils = new PerfUtils(); // Setup the format string and the list of objects to format StringBuilder formatter = new StringBuilder(); List<string> objects = new List<string>(); for (int i = 0; i < numberOfObjects; i++) { formatter.Append("%s, "); objects.Add(utils.CreateString(10)); } string format = formatter.ToString(); string[] objectArr = objects.ToArray(); // Perform the actual formatting foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i < 5000; i++) string.Format(format, objectArr); }
public void GetLength(int size) { PerfUtils utils = new PerfUtils(); int result; string testString = utils.CreateString(size); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) { result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; result = testString.Length; } }
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; } }
public void Split(int size) { PerfUtils utils = new PerfUtils(); string testString = utils.CreateString(size); string existingValue = testString.Substring(testString.Length / 2, 1); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i < 10000; i++) testString.Split(existingValue); }
public void ContainsKey(Dictionary<string, string> dict) { // Setup - utils needs a specific seed to prevent key collision with TestData PerfUtils utils = new PerfUtils(152891); string key = utils.CreateString(50); dict.Add(key, "value"); // Actual perf testing foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i <= 10000; i++) { dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); dict.ContainsKey(key); } dict.Remove(key); }
public void Trim_WithWhitespace(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.Trim(); }
public void Trim_NothingToDo(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.Trim(); }
public void TryGetValue(Dictionary<string, string> dict) { // Setup - utils needs a specific seed to prevent key collision with TestData string retrieved; PerfUtils utils = new PerfUtils(56334); string key = utils.CreateString(50); dict.Add(key, "value"); // Actual perf testing foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i <= 1000; i++) { dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); dict.TryGetValue(key, out retrieved); } // Teardown dict.Remove(key); }
public void GetByteCount(int size, string encName) { const int innerIterations = 100; Encoding enc = Encoding.GetEncoding(encName); PerfUtils utils = new PerfUtils(); char[] chars = utils.CreateString(size).ToCharArray(); foreach (var iteration in Benchmark.Iterations) using (iteration.StartMeasurement()) for (int i = 0; i < innerIterations; i++) { enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); enc.GetByteCount(chars); } }