Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <EEPROM.h>
#define BUFFER_LEN 256
char sram_buffer[BUFFER_LEN];
// benchmark sram
void benchmark_sram() {
for (int i = 0; i < BUFFER_LEN; i++) {
sram_buffer[i] = (unsigned char)i;
}
}
// can't write to progmem, so no benchmark required there
// eeprom
void benchmark_eeprom() {
for (int i = 0; i < BUFFER_LEN; i++) {
EEPROM.write(i, (unsigned char)i);
}
}
void setup() {
Serial.begin(9600);
Serial.println("benchmarking sram...");
unsigned long sram_start = micros();
benchmark_sram();
unsigned long sram_end = micros();
Serial.println("finished benchmarking sram");
Serial.println("benchmarking eeprom...");
unsigned long eeprom_start = micros();
benchmark_eeprom();
unsigned long eeprom_end = micros();
Serial.println("finished benchmarking eeprom");
// dump sram stats
Serial.println("sram:");
Serial.print("- time:");
Serial.println(sram_end - sram_start);
// can't write to progmem, so no benchmark required there
Serial.println("progmem:");
Serial.print("- time:");
Serial.println("n/a");
// dump eeprom stats
Serial.println("eeprom:");
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