Beispiel #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;
        }
Beispiel #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;
 }
Beispiel #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);
 }
Beispiel #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;
 }
Beispiel #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;
 }
        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);
            }
        }
Beispiel #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;
        }
Beispiel #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();
 }
Beispiel #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);
 }
Beispiel #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);
             }
 }
Beispiel #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();
                    }
            }
        }
Beispiel #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();
                    }
            }
        }
Beispiel #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();
                    }
            }
        }
Beispiel #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);
             }
 }
Beispiel #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);
             }
 }
        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);
                    }
            }
        }
Beispiel #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
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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;
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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
            }
        }
Beispiel #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);
 }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
                    }
            }
        }
Beispiel #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);
            }
        }
Beispiel #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];
                    }
                }
            }
        }
Beispiel #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);
 }
Beispiel #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);
        }
Beispiel #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;
             }
 }
Beispiel #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;
             }
 }
Beispiel #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);
 }
Beispiel #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);
        }
Beispiel #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();
 }
Beispiel #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();
 }
Beispiel #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);
        }
Beispiel #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);
             }
 }