EEPROM read and write speeds

Status
Not open for further replies.

virtualdave

Well-known member
Hi all,

Just want to make sure these numbers looked right. I'm testing read and write speeds to the EEPROM of the Teensy 3 and here are the numbers I'm seeing:

reading 100 byte array ~= 93 microseconds
writing 100 byte array ~= 118 microseconds
reading 2 bytes, doing some quick processing (adding the two bytes, incrementing, splitting the sum back into 2 bytes and writing back to EEPROM ~= 345 microseconds.

This was mainly a test to see if this action would get in the way of other processes happening on the micro (that last time test is what I am most interested in). Do these numbers seem reasonable?

The sketch I used is below.

Thanks,
David

Code:
// +++++++++++++++++++++ libraries +++++++++++++++++++++ //
#include <EEPROM.h>

// +++++++++++++++++++++ general variables +++++++++++++++++++++ //
int statusLED = 13;

// +++++++++++++++++++++ timers +++++++++++++++++++++ //
elapsedMicros processingTimer;

unsigned long readTime;
unsigned long writeTime;
unsigned long readWriteTime;

const int arraySize = 100;

unsigned long readWriteNumber = 0;

byte data[arraySize];

byte serialIn;


void setup()
{
  Serial.begin(921600); // USB
  
  pinMode(statusLED, OUTPUT); // declare pin as output

  // flashy flashy
  for (int i=0; i <= 25; i++){ // blink LED so we know its alive
    digitalWrite(statusLED, HIGH);
    delay(20);
    digitalWrite(statusLED, LOW);
    delay(20);
  } 
  
  resetEEPROM();
  createDataSet();
  delay(1000);
}

void loop() {

  // +++++++++++++++++++++ check USB for messages +++++++++++++++++++++ //
  while (Serial.available() > 0) { // mail call from CPU
    serialIn = Serial.read();
    if (serialIn == 114) { // 'r'
      resetEEPROM();
      Serial.print("zeroing EEPROM");
      Serial.write(10);
      delay(1000);
    }
  } // end USB check
  
  
  // +++++++++++++++++++++ EEPROM read test +++++++++++++++++++++ //
  processingTimer = 0;
  readEEPROM();
  readTime = processingTimer;
  delay(100);
  
  // +++++++++++++++++++++ EEPROM write test +++++++++++++++++++++ //
  processingTimer = 0;
  writeEEPROM();
  writeTime = processingTimer;
  delay(100);  
  
  // +++++++++++++++++++++ EEPROM read/write test +++++++++++++++++++++ //
  processingTimer = 0;
  readWriteEEPROM();
  readWriteTime = processingTimer;
  delay(100);
  
  // +++++++++++++++++++++ report times +++++++++++++++++++++ //
  Serial.print("read time = ");
  Serial.print(readTime);
  Serial.write(32);
  Serial.print("write time = ");
  Serial.print(writeTime);
  Serial.write(32);
  Serial.print("read&write time = ");
  Serial.print(readWriteTime);
  Serial.write(32);
  Serial.print("read&write number = ");
  Serial.print(readWriteNumber);
  
  /* // for debugging
  Serial.write(32);
  for (int i = 0; i < arraySize; i++) {
    Serial.print(data[i]);
    Serial.write(32);
    Serial.print(EEPROM.read(i));
    Serial.write(32);
  }
  */
  
  Serial.write(10);
  
  delay(1000);
     
} // end main loop()

void createDataSet() {
  for (int i = 0; i < arraySize; i++) {
    data[i] = random(0, 256);
    EEPROM.write(i, data[i]);
  }
} // end createDataSet()

void readEEPROM() 
{
  for (int i = 0; i < arraySize; i++) {
    data[i] = EEPROM.read(i);
  }
} // end read EEPROM

void writeEEPROM()
{
  for (int i = 0; i < arraySize; i++) {
    EEPROM.write(i, data[i]);
  }
} // end write EEPROM

void readWriteEEPROM() 
{
  readWriteNumber = (EEPROM.read(14) << 8) + EEPROM.read(15);
  readWriteNumber++;
  if (readWriteNumber > 65535) readWriteNumber = 0;
  EEPROM.write(14, (readWriteNumber >> 8 & 255));
  EEPROM.write(15, (readWriteNumber & 255));
} // end readWrite EEPROM

void resetEEPROM()
{
  for (int i = 0; i < 2048; i++) {
    EEPROM.write(i, 255); // note 255 = default values
  }
} // end reset EEPROM
 
Last edited:
They look reasonable.

Actually, I'm a bit surprised the write is that fast and the read is that slow. I suspect both may be dominated by software overhead, rather than the actual memory speed.
 
Status
Not open for further replies.
Back
Top