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 1105787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:41:23+00:00 2026-05-17T01:41:23+00:00

I will explain my problem(excuse my bad English), I have a .NET exe in

  • 0

I will explain my problem(excuse my bad English), I have a .NET exe in which every milliseconds of processing is very important.

This program does lots of string comparison (most of it is string1.IndexOf(string2, StringComparison.OrdinalIgnoreCase)).

When i switch to framework 4, my program time is twice than before.

I searched for explanation and I found that the function IndexOf(s, OrdinalIgnoreCase) is much slower in framework 4 (I did test with a simple console application and in a loop the time was 30ms in 3.5 and 210ms in 4.0 ???). But the comparison in current culture is quicker in framework 4 than 3.5.

Here it’s a sample of code I use :

int iMax = 100000;
String str  = "Mozilla/5.0+(Windows;+U;+Windows+NT+5.1;+fr;+rv:1.9.0.1)+Gecko/2008070208+Firefox/3.0.1";
Stopwatch sw = new Stopwatch();
sw.Start();
StringComparison s = StringComparison.OrdinalIgnoreCase;
for(int i = 1;i<iMax;i++)
{
    str.IndexOf("windows", s);
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
Console.Read();

My questions are :

  1. Has anyone noticed the same problem?

  2. Someone have an explanation on this change?

  3. Is there a solution to bypass the problem?

Thanks.

  • 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-17T01:41:23+00:00Added an answer on May 17, 2026 at 1:41 am

    Ok i have a response of one of my question.

    With reflector i can see the difference between framework 2 and 4 and that explain my perforamnce issue.

        public int IndexOf(string value, int startIndex, int count, StringComparison comparisonType)
    {
        if (value == null)
        {
            throw new ArgumentNullException("value");
        }
        if ((startIndex < 0) || (startIndex > this.Length))
        {
            throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index"));
        }
        if ((count < 0) || (startIndex > (this.Length - count)))
        {
            throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count"));
        }
        switch (comparisonType)
        {
            case StringComparison.CurrentCulture:
                return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.None);
    
            case StringComparison.CurrentCultureIgnoreCase:
                return CultureInfo.CurrentCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
    
            case StringComparison.InvariantCulture:
                return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.None);
    
            case StringComparison.InvariantCultureIgnoreCase:
                return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.IgnoreCase);
    
            case StringComparison.Ordinal:
                return CultureInfo.InvariantCulture.CompareInfo.IndexOf(this, value, startIndex, count, CompareOptions.Ordinal);
    
            case StringComparison.OrdinalIgnoreCase:
                return TextInfo.IndexOfStringOrdinalIgnoreCase(this, value, startIndex, count);
        }
        throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType");
    }
    

    This is the base code of function IndexOf of the 2 framework (no difference between 4 and 2)

    But in the function TextInfo.IndexOfStringOrdinalIgnoreCase there are differences :

    Framework 2 :

        internal static unsafe int IndexOfStringOrdinalIgnoreCase(string source, string value, int startIndex, int count)
    {
        if (source == null)
        {
            throw new ArgumentNullException("source");
        }
        return nativeIndexOfStringOrdinalIgnoreCase(InvariantNativeTextInfo, source, value, startIndex, count);
    }
    

    Framework 4 :

        internal static int IndexOfStringOrdinalIgnoreCase(string source, string value, int startIndex, int count)
    {
        if ((source.Length == 0) && (value.Length == 0))
        {
            return 0;
        }
        int num = startIndex + count;
        int num2 = num - value.Length;
        while (startIndex <= num2)
        {
            if (CompareOrdinalIgnoreCaseEx(source, startIndex, value, 0, value.Length, value.Length) == 0)
            {
                return startIndex;
            }
            startIndex++;
        }
        return -1;
    }
    

    The main algorithm has changed in framework 2 the call is a nativeDll that has been removed of framework 4.
    Its good to know

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

Sidebar

Related Questions

i have a problem with a asp.net website first i will explain the current
I will explain the problem with an example. I have a Vehicle object which
I have problem adding arraylist to list view, will explain about my problem here..
I have a problem and I will try to explain the issue: I have
I have a problem with JPA I will explain in detail: I created a
I will try to explain my problem clearly: I have two tables: document and
I will explain my problem statement with the following illustration. I have 4 machines,
I will try to explain my problem. I have 4 files index.html, event.js, start.js
I will try to explain the problem that I have with this code. This
I have CSS problems. I will try to explain my problem to you with

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.