It has been assumed that as EasyC compiles to native code on the cortex, whereas RobotC uses opcodes being interpreted by a virtual machine, there is a significant advantage in terms of execution speed. I know speed tests have been done by others but I though I would run a few tests of my own to see what the advantage was.
Tests were done using RobotC V3.04 and EasyC V4.0.2.7. The tests involved setting a digital output on the cortex to a ‘1’, performing some action (ie. running some code) and then setting the digital output back to ‘0’. The time taken for the code to execute, that is the time the digital output was ‘1’, was measured using an oscilloscope. The code used was simple and translates between the two environments without much change, only the RobotC version will be shown as it’s easier to cut and paste here. The tests start trivial and gradually increase in complexity to finally end with a real world example from current competition code.
The first test was to just look at the time for the digital output alone to toggle.
task main()
{
while(true)
{
SensorValue[dgtl1 ] = 1;
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 3uS
EasyC time 1.5uS
Advantage EasyC (by a factor of 2)
Test 2 is a bit artificial and is the time taken to execute a for loop with 1000 itterations, this type of code is easy to optimize out but can be used as a poor mans delay in some situations.
task main()
{
int x;
while(true)
{
SensorValue[dgtl1 ] = 1;
for(x=0;x<1000;x++)
;
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 5.4mS
EasyC time 200uS
Advantage EasyC (by a factor of 27)
Test 3, now starting to get a bit more meaningful.
Set All 10 motors to a constant value of 0, ie. stop all motors.
task main()
{
int x;
while(true)
{
SensorValue[dgtl1 ] = 1;
for(x=0;x<10;x++)
motor[x] = 0;
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 101uS
EasyC time 35uS
Advantage EasyC (by a factor of 3)
Test4, set all motors to the value of joystick channel 1
task main()
{
int x;
while(true)
{
SensorValue[dgtl1 ] = 1;
for(x=0;x<10;x++)
motor[x] = vexRT[Ch1];
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 124uS
EasyC time 70uS
Advantage EasyC (by a factor of 1.8)
Test 5, send a string to the debug console.
task main()
{
while(true)
{
SensorValue[dgtl1 ] = 1;
writeDebugStreamLine("Hello");
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 12uS
EasyC time 260uS
Advantage RobotC (by a factor of 21)
Test6, create a look up table used for motor control.
/*-----------------------------------------------------------------------------*/
/* */
/* Create a power based lut */
/* */
/*-----------------------------------------------------------------------------*/
// Use a default of 20 if not already defined
#define MOTOR_LUT_FACTOR 20.0
#define MOTOR_LUT_OFFSET 10
// lookup table for non linear control
int MotorLut[128];
void
MakeLut()
{
int i;
float x;
for(i=0;i<128;i++)
{
// check for valid power base
if( MOTOR_LUT_FACTOR > 1 )
{
x = pow( MOTOR_LUT_FACTOR, (float)i / 127.0 );
if(i >= (MOTOR_LUT_OFFSET/2))
MotorLut* = (((x - 1.0) / (MOTOR_LUT_FACTOR - 1.0)) * (127-MOTOR_LUT_OFFSET)) + MOTOR_LUT_OFFSET;
else
MotorLut* = i * 2;
}
else
{
// Linear
MotorLut* = i;
}
}
}
task main()
{
while(true)
{
SensorValue[dgtl1 ] = 1;
MakeLut();
SensorValue[dgtl1 ] = 0;
}
}
RobotC time 14mS
EasyC time 31mS
Advantage RobotC** (by a factor of 2.2)
Make of these whatever you want, benchmarks are one way of looking at compiler speed but not the only way. They do suggest that for simple code execution EasyC is faster, however, as code complexity increases with the inclusion of math functions, RobotC has the advantage.*