PC Review


Reply
Thread Tools Rate Thread

Code Performance

 
 
koorb
Guest
Posts: n/a
 
      20th Aug 2004
Every so often I read something like:
"use a defensive code technique like File.Exists instead of a Try and
Catch because it's less of a performance hog"

And when I program, I obviously have different ideas on how to code
different sections. So how to I findout what's best from a performance
point-of-view?
 
Reply With Quote
 
 
 
 
Richard Myers
Guest
Posts: n/a
 
      21st Aug 2004
Test and read.

Do you understand what they mean by defensive coding techniques in this
scenario?

Richard


"koorb" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Every so often I read something like:
> "use a defensive code technique like File.Exists instead of a Try and
> Catch because it's less of a performance hog"
>
> And when I program, I obviously have different ideas on how to code
> different sections. So how to I findout what's best from a performance
> point-of-view?



 
Reply With Quote
 
koorb
Guest
Posts: n/a
 
      21st Aug 2004
On Sat, 21 Aug 2004 12:40:59 +1200, "Richard Myers"
<richard.spam-(E-Mail Removed)> wrote:

>Test and read.
>
>Do you understand what they mean by defensive coding techniques in this
>scenario?
>
>Richard


Yep, but is there a way of finding out the difference in performance
between two sets of the same code?
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      21st Aug 2004
* koorb <(E-Mail Removed)> scripsit:
>> Test and read.
>>
>> Do you understand what they mean by defensive coding techniques in this
>> scenario?
>>
>> Richard

>
> Yep, but is there a way of finding out the difference in performance
> between two sets of the same code?


Experience and testing.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Richard Myers
Guest
Posts: n/a
 
      21st Aug 2004

It depends what performance metric your trying to optimise for? Speed,
memory usage etc.

We're not trying to be smart arsed about it but there are so many different
answers to your question. For example if it were purely speed, you could
test a given method/algorithm by timestamping the entry/exit points for each
alternative implementation. i.e test.

More often though it as important to know why one alternative is
faster/slower than another as this can have implications for other metrics.
For instance if you are optimising purely for speed then you have one
variable to consider, but if you're optimising for speed/memory useage then
you have 2 variables to consider, so then you have to give a relative weight
to each in terms of its performance.

If as above, then you might choose the slower algorithm because you have
afforded memory useage a greater weighting in terms of solution
effectiveness. Hence Herfrieds comments about experience.

Theres no definitive answer to this question...as everything "depends".











 
Reply With Quote
 
rob willaar
Guest
Posts: n/a
 
      21st Aug 2004
I often use this code to check performance:

Dim tm As Double

tm = Microsoft.VisualBasic.Timer

'do something

MsgBox(Microsoft.VisualBasic.Timer - tm)


It's not perfect but better then nothing

"koorb" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Every so often I read something like:
> "use a defensive code technique like File.Exists instead of a Try and
> Catch because it's less of a performance hog"
>
> And when I program, I obviously have different ideas on how to code
> different sections. So how to I findout what's best from a performance
> point-of-view?



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      21st Aug 2004
Koorb,

Performance can seldom be the priority (in a PC application, I am not
talking about PDA).

Most programs on modern computers are much faster than a user can act.

Your example you can test if a File.Exist so why not test on that, you can
than take the proper procedures.

You cannot test if the file is damaged, so you need to use the try as well.

This is not a matter of performance, when you user has a problem, you have a
much larger problem than when the object is deboxed in 1/100000000 of a
nanosecond or that it is deboxed in 1/99999999 of a nanaosecond.

Just my 2 eurocents

Cor


 
Reply With Quote
 
koorb
Guest
Posts: n/a
 
      21st Aug 2004
On Sat, 21 Aug 2004 14:20:19 +0200, "Cor Ligthert"
<(E-Mail Removed)> wrote:

>Koorb,
>
>Performance can seldom be the priority (in a PC application, I am not
>talking about PDA).
>
>Most programs on modern computers are much faster than a user can act.
>
>Your example you can test if a File.Exist so why not test on that, you can
>than take the proper procedures.
>
>You cannot test if the file is damaged, so you need to use the try as well.
>
>This is not a matter of performance, when you user has a problem, you have a
>much larger problem than when the object is deboxed in 1/100000000 of a
>nanosecond or that it is deboxed in 1/99999999 of a nanaosecond.
>
>Just my 2 eurocents
>
>Cor


Ok thanks, I suppose it's not worth worrying about unless there is an
actual problem then.
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      21st Aug 2004
* koorb <(E-Mail Removed)> scripsit:
> Ok thanks, I suppose it's not worth worrying about unless there is an
> actual problem then.


Make sure your code can be understood easily -- that's much more
important than some milliseconds more of execution time.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
koorb
Guest
Posts: n/a
 
      21st Aug 2004
On 21 Aug 2004 14:54:02 +0200, hirf-spam-me-(E-Mail Removed) (Herfried K.
Wagner [MVP]) wrote:

>* koorb <(E-Mail Removed)> scripsit:
>> Ok thanks, I suppose it's not worth worrying about unless there is an
>> actual problem then.

>
>Make sure your code can be understood easily -- that's much more
>important than some milliseconds more of execution time.


I always get praised for my code being easily understood so there is
no worries there. Plus I comment a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba Code Performance Klips Microsoft Excel Programming 1 13th Apr 2007 12:27 PM
Trying to improve the performance of my code =?Utf-8?B?Q2FybG8=?= Microsoft Excel Programming 2 22nd Dec 2006 09:06 AM
C# code benchmark performance =?Utf-8?B?TWFjY2E=?= Microsoft C# .NET 6 6th Dec 2005 09:25 PM
performance and code behind =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= Microsoft ASP .NET 2 8th Feb 2005 02:40 PM
Code Performance Question MattC Microsoft C# .NET 3 11th Jan 2005 12:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:18 AM.