Which one is faster ?
-
Hello. Which one is faster ? this one :
int x , y , z ;
.
.
.
//some codes 1 == some codes 2
if (x > y) { /*some codes 1*/ }
else if ( z > x ) { /*some codes 2*/ }or this one :
int x , y , z ;
.
.
.
if (x > y || z > x ) { /*some codes1*/ }Thanks.
-
Hello. Which one is faster ? this one :
int x , y , z ;
.
.
.
//some codes 1 == some codes 2
if (x > y) { /*some codes 1*/ }
else if ( z > x ) { /*some codes 2*/ }or this one :
int x , y , z ;
.
.
.
if (x > y || z > x ) { /*some codes1*/ }Thanks.
I really don't understand why you're asking this here. Why don't you set up a test that performs the comparisons a few thousand times and see for yourself?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
I really don't understand why you're asking this here. Why don't you set up a test that performs the comparisons a few thousand times and see for yourself?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thank you John .
John Simmons / outlaw programmer wrote:
Why don't you set up a test that performs the comparisons a few thousand times and see for yourself?
Well, I think it doesn't show the real result, because it will depend to our system configuration. Isn't it ?
-
Thank you John .
John Simmons / outlaw programmer wrote:
Why don't you set up a test that performs the comparisons a few thousand times and see for yourself?
Well, I think it doesn't show the real result, because it will depend to our system configuration. Isn't it ?
Yes, how fast it is depends on the system it's being run on, but since you're simply trying to determine which one is faster, the results should be comparative since you'd be running the test on the same system. You may have to run several hundred thousand iterations to get a measurable time.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Yes, how fast it is depends on the system it's being run on, but since you're simply trying to determine which one is faster, the results should be comparative since you'd be running the test on the same system. You may have to run several hundred thousand iterations to get a measurable time.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thank you my friend ;)
-
Hello. Which one is faster ? this one :
int x , y , z ;
.
.
.
//some codes 1 == some codes 2
if (x > y) { /*some codes 1*/ }
else if ( z > x ) { /*some codes 2*/ }or this one :
int x , y , z ;
.
.
.
if (x > y || z > x ) { /*some codes1*/ }Thanks.
It doesnt matter. Most likely both of those examples will JIT down to identical code. If they don't now, then they might later. Performance difference of those examples comes down to the platform implementation, which is really none of your business in a high level language like C#. You don't need to worry about performance at that level. If your application is running slowly, I can guarantee its not due to trivial things like this.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding. -
Thank you John .
John Simmons / outlaw programmer wrote:
Why don't you set up a test that performs the comparisons a few thousand times and see for yourself?
Well, I think it doesn't show the real result, because it will depend to our system configuration. Isn't it ?
not actually..... because you are going to execute and check both the code in the same machine.... right??? so system's performance will not have any impact on this....
Have a Happy Coding.....
-
not actually..... because you are going to execute and check both the code in the same machine.... right??? so system's performance will not have any impact on this....
Have a Happy Coding.....
King Julien wrote:
because you are going to execute and check both the code in the same machine.... right???
No, it will run in another systems with different hardware !
-
It doesnt matter. Most likely both of those examples will JIT down to identical code. If they don't now, then they might later. Performance difference of those examples comes down to the platform implementation, which is really none of your business in a high level language like C#. You don't need to worry about performance at that level. If your application is running slowly, I can guarantee its not due to trivial things like this.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.Mark Churchill wrote:
You don't need to worry about performance at that level. If your application is running slowly, I can guarantee its not due to trivial things like this.
Actually , I'm working on Image Processing. So I think , the simple things like these are important for reaching the most speed !
-
Mark Churchill wrote:
You don't need to worry about performance at that level. If your application is running slowly, I can guarantee its not due to trivial things like this.
Actually , I'm working on Image Processing. So I think , the simple things like these are important for reaching the most speed !
If you are really concerned you should take a look at the MSIL output of both approaches. This behaviour is not specified by the compiler - I'd suggest looking for algorithmetic speedups over "cargo-cult" coding kind of tricks. Either that or switch to an unmanaged compiler for absolute maximum peformance. Take a look at the Mono.SIMD library as well.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Entanglar: .Net game engine featuring automatic networking and powerful HLSL gfx binding.