Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the advices received (use StringBuilder for example) and with Parallel extensions, use how many cores you have in your machine to do the work in parallel.</p> <p>Look at this code:</p> <pre><code>class Program { static void Main(String[] args) { // Filling the data List&lt;KeyValuePair&lt;String, String&gt;&gt; map = new List&lt;KeyValuePair&lt;String, String&gt;&gt;(); List&lt;StringBuilder&gt; strings = new List&lt;StringBuilder&gt;(); List&lt;StringBuilder&gt; strings2 = new List&lt;StringBuilder&gt;(); for (Int32 i = 0; i &lt; 50; i++) { String key = String.Format("[KEY{0}]", i); String value = String.Format("Text of KEY{0}", i); KeyValuePair&lt;String, String&gt; keyValuePair = new KeyValuePair&lt;String, String&gt;(key, value); map.Add(keyValuePair); } for (Int32 i = 0; i &lt; 1024; i++) { StringBuilder text = new StringBuilder(); foreach (KeyValuePair&lt;String, String&gt; keyValuePair in map) { text.AppendFormat("Some text before - {0} - Some text after.", keyValuePair.Key); text.AppendLine(); } strings.Add(text); strings2.Add(text); } // Measuring the normal loop Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (StringBuilder text in strings) { foreach (KeyValuePair&lt;String, String&gt; eachMap in map) { text.Replace(eachMap.Key, eachMap.Value); } } stopwatch.Stop(); Console.WriteLine("Time with normal loop: {0}", stopwatch.Elapsed); // Measuring the parallel loop stopwatch.Reset(); stopwatch.Start(); Parallel.ForEach(strings2, text =&gt; { foreach (KeyValuePair&lt;String, String&gt; eachMap in map) { text.Replace(eachMap.Key, eachMap.Value); } }); stopwatch.Stop(); Console.WriteLine("Time with parallel: {0}", stopwatch.Elapsed); Console.ReadLine(); } } </code></pre> <p>And look at some measures running on my nootebook (AMD Turion64 X2 - 2 cores):</p> <p><br /> <br /> Time with normal loop: 00:00:03.5956428 <br /> Time with parallel: 00:00:01.8707367 <br /> <br /> Time with normal loop: 00:00:02.1467821 <br /> Time with parallel: 00:00:01.4627365 <br /> <br /> Time with normal loop: 00:00:03.4123084 <br /> Time with parallel: 00:00:01.6704408 <br /> <br /> <br /> <br /></p> <p>Hope this helps.</p> <p>Ricardo Lacerda Castelo Branco</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload