Last active
December 12, 2015 22:17
-
-
Save smcl/2b7f123958f8f0546d8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/pgmspace.h> | |
#include <EEPROM.h> | |
#define BUFFER_LEN 256 | |
char sram_buffer[] = { | |
170, 160, 146, 188, 90, 202, 109, 76, 120, 184, 232, 184, 109, 156, 246, 179, 19, 75, 56, 48, 91, 209, 200, 135, 191, 40, 119, 141, 202, 241, 223, 195, 115, 21, 79, 228, 99, 148, 66, 202, 146, 157, 71, 23, 190, 170, 173, 92, 191, 246, 187, 66, 94, 186, 2, 78, 135, 49, 211, 43, 187, 57, 56, 47, 197, 128, 49, 250, 230, 183, 77, 196, 185, 252, 46, 157, 225, 177, 23, 215, 167, 51, 233, 237, 108, 164, 185, 111, 180, 123, 126, 227, 239, 225, 191, 209, 236, 103, 196, 255, 0, 55, 99, 146, 15, 184, 198, 223, 116, 61, 88, 48, 10, 227, 39, 82, 179, 197, 61, 246, 147, 77, 95, 208, 245, 241, 118, 247, 139, 224, 134, 7, 48, 165, 15, 128, 157, 173, 96, 236, 182, 234, 84, 153, 21, 237, 38, 246, 198, 7, 216, 17, 43, 182, 228, 118, 195, 1, 13, 223, 243, 248, 40, 16, 237, 174, 195, 190, 102, 26, 21, 238, 97, 114, 183, 40, 82, 188, 207, 197, 23, 164, 38, 129, 222, 242, 34, 244, 148, 8, 224, 184, 52, 5, 66, 134, 100, 143, 204, 213, 22, 219, 193, 103, 210, 249, 81, 41, 206, 130, 46, 190, 238, 105, 142, 9, 197, 30, 142, 172, 133, 193, 104, 101, 255, 63, 240, 147, 177, 237, 48, 117, 149, 152, 126, 78, 125, 40, 63, 52, 2, 255, 64, 80, 32, 94, 98, 114, 202, 51, 112, 72, 95, 209, 79, 44 | |
}; | |
const char progmem_buffer[] PROGMEM = { | |
170, 160, 146, 188, 90, 202, 109, 76, 120, 184, 232, 184, 109, 156, 246, 179, 19, 75, 56, 48, 91, 209, 200, 135, 191, 40, 119, 141, 202, 241, 223, 195, 115, 21, 79, 228, 99, 148, 66, 202, 146, 157, 71, 23, 190, 170, 173, 92, 191, 246, 187, 66, 94, 186, 2, 78, 135, 49, 211, 43, 187, 57, 56, 47, 197, 128, 49, 250, 230, 183, 77, 196, 185, 252, 46, 157, 225, 177, 23, 215, 167, 51, 233, 237, 108, 164, 185, 111, 180, 123, 126, 227, 239, 225, 191, 209, 236, 103, 196, 255, 0, 55, 99, 146, 15, 184, 198, 223, 116, 61, 88, 48, 10, 227, 39, 82, 179, 197, 61, 246, 147, 77, 95, 208, 245, 241, 118, 247, 139, 224, 134, 7, 48, 165, 15, 128, 157, 173, 96, 236, 182, 234, 84, 153, 21, 237, 38, 246, 198, 7, 216, 17, 43, 182, 228, 118, 195, 1, 13, 223, 243, 248, 40, 16, 237, 174, 195, 190, 102, 26, 21, 238, 97, 114, 183, 40, 82, 188, 207, 197, 23, 164, 38, 129, 222, 242, 34, 244, 148, 8, 224, 184, 52, 5, 66, 134, 100, 143, 204, 213, 22, 219, 193, 103, 210, 249, 81, 41, 206, 130, 46, 190, 238, 105, 142, 9, 197, 30, 142, 172, 133, 193, 104, 101, 255, 63, 240, 147, 177, 237, 48, 117, 149, 152, 126, 78, 125, 40, 63, 52, 2, 255, 64, 80, 32, 94, 98, 114, 202, 51, 112, 72, 95, 209, 79, 44 | |
}; | |
unsigned int benchmark_sram() { | |
unsigned int checksum = 0; | |
for (int i = 0; i < BUFFER_LEN; i++) { | |
checksum += (unsigned char)sram_buffer[i]; | |
} | |
return checksum; | |
} | |
unsigned int benchmark_progmem() { | |
unsigned int checksum = 0; | |
for (int i = 0; i < BUFFER_LEN; i++) { | |
checksum += (unsigned char)pgm_read_byte_near(progmem_buffer + i); | |
} | |
return checksum; | |
} | |
// not sure what is currently in eeprom, and arduino flash strips this section | |
// from binary, so need to initialise this manually ... once | |
void setup_eeprom() { | |
for (int i = 0; i < BUFFER_LEN; i++) { | |
EEPROM.write(i, sram_buffer[i]); | |
} | |
} | |
unsigned int benchmark_eeprom() { | |
unsigned int checksum = 0; | |
for (int i = 0; i < BUFFER_LEN; i++) { | |
checksum += (unsigned char)EEPROM.read(i); | |
} | |
return checksum; | |
} | |
void setup() { | |
Serial.begin(9600); | |
unsigned long sram_start = micros(); | |
int sram_csum = benchmark_sram(); | |
unsigned long sram_end = micros(); | |
unsigned long progmem_start = micros(); | |
int progmem_csum = benchmark_progmem(); | |
unsigned long progmem_end = micros(); | |
setup_eeprom(); | |
unsigned long eeprom_start = micros(); | |
int eeprom_csum = benchmark_eeprom(); | |
unsigned long eeprom_end = micros(); | |
// dump sram stats | |
Serial.println("sram:"); | |
Serial.print("- checksum:"); | |
Serial.println(sram_csum, HEX); | |
Serial.print("- time:"); | |
Serial.println(sram_end - sram_start); | |
// dump progmem stats | |
Serial.println("progmem:"); | |
Serial.print("- checksum:"); | |
Serial.println(progmem_csum, HEX); | |
Serial.print("- time:"); | |
Serial.println(progmem_end - progmem_start); | |
// dump eeprom stats | |
Serial.println("eeprom:"); | |
Serial.print("- checksum:"); | |
Serial.println(eeprom_csum, HEX); | |
Serial.print("- time:"); | |
Serial.println(eeprom_end - eeprom_start); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment