To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 17674
17673  |  17675
Subject: 
RCX Firmware speed versus legOS
Newsgroups: 
lugnet.robotics
Date: 
Thu, 11 Apr 2002 17:23:20 GMT
Viewed: 
628 times
  
The discussion about the Firmware speed is intresting indeed. So I did a
fast, by no means representative, reserch. The following program is a legOS
program reading the light sensor, calculating some values and printing the
elapsed time:

------------------------------------------------------

#include <conio.h>
#include <unistd.h>
#include <dsensor.h>

int main()
{
int    i;
int    max, min, mean;
int    value;
time_t time;

   max = 0;
   min = 5000;
   mean = 0;
   value = 0;

   ds_active( &SENSOR_2 );
   time = sys_time;

   for( i = 1; i <= 10000; i++ ) {
      value = LIGHT_2;          // for empty loop comment out this line
      if( max < value ) max = value;
      if( min > value ) min = value;
      mean = ( mean * 3 - mean + value ) / 3;
   }
   time = sys_time - time;
   lcd_int( time );
   return 0;
}

----------------------------------------------------------

It took 0.211 sec. running empty, i.e. without reading the sensor but only
doing calculations, and 1.113 sec. with reading the sensor. So I can assume
that reading 10000 light values takes about 1 second.

I tried the same with the following nqc program:

----------------------------------------------------------

task main()
{
int i;
int max, min, mean;
int value;
int time;

   max = 0;
   min = 5000;
   mean = 0;
   value = 0;

   SetUserDisplay( 0, 0 );
   SetSensor( SENSOR_2, SENSOR_LIGHT );
   ClearTimer( 0 );
   for( i = 1; i <= 10000; i++ ) {
      value = SENSOR_2;
      if( max < value ) max = value;
      if( min > value ) min = value;
      mean = ( mean * 3 - mean + value ) / 3;
   }
   time = Timer( 0 );
   SetUserDisplay( time, 0 );
   until( false );
}

------------------------------------------------------------

This program is a direct conversion of the legOS version. The empty loop
took 322.3 sec.
So it can safely be assumed that the interpreted program runs about the
factor 300 slower than the assembly program generated by gcc. But with
reading the light sensor, the program only took 350.4 sec., giving about 30
secs for 10000 light sensor reads.
This result seems reasonable. The pure action of reading the light sensor
is roughly the same for legOS and the Firmware because reading an active
sensor value is very time critical.

Inspecting only the light sensor read, legOS is 30 times faster then a
Firmware program. But reading the sensor alone is not useful most of the
time. If one has do do some math with the results, legOS runs up and away.

The numbers for comparision:

                        empty                   with light reading

LegOS program:            0.211                            1.113
Firmware program:       322.3                            350.4

I would be pleased to get the results for my test program from lejos and
pbforth too, but I can't write a program in forth and are slow with java.
Any volunteers?

Bye

Mike



Message has 1 Reply:
  Re: RCX Firmware speed versus legOS
 
"Michael Obenland" <obenland@t-online.de> wrote in message news:GuEtHr.M39@lugnet.com... (...) but only (...) assume (...) I was surprized at the wide disparity between 'empty loop' and loop with 'reading the sensor'. I suspect there is significant (...) (23 years ago, 11-Apr-02, to lugnet.robotics)

3 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