code size

stimmer:
Just to add to the confusion, here's blink with an unrolled loop - 2000*digitalWrite and delay.

/*

Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

#define do10(x) x x x x x x x x x x
#define do50(x) do10(x) do10(x) do10(x) do10(x) do10(x)
#define do250(x) do50(x) do50(x) do50(x) do50(x) do50(x)
#define do1000(x) do250(x) do250(x) do250(x) do250(x)

// the loop routine runs over and over again forever:
void loop() {
do1000(
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
)
}





code size         mega    due
normal blink      1662    9740
unrolled blink    44866   41716




Due beats Mega by 3k :D

This bears out my general experience with the Due - the larger code sizes are because it has a more comprehensive runtime. Ignoring the overhead, code for code the Due seems to be slightly better than the Mega.

I reworked some of my bulkier code and compiled for both Due / Mega. As everybody has acknowledged, there is more overhead, but there is also a lot more performance.

#pragma message: Compiling for Arduino Due (AT91SAM3X8E)...
Binary sketch size: 62,216 bytes (of a 524,288 byte maximum)

For the Mega - compiles to:
Binary sketch size: 45,634 bytes (of a 258,048 byte maximum)

Nothing as bad as the apparent initial 6:1 sort of increase. Relax I think. :slight_smile:

I think Due will be pretty good to use, well, after I re-jig the Analog input levels and assorted 5V TTL logic level changers etc.

Graeme