Skip to content

Instantly share code, notes, and snippets.

@smcl
Created December 12, 2015 22:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smcl/8a2b9630db5b94df2e31 to your computer and use it in GitHub Desktop.
Save smcl/8a2b9630db5b94df2e31 to your computer and use it in GitHub Desktop.
#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