To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1047
1046  |  1048
Subject: 
Re: "Speed" of control statments
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sat, 31 Mar 2001 00:09:38 GMT
Viewed: 
2421 times
  
Actually, its not a general programming question.  Efficiency of
something like events is heavily dependent on the operating system (in
this case the Lego firmware).  Efficiency of "if" vs. "switch" can be
very dependent on the compiler and the CPU architecture itself.  A good
compiler will generally pick the most efficient way to code a switch
statement, so if it has only one case and a default, the resulting code
will probably look a lot like the code generated from an "if" statement,
rather than the table-drive code that many "switch" statements generate.

For NQC/RCX...

I haven't done extensive testing, but I believe the fastest response is
using events provided that all tasks are idle (stopped or in a Wait()
call).  That means you probably want to code your main loop something
like this:

while(true)
{
  monitor(..your event mask here..)
  {
    while(true) Wait(32767);
  }
  catch
  {
  }
}


----

If you just use "while(true);" instead of "while(true) Wait(32767);",
then the task will be continuously executing bytecodes (in this case a
single jump instruction).  By using Wait, only two bytecodes are
executed every 5 minutes or so.

The optimization for some trivial cases (constant condition, empty body,
etc) of "if" statements can be slightly better than the corresponding
"switch" statement.  For non-trivial cases, however, the code should be
the same, so the "if" vs. "switch" decision is largely a personal
preference and whatever you feel expresses the problem most cleanly.

Dave

In article <GB0n44.n49@lugnet.com>, "Jeff Lalo" <jeff_lalo@hotmail.com>
wrote:

I have been currently working on a control program that necessitates the
highest reaction time possible.  Does anyone what the fastest control
statements would be using NQC (making the outputs react to sensor values
as
fast as possible)?  i.e. Which is faster a series of if...else, event
monitoring or switch statements?

Thanks in advance for the help, I realize this is a more general
programming
question, but I am not a programmer (An old college PASCAL course and NQC
is
as far as I go)

--
reply to: dbaum at enteract dot com



Message is in Reply To:
  "Speed" of control statments
 
I have been currently working on a control program that necessitates the highest reaction time possible. Does anyone what the fastest control statements would be using NQC (making the outputs react to sensor values as fast as possible)? i.e. Which (...) (24 years ago, 30-Mar-01, to lugnet.robotics.rcx.nqc)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR