what is better in performance ?

  • Thread starter Thread starter semedao
  • Start date Start date
S

semedao

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;

}
 
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
 
thanks
I can use this method in some loop etc , so I think about it before I had
any problems.. :)
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top