ROBOTC.net forums
http://robotc.net/forums/

Instructions per cycle....
http://robotc.net/forums/viewtopic.php?f=1&t=5713
Page 1 of 1

Author:  elizabeth.mabrey [ Wed Apr 17, 2013 10:50 am ]
Post subject:  Instructions per cycle....

I'm back to ponder about the processing power between Arduino-Mega-Sketch vs NXT-RobotC ...

I read from one the previous post - "about 10 instructions out of the 48K cycles in a millisecond...", ie.
- ~20 µs per cycle (based on ~50 cycles per msec)
- ~1 instruction per 100 µs.

Since RobotC executable is bytecode so to speak, not like the Arduino's Sketch .hex binary code, even the processing power of Arduino's mega is lower than NXT's, I wonder how does the comparison between the two fare?

Author:  magicode [ Sat Apr 20, 2013 4:46 am ]
Post subject:  Re: Instructions per cycle....

I think you're misunderstanding the quote. Here's the original:
Dick Swan wrote:
RobotC keeps a single list of waiting tasks that is sorted by when wiat-time expires. On a new timer tick it only needs to check to see if the top queue element timer is less than the current timer. This is about as close as you can get to "not consume any CPU cycles" -- i.e. about 10 instructions out of the 48K cycles in a millisecond.

I think Dick is saying that the background processing for the timers only takes about 10 instructions per millisecond. Not that 10 instructions execute in 48,000 cycles.

The NXT's main processor is the AT91SAM7S256 chip, which runs at around 48 MHz, while the ATmega1280 chip used for the Arduino Mega runs at 16 Mhz. I don't know how much overhead ROBOTC adds to the CPI (I asked this myself before) vs the .hex for the Arduino, but I'm fairly certain that the processor speed difference more than accounts for that.

Author:  mattallen37 [ Sat Apr 20, 2013 12:34 pm ]
Post subject:  Re: Instructions per cycle....

The NXT uses a task scheduler, so there is overhead involved in that as well.

With the standard Arduino setup (not ROBOTC for Arduino), unless you do some fancy programming (or make use of the right library), you can't multitask on an Arduino (this applies to the Uno, Mega, Leonardo, etc.). If you do multitask on an Arduino, the task scheduler will use up a huge amount of the resources, and add a lot of overhead to the execution.

Any time you have a CPU dedicated to a single task, it will be far more efficient than running the same task on a CPU that is multitasking (especially if it uses a byte-code interpreter as well). For example, if you toggle an Arduino pin as fast as possible in code (using the standard Opti-boot and compiler, it's 4 MHz sustained), it's far faster than toggling one of the NXT IO pins in code (using ROBOTC, it seems to be about 60kHz to 72.3kHz, with a ~0.19 ms break every 1ms (likely for maintenance of the LCD etc.)).

Here are the two programs I used for testing the speed.

Uno:
Code:
void setup()
{
  pinMode(1, OUTPUT);
}

void loop()
{
Restart:
  PORTD = 0x02;
  PORTD = 0x00;
  goto Restart;
}

NXT:
Code:
#pragma config(Sensor, S1,     IO,             sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   DigitalPinDirection[IO] = 0x03;
   Restart:
   DigitalPinValue[IO] = 0x01;
   DigitalPinValue[IO] = 0x00;
   goto Restart;
}

Author:  roboRed [ Mon Jun 03, 2013 8:41 pm ]
Post subject:  Re: Instructions per cycle....

What's
Code:
goto Restart;

Author:  mattallen37 [ Mon Jun 03, 2013 9:28 pm ]
Post subject:  Re: Instructions per cycle....

It means jump to label "Restart".

Author:  roboRed [ Mon Jun 03, 2013 9:30 pm ]
Post subject:  Re: Instructions per cycle....

And restart is..

Sorry, I really don't know :oops:

Author:  mattallen37 [ Mon Jun 03, 2013 9:35 pm ]
Post subject:  Re: Instructions per cycle....

It's just a user created label.

Author:  roboRed [ Mon Jun 03, 2013 9:39 pm ]
Post subject:  Re: Instructions per cycle....

So... In other words, a user defined function?

Author:  mattallen37 [ Mon Jun 03, 2013 9:42 pm ]
Post subject:  Re: Instructions per cycle....

No. Just a user defined label.

A label is a place the program can jump to.

Author:  Ernest3.14 [ Mon Jun 03, 2013 9:47 pm ]
Post subject:  Re: Instructions per cycle....

Gotos are evil... Why no use while loop?! (I don't think there's a speed difference.)

Author:  mattallen37 [ Mon Jun 03, 2013 9:52 pm ]
Post subject:  Re: Instructions per cycle....

There is a speed difference, and that's why.

A while statement checks the value, and if true runs the code, and at the end, it jumps back to check the value again. If the value is false, it jumps to the end of the while block.

goto jumps directly to the label without needing to check the value of "true".

Author:  Ernest3.14 [ Mon Jun 03, 2013 10:05 pm ]
Post subject:  Re: Instructions per cycle....

Ah. Does the RobotC optimizer take this into account, if you have a "while(true)" infinite loop? Or are compilers not smart enough yet :)

Author:  mattallen37 [ Mon Jun 03, 2013 10:16 pm ]
Post subject:  Re: Instructions per cycle....

I'm not sure about the ROBOTC compiler, but I know that some compilers do not.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/