RSS Forums RSS
Please support our Computer Science and Software Design advertiser: Programming Forums
Views: 1027 | Replies: 5
Reply
Join Date: Mar 2006
Posts: 12
Reputation: a.baki is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
a.baki a.baki is offline Offline
Newbie Poster

optimization problem

  #1  
Mar 26th, 2007
what is the difference between statements below?
  X = Y*0;
   X = 0;

a kind of optimization problem.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,318
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 42
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: optimization problem

  #2  
Mar 26th, 2007
I think you can see the difference right there for yourself. This has nothing to do with optimization, unless you enable the -fretarded flag on your compiler.
You can adblock jbennet's avatar.
Reply With Quote  
Join Date: Aug 2006
Location: South Africa, Durban
Posts: 112
Reputation: PoovenM is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 8
PoovenM PoovenM is offline Offline
Junior Poster

Re: optimization problem

  #3  
Mar 27th, 2007
I've never really heard of optimization on a high level programming language. In assembly perhaps.
So I would expect that X = 0 is more efficent that X = Y * 0;
The issue lies with memory access and compution. X = 0 accesses memory once where as the X = Y * 0 access memory twice and performs a calculation. If you look at the assembly commands to carry out these operations, you'll see the actual costs involved.
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: optimization problem

  #4  
Mar 28th, 2007
You don't optimize wrong code.. You correct it..
Why would anyone do x= y * 0; if they want to set x to 0 ?!
Last edited by thekashyap : Mar 28th, 2007 at 2:44 pm. Reason: it -> if
Reply With Quote  
Join Date: Apr 2005
Location: Dundee, Scotland
Posts: 13,041
Reputation: jbennet is just really nice jbennet is just really nice jbennet is just really nice jbennet is just really nice 
Rep Power: 33
Solved Threads: 310
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: optimization problem

  #5  
Mar 28th, 2007
yeah as anything timesed by 0 = 0

i suppose x = 0 would be faster than x = y * 0 as its less steps?
Last edited by jbennet : Mar 28th, 2007 at 4:39 pm.
TRY MY SUGGESTIONS AT YOUR OWN RISK

Master of puppets Im pulling your strings, blinded by me, you cant see a thing. Master! Master!
Reply With Quote  
Join Date: Jun 2005
Location: Cambridge, MA
Posts: 1,318
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 42
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

Re: optimization problem

  #6  
Mar 28th, 2007
You might have x = y * CONSTANT where #define CONSTANT 0 is located someplace. That's how you could get that in your code.

Whether x = y * 0 is compiled to anything different than x = 0 is compiled to depends on the compiler.
You can adblock jbennet's avatar.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:46 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC