Ejemplo n.º 1
0
        // 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;
        }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
 /// <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;
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
 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();
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 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);
             }
 }
Ejemplo n.º 11
0
        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();
                    }
            }
        }
Ejemplo n.º 12
0
        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();
                    }
            }
        }
Ejemplo n.º 13
0
        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();
                    }
            }
        }
Ejemplo n.º 14
0
 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);
             }
 }
Ejemplo n.º 15
0
 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);
             }
 }
Ejemplo n.º 16
0
        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);
                    }
            }
        }
Ejemplo n.º 17
0
        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
            }
        }
Ejemplo n.º 18
0
        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);
                    }
            }
        }
Ejemplo n.º 19
0
        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);
                    }
            }
        }
Ejemplo n.º 20
0
        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);
                    }
        }
Ejemplo n.º 21
0
        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);
                    }
            }
        }
Ejemplo n.º 22
0
        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);
                    }
            }
        }
Ejemplo n.º 23
0
        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);
                    }
            }
        }
Ejemplo n.º 24
0
        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);
                    }
            }
        }
Ejemplo n.º 25
0
        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);
                    }
            }
        }
Ejemplo n.º 26
0
        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;
                    }
            }
        }
Ejemplo n.º 27
0
        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);
                    }
            }
        }
Ejemplo n.º 28
0
        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
            }
        }
Ejemplo n.º 29
0
        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);
                    }
            }
        }
Ejemplo n.º 30
0
        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);
                    }
            }
        }
Ejemplo n.º 31
0
        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);
                    }
            }
        }
Ejemplo n.º 32
0
        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
            }
        }
Ejemplo n.º 33
0
 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);
 }
Ejemplo n.º 34
0
        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);
                    }
            }
        }
Ejemplo n.º 35
0
        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);
                    }
            }
        }
Ejemplo n.º 36
0
        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);
                    }
            }
        }
Ejemplo n.º 37
0
        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);
                    }
            }
        }
Ejemplo n.º 38
0
        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);
            }
        }
Ejemplo n.º 39
0
        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];
                    }
                }
            }
        }
Ejemplo n.º 40
0
 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);
 }
Ejemplo n.º 41
0
        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);
        }
Ejemplo n.º 42
0
 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;
             }
 }
Ejemplo n.º 43
0
 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;
             }
 }
Ejemplo n.º 44
0
 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);
 }
Ejemplo n.º 45
0
        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);
        }
Ejemplo n.º 46
0
 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();
 }
Ejemplo n.º 47
0
 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();
 }
Ejemplo n.º 48
0
        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);
        }
Ejemplo n.º 49
0
 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);
             }
 }