Go to Post If it walks like a duck, and talks like a duck could be a very clever animatronics display created by Disney Imagineers.... Sometimes it is just a duck. - IKE [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-02-2005, 23:23
Gary Bonner Gary Bonner is offline
Registered User
FRC #3974
 
Join Date: Jan 2002
Rookie Year: 2000
Location: PA
Posts: 120
Gary Bonner has a spectacular aura aboutGary Bonner has a spectacular aura about
Which is faster?

Code:
if p1_y > 125
	Pwm1_green = 1;
else
	Pwm1_green = 0;
or

Code:
Pwm1_green = p1_y / 126;
  #2   Spotlight this post!  
Unread 26-02-2005, 23:25
Alex1072 Alex1072 is offline
Registered User
AKA: Alex
#1072 (Harker Robotics Team)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: San Jose
Posts: 110
Alex1072 is an unknown quantity at this point
Send a message via AIM to Alex1072 Send a message via Yahoo to Alex1072
Re: Which is faster?

Quote:
Originally Posted by Gary Bonner
Code:
if p1_y > 125
	Pwm1_green = 1;
else
	Pwm1_green = 0;
or

Code:
Pwm1_green = p1_y / 126;
I would say #2, but i'm not an expert on optimization.
__________________
--------------------------------------
Alex
President
Team 1072 Harker Robotics
  #3   Spotlight this post!  
Unread 26-02-2005, 23:56
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,721
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Which is faster?

I think it depends on the processor. Fancy pipelined processors don't do well with branches and if statements. I'm pretty sure the PIC isn't that fancy. The only real question is if it can complete a divide in one clock cycle or not. I'd bet on the latter being faster, though. The branch instruction is more likely to delay the processor more than a simple integer divide. Either one is going to be pretty darned fast, though.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
  #4   Spotlight this post!  
Unread 27-02-2005, 00:14
Arrow250 Arrow250 is offline
Custom User Title.
AKA: Nate
#0250 (Dynamos)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2002
Location: Colonie, NY
Posts: 1
Arrow250 is an unknown quantity at this point
Re: Which is faster?

Well it will be different on every CPU, but to give you an idea, on x86 machines, it compiles down to 27 and 31 lines of ASM for #1 and #2 respectively. So basically, the first has few instructions at a lower level. Though that still may not give much indication as to how fast it will run on the IFI PIC's. Especially with all the variables and aliases involved in the operation.
  #5   Spotlight this post!  
Unread 27-02-2005, 00:51
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,588
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Which is faster?

Nate, x86 has a built in divide instruction, while the PIC does not, so I'd expect both to be similar in number of instructions on x86 but not on the PIC. You didn't say how long each took though, because the divide instruction will take several cycles to execute.

Gary, You can put both in your code and compare them in the list file. That will give you the exact answer for the PIC.

Also, is it absolutely necessary to divide by 126? It would be much faster to divide by 128, which boils down to a rotate and an AND.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
coupling Bosch & Atwood motors caffel Motors 10 28-05-2003 16:00
How Do I Program My RC To Spot One wheel From Going faster than the other Kyle1010 Programming 5 12-01-2003 15:30
Robot Speeds - Opinions sought archiver 2000 31 23-06-2002 23:04


All times are GMT -5. The time now is 00:16.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi