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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:01:44+00:00 2026-05-25T20:01:44+00:00

I’m using Visual Studio 2010 SP1, Target framework is 2.0, Platform target: Any CPU,

  • 0

I’m using Visual Studio 2010 SP1, Target framework is 2.0, Platform target: Any CPU, testing under Windows 7 x64 SP1.

I’m experiencing strange performance behavior.

Without an app.config, or with the following app.config, it makes my program run slowly (Stopwatch shows ~0.11 s)

<?xml version="1.0"?>
<configuration>
  <startup >
    <supportedRuntime version="v2.0.50727" />
  </startup>
</configuration>

The following app.config makes my program run x5 times faster (Stopwatch shows ~0.02 s)

<?xml version="1.0"?>
<configuration>
  <startup >
    <supportedRuntime version="v4.0.30319" sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>

This is the test program code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        Stopwatch sw = new Stopwatch();

        while (true)
        {
            sw.Reset();
            sw.Start();

            for (int i = 0; i < 1000000; i++ )
            {
                "blablabla".IndexOf("ngrhotbegmhroes", StringComparison.OrdinalIgnoreCase);
            }

            Console.WriteLine(sw.Elapsed);
        }
    }
}

I’m sitting for hours and can’t figure out what is happening here.
Have you any idea?

  • 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-25T20:01:45+00:00Added an answer on May 25, 2026 at 8:01 pm

    It sounds like you’ve just found a situation in which .NET 4 is a lot faster. By default, your app is running with the framework it was built to target. When you force it to use .NET 4, it’s faster. That may be a JIT compiler improvement which happens to hit your situation, or it may be a framework improvement – but it shouldn’t be too surprising that some things are faster in newer versions.

    (For what it’s worth, I’d increase the number of iterations you’re timing over if I were you… on my box under .NET 4, each iteration is only 10ms, which isn’t really a great measurement. I prefer to benchmark for at least a few seconds.)

    (And like Mitch, I can confirm that I see the same effect.)

    EDIT: I’ve just investigated this a bit further, and seen an interesting effect… I’ll assume we’re calling haystack.IndexOf(needle, StringComparison.OrdinalIgnoreCase):

    • On .NET 2, the results are roughly the same however big the “needle” is
    • On .NET 4:
      • If needle is bigger than haystack (as per your example) .NET 4 is much faster than .NET 2
      • If needle is the same size as haystack, .NET 4 is a little bit slower than .NET 2
      • If needle is smaller than haystack, .NET 4 is a lot slower than .NET 2

    (This is keeping a test where the first character of needle never appears in haystack, btw.)

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

Sidebar

Related Questions

No related questions found

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.