当前位置: 首页>>代码示例>>C#>>正文


C# PerfUtils.CreateString方法代码示例

本文整理汇总了C#中PerfUtils.CreateString方法的典型用法代码示例。如果您正苦于以下问题:C# PerfUtils.CreateString方法的具体用法?C# PerfUtils.CreateString怎么用?C# PerfUtils.CreateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PerfUtils的用法示例。


在下文中一共展示了PerfUtils.CreateString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ByteArraysToCompress

        // Creates byte arrays that contain random data to be compressed
        public static IEnumerable<object[]> ByteArraysToCompress()
        {
            if (_byteArraysToCompress == null)
            {
                PerfUtils utils = new PerfUtils();
                _byteArraysToCompress = new List<object[]>();

                // Regular, semi well formed data
                _byteArraysToCompress.Add(new object[] { Text.Encoding.UTF8.GetBytes(utils.CreateString(100000000)) });

                // Crypto random data
                {
                    byte[] bytes = new byte[100000000];
                    var rand = RandomNumberGenerator.Create();
                    rand.GetBytes(bytes);
                    _byteArraysToCompress.Add(new object[] { bytes });
                }

                // Highly repeated data
                {
                    byte[] bytes = new byte[101000000];
                    byte[] small = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
                    for (int i = 0; i < 1000; i++)
                        small.CopyTo(bytes, 100000 * i);
                    _byteArraysToCompress.Add(new object[] { bytes });
                }
            }
            return _byteArraysToCompress;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:30,代码来源:Perf.DeflateStream.cs

示例2: CreateHashtable

 public static Hashtable CreateHashtable(int size)
 {
     Hashtable ht = new Hashtable();
     PerfUtils utils = new PerfUtils();
     for (int i = 0; i < size; i++)
         ht.Add(utils.CreateString(50), utils.CreateString(50));
     return ht;
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:8,代码来源:Perf.HashTable.cs

示例3: Concat_str_str

 public void Concat_str_str(int size)
 {
     PerfUtils utils = new PerfUtils();
     string testString1 = utils.CreateString(size);
     string testString2 = utils.CreateString(size);
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 10000; i++)
                 string.Concat(testString1, testString2);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:Perf.String.cs

示例4: CreateDictionary

 /// <summary>
 /// Creates a Dictionary of string-string with the specified number of pairs
 /// </summary>
 public static Dictionary<string, string> CreateDictionary(PerfUtils utils, int size)
 {
     Dictionary<string, string> dict = new Dictionary<string, string>();
     while (dict.Count < size)
     {
         string key = utils.CreateString(50);
         while (dict.ContainsKey(key))
             key = utils.CreateString(50);
         dict.Add(key, utils.CreateString(50));
     }
     return dict;
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:15,代码来源:Perf.Dictionary.cs

示例5: CreateList

 /// <summary>
 /// Creates a list containing a number of elements equal to the specified size
 /// </summary>
 public static List<object> CreateList(PerfUtils utils, int size)
 {
     List<object> list = new List<object>();
     for (int i = 0; i < size; i++)
         list.Add(utils.CreateString(100));
     return list;
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:10,代码来源:Perf.List.cs

示例6: ExpandEnvironmentVariables

        public void ExpandEnvironmentVariables()
        {
            PerfUtils utils = new PerfUtils();
            string env = utils.CreateString(15);
            string inputEnv = "%" + env + "%";
            try
            {
                // setup the environment variable so we can read it
                Environment.SetEnvironmentVariable(env, "value");

                // read the valid environment variable
                foreach (var iteration in Benchmark.Iterations)
                    using (iteration.StartMeasurement())
                        for (int i = 0; i < 40000; i++)
                        {
                            Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
                            Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
                            Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
                            Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
                            Environment.ExpandEnvironmentVariables(inputEnv); Environment.ExpandEnvironmentVariables(inputEnv);
                        }
            }
            finally
            {
                // clear the variable that we set
                Environment.SetEnvironmentVariable(env, null);
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:28,代码来源:Perf.Environment.cs

示例7: CompressedFiles

        /// <summary>
        /// Yields an Enumerable list of paths to GZTestData files
        /// </summary>
        public static IEnumerable<object[]> CompressedFiles()
        {
            if (_compressedFiles == null)
            {
                PerfUtils utils = new PerfUtils();
                _compressedFiles = new List<object[]>();
                // Crypto random data
                byte[] bytes = new byte[100000000];
                var rand = RandomNumberGenerator.Create();
                rand.GetBytes(bytes);
                string filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });

                // Create a compressed file with repeated segments
                bytes = Text.Encoding.UTF8.GetBytes(utils.CreateString(100000));
                filePath = utils.GetTestFilePath() + ".gz";
                using (FileStream output = File.Create(filePath))
                using (GZipStream zip = new GZipStream(output, CompressionMode.Compress))
                    for (int i = 0; i < 1000; i++)
                        zip.Write(bytes, 0, bytes.Length);
                _compressedFiles.Add(new object[] { filePath });
            }
            return _compressedFiles;
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:30,代码来源:Perf.DeflateStream.cs

示例8: GetChars

 public void GetChars(int size)
 {
     PerfUtils utils = new PerfUtils();
     string testString = utils.CreateString(size);
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 10000; i++)
                 testString.ToCharArray();
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:9,代码来源:Perf.String.cs

示例9: Contains

 public void Contains(int size)
 {
     PerfUtils utils = new PerfUtils();
     string testString = utils.CreateString(size);
     string subString = testString.Substring(testString.Length / 2, testString.Length / 4);
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 10000; i++)
                 testString.Contains(subString);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:Perf.String.cs

示例10: ctor_string

 public void ctor_string(int length)
 {
     PerfUtils utils = new PerfUtils();
     string input = utils.CreateString(length);
     StringBuilder builder;
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 10000; i++)
             {
                 builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
                 builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
                 builder = new StringBuilder(input); builder = new StringBuilder(input); builder = new StringBuilder(input);
             }
 }
开发者ID:eerhardt,项目名称:corefx,代码行数:14,代码来源:Perf.StringBuilder.cs

示例11: GetBytes_str

 public void GetBytes_str(int size)
 {
     Encoding enc = Encoding.UTF8;
     PerfUtils utils = new PerfUtils();
     string toEncode = utils.CreateString(size);
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < 100; i++)
             {
                 enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
                 enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
                 enc.GetBytes(toEncode); enc.GetBytes(toEncode); enc.GetBytes(toEncode);
             }
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:14,代码来源:Perf.Encoding.cs

示例12: GetChars

 public void GetChars(int size, string encName)
 {
     const int innerIterations = 100;
     Encoding enc = Encoding.GetEncoding(encName);
     PerfUtils utils = new PerfUtils();
     byte[] bytes = enc.GetBytes(utils.CreateString(size));
     foreach (var iteration in Benchmark.Iterations)
         using (iteration.StartMeasurement())
             for (int i = 0; i < innerIterations; i++)
             {
                 enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
                 enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
                 enc.GetChars(bytes); enc.GetChars(bytes); enc.GetChars(bytes);
             }
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:Perf.Encoding.cs

示例13: Append

        public void Append(int length)
        {
            PerfUtils utils = new PerfUtils();
            foreach (var iteration in Benchmark.Iterations)
            {
                // Setup - Create a string of the specified length
                string builtString = utils.CreateString(length);
                StringBuilder empty = new StringBuilder();

                // Actual perf testing
                using (iteration.StartMeasurement())
                    for (int i = 0; i < 10000; i++)
                        empty.Append(builtString); // Appends a string of length "length" to an increasingly large StringBuilder
            }
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:15,代码来源:Perf.StringBuilder.cs

示例14: Combine

        public void Combine(int innerIterations)
        {
            PerfUtils utils = new PerfUtils();
            string testPath1 = utils.GetTestFilePath();
            string testPath2 = utils.CreateString(10);

            foreach (var iteration in Benchmark.Iterations)
                using (iteration.StartMeasurement())
                    for (int i = 0; i < innerIterations; i++)
                    {
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                        Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2); Path.Combine(testPath1, testPath2);
                    }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:15,代码来源:Perf.Path.cs

示例15: GetItem

 public void GetItem(Hashtable table)
 {
     // Setup - utils needs a specific seed to prevent key collision with TestData
     object result;
     PerfUtils utils = new PerfUtils(983452);
     string key = utils.CreateString(50);
     table.Add(key, "value");
     foreach (var iteration in Benchmark.Iterations)
     {
         using (iteration.StartMeasurement())
         {
             for (int i = 0; i < 40000; i++)
             {
                 result = table[key]; result = table[key]; result = table[key]; result = table[key];
                 result = table[key]; result = table[key]; result = table[key]; result = table[key];
                 result = table[key]; result = table[key]; result = table[key]; result = table[key];
                 result = table[key]; result = table[key]; result = table[key]; result = table[key];
             }
         }
     }
     table.Remove(key);
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:22,代码来源:Perf.HashTable.cs


注:本文中的PerfUtils.CreateString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。