Note that there are some explanatory texts on larger screens.

plurals
  1. POFastest way to replace multiple strings in a huge string
    primarykey
    data
    text
    <p>I m looking for the fastest way to replace multiple (~500) substrings of a big (~1mb) string. Whatever I have tried it seems that String.Replace is the fastest way of doing it.</p> <p>I just care about the fastest possible way. Not code readability, maintainability etc. I dont care if I need to use unsafe code or pre-process the original string either.</p> <p><strong>EDIT:</strong> After the comments I have added some more details:</p> <p>Each replace iteration will replace ABC on the string with some other string (different per replace iteration). The string to replace will ALWAYS be the same - ABC will always be ABC. Never ABD. So if there are <code>400.000</code> thousands replace iterations. The same string - ABC - will be replaced with some other (different) string each time. </p> <p>I can be in control on what ABC is. I can make it super-short or super-long as long as it doesn't affect the results. Clearly ABC can't be <em>hello</em> cause hello will exist as a word in most of the input strings.</p> <p>Example input: <code>ABCDABCABCDABCABCDABCABCDABCD</code></p> <p>Example replace from string: <code>BC</code></p> <p>Example replace with strings: <code>AA, BB, CC, DD, EE (5 iterations)</code></p> <p>Example outputs:</p> <pre><code>AAADAAAAAADAAAAAADAAAAAADAAAD ABBDABBABBDABBABBDABBABBDABBD ACCDACCACCDACCACCDACCACCDACCD ADDDADDADDDADDADDDADDADDDADDD AEEDAEEAEEDAEEAEEDAEEAEEDAEED </code></pre> <p><strong>Average case:</strong> Input string is 100-200kb with 40.000 replace iterations. Worst case: Input string is 1-2mb with 400.000 replace iterations.</p> <p>I can do ANYTHING. Do it in parallel, do it unsafe, etc. It doesnt matter how I do it. What matters is that it needs to be as fast as it gets.</p> <p>Thanks</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.
 

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