473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

what is better in performance ?

Hi , I have this method to check something..

my question is if changing the order of the "if " will make it faster

when the "val" argument is 99% or int or string

for example , the IsSerializable is faster or slower then

val is string , or val is int...

?

here is the code:

bool method(Object val)

{

Type _type = val.GetType();

if (_type.IsPrimitive)

return true;

else if (_type.IsEnum)

return true;

else if (_type.IsSerializable)

return true;

else if (val is string)

return true;

else if (val is string[])

return true;

else if (val is byte[])

return true;

else

return false;

}
Oct 15 '06 #1
5 1205
Well, it isn't entirely clear what the intent is, but...

Technically, yes, if you can test common scenarios earlier on, it
should perform *marginally* quicker due to short circuiting. However,
in this code I suspect that any such concern is a false optimisation,
as it should be pretty quick in any order. Do you have a reason to
suspect that there is a performance problem here? If not, profile your
app, and concentrate your effort in the bits that actually *are* taking
time.

Marc

Oct 15 '06 #2
thanks
I can use this method in some loop etc , so I think about it before I had
any problems.. :)

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Well, it isn't entirely clear what the intent is, but...

Technically, yes, if you can test common scenarios earlier on, it
should perform *marginally* quicker due to short circuiting. However,
in this code I suspect that any such concern is a false optimisation,
as it should be pretty quick in any order. Do you have a reason to
suspect that there is a performance problem here? If not, profile your
app, and concentrate your effort in the bits that actually *are* taking
time.

Marc

Oct 15 '06 #3
Semedao,

Take the advice from Marc, if you are using it in a loop that is processed
10000000000 times. That is when you see it probably, than it is time to
profile your application, but not in this bit f*cking part.

Cor

"semedao" <se*****@community.nospamschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
thanks
I can use this method in some loop etc , so I think about it before I had
any problems.. :)

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>Well, it isn't entirely clear what the intent is, but...

Technically, yes, if you can test common scenarios earlier on, it
should perform *marginally* quicker due to short circuiting. However,
in this code I suspect that any such concern is a false optimisation,
as it should be pretty quick in any order. Do you have a reason to
suspect that there is a performance problem here? If not, profile your
app, and concentrate your effort in the bits that actually *are* taking
time.

Marc


Oct 15 '06 #4
A reasonable thing to ponder, but in *general*, a large part of
performance issues tend to relate to:
1: "O" (handling big sets of data; does twice as much take twice as
long? 4 times? 8 times?)
2: "IO" (network, disk, etc)

Since you are doing either, any performance glitch here will be linear,
so yes: in a tight loop that runs a huge amount of times, you might
notice it, but from what I can see of the code, I doubt you'll get any
real, tangible, benefit in real usage. Maybe if you were doing
something hugely maths intensive, and every picosecond counts...

Marc

Oct 16 '06 #5
sorry: neither

Oct 16 '06 #6

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

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
24
by: Bob Alston | last post by:
Most of my Access database implementations have been fairly small in terms of data volume and number of concurrent users. So far I haven't had performance issues to worry about. <knock on wood> ...
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
5
by: serge | last post by:
Is it generally or almost always better to have multiple small SPs and functions to return a result set instead of using a single big 1000+ lines SP? I have one SP for example that is 1000+...
37
by: deepu | last post by:
Please reply...
15
by: jim | last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot of apps in .Net (although they certainly push it for others). What does MS write using pure .Net? If applications...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
10
by: timor.super | last post by:
Hi all, Imagine I've an array of int : int anArray = new int; I want to extract all the integer that are superior to 500 I can do :
66
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.