473,795 Members | 3,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code Performance

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?
Nov 21 '05 #1
18 1193
Test and read.

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

Richard
"koorb" <ko***@raidrs.c o.uk> wrote in message
news:bu******** *************** *********@4ax.c om...
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?

Nov 21 '05 #2
On Sat, 21 Aug 2004 12:40:59 +1200, "Richard Myers"
<ri************ *********@basd. co.nz> 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?
Nov 21 '05 #3
* koorb <ko***@raidrs.c o.uk> 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/>
Nov 21 '05 #4

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".



Nov 21 '05 #5
I often use this code to check performance:

Dim tm As Double

tm = Microsoft.Visua lBasic.Timer

'do something

MsgBox(Microsof t.VisualBasic.T imer - tm)
It's not perfect but better then nothing

"koorb" <ko***@raidrs.c o.uk> schreef in bericht
news:bu******** *************** *********@4ax.c om...
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?

Nov 21 '05 #6
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
Nov 21 '05 #7
On Sat, 21 Aug 2004 14:20:19 +0200, "Cor Ligthert"
<no**********@p lanet.nl> 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.
Nov 21 '05 #8
* koorb <ko***@raidrs.c o.uk> 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/>
Nov 21 '05 #9
On 21 Aug 2004 14:54:02 +0200, hi************* **@gmx.at (Herfried K.
Wagner [MVP]) wrote:
* koorb <ko***@raidrs.c o.uk> 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.
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
5295
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
25
2352
by: Delta | last post by:
Drop Down Menu Mozilla : work well widowed elements such as drop downs, except for flash movies IE : work well so far http://pwp.netcabo.pt/falmartins/index.htm
13
17116
by: Gaijinco | last post by:
Every now and then and found two ways to resolve a problem. I try to find a way to decide which one is best (at least speed-wise) but I don't know how do I test how long those it take a program to run?
65
12622
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
29
3682
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form id="Form1" method="post" runat="server"> <%
88
8097
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
48
2642
by: Tony | last post by:
How much bloat does the STL produce? Is it a good design wrt code bloat? Do implementations vary much? Tony
30
3549
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
66
3379
by: John | last post by:
Hi What are the advantages actually achieved of managed code? I am not talking of theory but in reality. Thanks Regards
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.