Click here to Skip to main content
15,899,026 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: ADO .NET & Parameterized Stored Procedures Returning Recordset Pin
Ashfield26-Nov-09 1:14
Ashfield26-Nov-09 1:14 
GeneralRe: ADO .NET & Parameterized Stored Procedures Returning Recordset Pin
T210226-Nov-09 2:02
T210226-Nov-09 2:02 
QuestionCoding Buddy! Pin
venomation25-Nov-09 6:19
venomation25-Nov-09 6:19 
AnswerRe: Coding Buddy! Pin
T210225-Nov-09 20:28
T210225-Nov-09 20:28 
QuestionSpell Checker component required for ASP.Net application Pin
palakshah8525-Nov-09 2:14
palakshah8525-Nov-09 2:14 
AnswerRe: Spell Checker component required for ASP.Net application Pin
Eddy Vluggen26-Nov-09 10:11
professionalEddy Vluggen26-Nov-09 10:11 
QuestionStrange string.Compare behavior... Pin
Eric M Evans24-Nov-09 8:41
Eric M Evans24-Nov-09 8:41 
AnswerRe: Strange string.Compare behavior... Pin
Simon P Stevens24-Nov-09 23:12
Simon P Stevens24-Nov-09 23:12 
The common way to do case insensitive compares is to convert both strings to all one case first. As in your first example, one string is already entirely lower case, nothing needs to be done to it. This will probably result in less work.

[Disclaimer: Pretty much just a guess]

[Edit: I repeated your experiment.

I found that method 1 took around 1.7 seconds and method 2 around 1.4 seconds for 10,000,000 iterations. This makes method 2 just 20% (1.2 times) faster. (No where near 17 times).

If you are finding a 17 fold increase (1700%!) I suspect you have some other problem causing an erroneous result. Also, remember that string literals can be handled very differently by the JIT compiler compared to string variables. If you really want to test the methods you should probably be using a list of randomly generated strings to prevent things like literal optimisation or caching effecting your results.

This was my code:
class Program
{
    private static int iterations = 10000000;
    private static int repeats = 10;
                                    
    static void Main(string[] args)
    {
        long method1Total = 0;
        long method2Total = 0;

        for (int experiementCounter = 0; experiementCounter < repeats; experiementCounter++)
        {
            Stopwatch s1 = new Stopwatch();
            s1.Start();
            for (int iterationCounter = 0; iterationCounter < iterations; iterationCounter++)
            {
                bool result1 = string.Compare("aBcDeFgHiJkLmNoPqRsTuVwXyZ", "abcdefghijklmnopqrstuvwxyz", true) == 0;
            }
            s1.Stop();

            

            Stopwatch s2 = new Stopwatch();
            s2.Start();
            for (int iterationCounter = 0; iterationCounter < iterations; iterationCounter++)
            {
                bool result2 = string.Compare("aBcDeFgHiJkLmNoPqRsTuVwXyZ", "aBcDeFgHiJkLmNoPqRsTuVwXyZ", true) == 0;
            }
            s2.Stop();

            method1Total += s1.ElapsedMilliseconds;
            method2Total += s2.ElapsedMilliseconds;

            Console.WriteLine("Experiment {0} Method 1: {1} Method 2: {2}", experiementCounter+1, s1.ElapsedMilliseconds,s2.ElapsedMilliseconds);
        }
        Console.WriteLine();
        Console.WriteLine("Averages: Method 1: {0} Method 2: {1}", method1Total / repeats, method2Total / repeats);
        Console.ReadLine();
    }
}


Simon

GeneralRe: Strange string.Compare behavior... Pin
Shameel24-Nov-09 23:51
professionalShameel24-Nov-09 23:51 
GeneralRe: Strange string.Compare behavior... Pin
Eric M Evans25-Nov-09 6:04
Eric M Evans25-Nov-09 6:04 
GeneralRe: Strange string.Compare behavior... Pin
Luc Pattyn25-Nov-09 6:37
sitebuilderLuc Pattyn25-Nov-09 6:37 
QuestionDOT NET - Design Patterns Pin
Reshma.R24-Nov-09 0:52
Reshma.R24-Nov-09 0:52 
AnswerRe: DOT NET - Design Patterns Pin
Eddy Vluggen24-Nov-09 1:30
professionalEddy Vluggen24-Nov-09 1:30 
AnswerRe: DOT NET - Design Patterns Pin
Pete O'Hanlon24-Nov-09 1:38
mvePete O'Hanlon24-Nov-09 1:38 
AnswerRe: DOT NET - Design Patterns Pin
Shameel24-Nov-09 3:44
professionalShameel24-Nov-09 3:44 
AnswerRe: DOT NET - Design Patterns Pin
The Man from U.N.C.L.E.24-Nov-09 4:27
The Man from U.N.C.L.E.24-Nov-09 4:27 
AnswerRe: DOT NET - Design Patterns Pin
Kevin McFarlane24-Nov-09 5:26
Kevin McFarlane24-Nov-09 5:26 
AnswerRe: DOT NET - Design Patterns Pin
Giorgi Dalakishvili24-Nov-09 5:41
mentorGiorgi Dalakishvili24-Nov-09 5:41 
Questionversion issue Pin
Abbas_here23-Nov-09 2:49
Abbas_here23-Nov-09 2:49 
AnswerRe: version issue Pin
Mark Salsbery23-Nov-09 6:52
Mark Salsbery23-Nov-09 6:52 
GeneralRe: version issue Pin
Abbas_here23-Nov-09 19:03
Abbas_here23-Nov-09 19:03 
Questionwindow.showModalDialog? Pin
pss.srinivasan22-Nov-09 23:42
pss.srinivasan22-Nov-09 23:42 
AnswerRe: window.showModalDialog? Crosspost Pin
Richard MacCutchan22-Nov-09 23:57
mveRichard MacCutchan22-Nov-09 23:57 
AnswerRe: window.showModalDialog? Pin
darkyro27-Nov-09 12:09
darkyro27-Nov-09 12:09 
QuestionData retrieve using VB.NET Pin
Jayaram Das22-Nov-09 23:05
Jayaram Das22-Nov-09 23:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.