Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:09:42+00:00 2026-05-31T09:09:42+00:00

Possible Duplicate: String comparison in dotnet framework 4 I noticed a performance problem on

  • 0

Possible Duplicate:
String comparison in dotnet framework 4

I noticed a performance problem on my machine in a UI app that is doing lots of string comparisons to do filtering of large lists. I tracked the issue down to using OrdinalIgnoreCase in a call to string.IndexOf. The following benchmarks were run in Release without the debugger attached, it’s a 4.0 project built in VS 2010, windows 7, I do have the 4.5 beta installed on this machine, I’m not sure if that would affect this.

1.190 seconds for OrdinalIgnoreCase
0.178 seconds for CurrentCultureIgnoreCase
0.175 seconds for InvariantCultureIgnoreCase

0.101 seconds for Ordinal
0.132 seconds for CurrentCulture
0.126 seconds for InvariantCulture

1.176 seconds for OrdinalIgnoreCase
0.189 seconds for CurrentCultureIgnoreCase
0.183 seconds for InvariantCultureIgnoreCase

0.104 seconds for Ordinal
0.138 seconds for CurrentCulture
0.127 seconds for InvariantCulture

As you can see OrdinalIgnoreCase is over 6.5x slower! But without IgnoreCase Ordinal is the fastest. In multiple places microsoft recommends OrdinalIgnoreCase for the best performance. Can anyone replicate these results or explain why OrdinalIgnoreCase is going so much slower in this test?

private static void Test(string search, string key, StringComparison comparison, int trials)
{
    var sw = Stopwatch.StartNew();

    for (int i = 0; i < trials; i++)
    {
        search.IndexOf(key, comparison);
    }

    Console.WriteLine("{0:0.000} seconds for {1}", sw.ElapsedMilliseconds / 1000.0, comparison);
}


static void Main(string[] args)
{
    int trials = 1000000;
    var search = Guid.NewGuid().ToString("N");
    var key = "34";

    Test(search, key, StringComparison.OrdinalIgnoreCase, trials);
    Test(search, key, StringComparison.CurrentCultureIgnoreCase, trials);
    Test(search, key, StringComparison.InvariantCultureIgnoreCase, trials);
    Test(search, key, StringComparison.Ordinal, trials);
    Test(search, key, StringComparison.CurrentCulture, trials);
    Test(search, key, StringComparison.InvariantCulture, trials);

    Test(search, key, StringComparison.OrdinalIgnoreCase, trials);
    Test(search, key, StringComparison.CurrentCultureIgnoreCase, trials);
    Test(search, key, StringComparison.InvariantCultureIgnoreCase, trials);
    Test(search, key, StringComparison.Ordinal, trials);
    Test(search, key, StringComparison.CurrentCulture, trials);
    Test(search, key, StringComparison.InvariantCulture, trials);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:09:45+00:00Added an answer on May 31, 2026 at 9:09 am

    This is apparently a known performance problem in .net 4, I found this bug entry on connect.microsoft.com

    And there is a response

    Posted by Microsoft on 2/10/2012 at 11:43 AM We were able to repro
    this issue. The issue has been resolved and the fix will be in the
    next release. Thank you for you feedback.

    I’m not sure what the next release will be, I will just prefer using InvariantCultureIgnoreCase instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: String comparison in Objective-C I realize that the question is not very
Possible Duplicate: Java string comparison? I have encounter the following problem, I have an
Possible Duplicate: C++ std::string conversion problem on Windows How to convert std::string to LPCSTR?
Possible Duplicate: String concatenation vs String Builder. Performance Any difference (performance and memory usage)
Possible Duplicate: Case insensitive string comparison in C++ C++ count and map How to
Possible Duplicate: String vs StringBuilder I just revisited some of the books that I
Possible Duplicate: Are string.Equals() and == operator really same? I know that in c#
Possible Duplicate: String greater, less, and equal comparison in XmlDocument Hi, In VBA I
Possible Duplicate: Convert string to Pascal Case (aka UpperCamelCase) in Javascript I'm doing some
Possible Duplicate: String comparison in Java heres my script: public class euler4 { /**

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.