473,804 Members | 3,700 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
18 1195
> I always get praised for my code being easily understood so there is
no worries there. Plus I comment a lot.


When your code is easily to understood there is no need for commenting.

I could not resist in this.

:-)

Cor
Nov 21 '05 #11
* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
I always get praised for my code being easily understood so there is
no worries there. Plus I comment a lot.


When your code is easily to understood there is no need for commenting.


Aren't comments /part of/ the code?

:-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #12
Koorb,
In addition to the other statements.

Remember the 80/20 rule! That is 80% of the execution time of your program
is spent in 20% of your code. I will optimize (worry about performance) the
20% once that 20% has been identified & proven to be a performance problem
via profiling (CLR Profiler is one profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

In the File.Exists case, it really depends on whether you should use it or
not. On both the likely hood of the file existing & how often you are
creating the file.

For example, if I am coding the "File Save" command for a Windows Forms
Application, then I probably would not worry about coding for File.Exists.

However! if I am coding a file save routine for a Window Service application
that is processing 100s of files per minute, then I would use the File.Exits
to avoid the overhead of possible 100s of exceptions per minute.

CLR Profiler is a tool you can reliably use to see if you app is not
releasing memory as it should.

Info on the CLR Profiler:
http://msdn.microsoft.com/library/de...nethowto13.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

In addition to the above articles, The following articles provide
information on writing .NET code that performs well. I believe one of the
covers how to use Performance Monitor under Control Panel to monitor the
memory usage of your app.

http://msdn.microsoft.com/architectu...l/scalenet.asp

http://msdn.microsoft.com/library/de...anagedcode.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

http://msdn.microsoft.com/library/de...vbnstrcatn.asp

http://msdn.microsoft.com/library/de...tchperfopt.asp

http://msdn.microsoft.com/library/de...tperftechs.asp
Hope this helps
Jay
"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 #13
When your code is easily to understood there is no need for commenting.


Whats really annoying is when you can understand another developers code but
not their comments.
Sometimes less is more.

;)
Nov 21 '05 #14
* "Richard Myers" <ri************ *********@basd. co.nz> scripsit:
When your code is easily to understood there is no need for commenting.


Whats really annoying is when you can understand another developers code but
not their comments.
Sometimes less is more.


I always try to keep my code self-explaining, without the use
of comments. Sometimes that's impossible, but often comments are used
to compensate poor/bad style.

;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #15
Herfried,

I always try to keep my code self-explaining, without the use
of comments. Sometimes that's impossible, but often comments are used
to compensate poor/bad style.

;-)


Aha, so why this sentence from you in this thread before on a sentence with
the same meaning as above?
Aren't comments /part of/ the code?

:-)

Cor

Nov 21 '05 #16
Cor,

* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
I always try to keep my code self-explaining, without the use
of comments. Sometimes that's impossible, but often comments are used
to compensate poor/bad style.

;-)


Aha, so why this sentence from you in this thread before on a sentence with
the same meaning as above?
Aren't comments /part of/ the code?


Comments are a part of the code that should be used only if it's really
necessary ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #17
Herfried,
If you read "Refactorin g - Improving the design of Existing Code" by Martin
Fowler from Addison Wesley http://www.refactoring.com/

Martin would suggests that too many comments is a "bad smell" in your code.
A "bad smell" is a section of cod that needs to be improved. Specifically
Martin states in reference to a long methods:

"A heuristic we follow is that whenever we feel
the need to comment something, we write a method
instead. Such a method contains the code that was
commented but is named after the intention of the
code rather then how it does it".

Basically if you have a long method where you have a comment every 10 or 15
lines, that each of those 10 or 15 lines should be its own method, where the
name of the method is the comment.

Martin is not suggesting you do not put comments before methods that explain
what the method does, what it expects & what it returns. He is referring to
comments within the method bodies themselves.

Hope this helps
Jay

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2o******** ****@uni-berlin.de...
* "Cor Ligthert" <no**********@p lanet.nl> scripsit:
I always get praised for my code being easily understood so there is
no worries there. Plus I comment a lot.


When your code is easily to understood there is no need for commenting.


Aren't comments /part of/ the code?

:-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #18
On Sat, 21 Aug 2004 18:56:16 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja************ @msn.com> wrote:
Koorb,
In addition to the other statements.

Remember the 80/20 rule! That is 80% of the execution time of your program
is spent in 20% of your code. I will optimize (worry about performance) the
20% once that 20% has been identified & proven to be a performance problem
via profiling (CLR Profiler is one profiling tool).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf


<snip>

Some interesting philosophical reading, but with the small stuff I am
writing at the moment the best thing is simply, be responsible with
variables and to make each event quick and painless.

Although I think that profiler might come in handy. :)
Nov 21 '05 #19

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

Similar topics

51
5296
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
25
2355
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
12633
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
3684
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
8104
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
2651
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
3553
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
3382
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
9582
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
10580
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
10335
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...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
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
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
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.