Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 11:07
Paw Jershauge13-Apr-10 11:07 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 11:08
mvePIEBALDconsult13-Apr-10 11:08 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 12:20
Paw Jershauge13-Apr-10 12:20 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:11
mvePIEBALDconsult13-Apr-10 13:11 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 19:44
Paw Jershauge13-Apr-10 19:44 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult14-Apr-10 3:15
mvePIEBALDconsult14-Apr-10 3:15 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:15
mvePIEBALDconsult13-Apr-10 13:15 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 20:28
Paw Jershauge13-Apr-10 20:28 
PIEBALDconsult wrote:
You don't find that a little suspicious? I expect the whole for loop got optimized away, I've had that happen before. Try summing up the values and print the sum after the loop to ensure that it doesn't it doesn't get optimized.


Actualy you might be right about the optimizing, but the fact is that the code is an will be faster running TryParse.


PIEBALDconsult wrote:
Paw Jershauge wrote:
catch (Exception) {}

I certainly didn't suggest that.


i didn't say you did. this was only a very very short demo test.


PIEBALDconsult wrote:
Paw Jershauge wrote:
int.Parse("x");

That's just silly.


No not really, as my p.o.i. was to fail anyway.

Stopwatch sw = new Stopwatch();
int ParseOutPut = 0;
sw.Start();
for (int i = 0; i < 1000; i++)
{
    try
    {
        int demo = 0;
        if(i % 3 == 0)
            demo = int.Parse("x");
        else
            demo = int.Parse("1" + i.ToString());
        ParseOutPut += demo;
    }
    catch (Exception) { }
}
sw.Stop();
Debug.WriteLine("Parse [" + ParseOutPut + "]: " + sw.ElapsedMilliseconds);
sw.Reset();
int TryParseOutPut = 0;
sw.Start();
for (int i = 0; i < 1000; i++)
{
    int demo;
    if(i % 3 == 0)
        int.TryParse("x", out demo);
    else
        int.TryParse("1" + i.ToString(), out demo);
    TryParseOutPut += demo;
}
sw.Stop();
Debug.WriteLine("Try Parse [" + TryParseOutPut + "]: " + sw.ElapsedMilliseconds);

Returns on my computer:
Parse [938727]: 1464 ms
Try Parse [938727]: 0 ms
With great code, comes great complexity, so keep it simple stupid...Shucks | :-\ Shucks | :-\

GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:29
mvePIEBALDconsult13-Apr-10 13:29 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 20:33
Paw Jershauge13-Apr-10 20:33 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult14-Apr-10 3:12
mvePIEBALDconsult14-Apr-10 3:12 
QuestionStopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 9:42
Jacob Dixon12-Apr-10 9:42 
AnswerRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 9:58
mvePIEBALDconsult12-Apr-10 9:58 
AnswerRe: Stopping threads (semi-safely).... Pin
Dave Kreskowiak12-Apr-10 9:59
mveDave Kreskowiak12-Apr-10 9:59 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:16
Jacob Dixon12-Apr-10 10:16 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:51
Jacob Dixon12-Apr-10 10:51 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:02
mvePIEBALDconsult12-Apr-10 13:02 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:39
Jacob Dixon12-Apr-10 13:39 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:51
mvePIEBALDconsult12-Apr-10 13:51 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:58
Jacob Dixon12-Apr-10 13:58 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 14:15
mvePIEBALDconsult12-Apr-10 14:15 
GeneralRe: Stopping threads (semi-safely).... Pin
Dave Kreskowiak12-Apr-10 15:33
mveDave Kreskowiak12-Apr-10 15:33 
AnswerRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 10:23
William Winner12-Apr-10 10:23 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:27
Jacob Dixon12-Apr-10 10:27 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 10:55
sitebuilderLuc Pattyn12-Apr-10 10:55 

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.