Skip to content

Commit a8d61c1

Browse files
committed
Improved benchmarks
1 parent 7328920 commit a8d61c1

File tree

7 files changed

+233
-43
lines changed

7 files changed

+233
-43
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The Storage library for Arduino is designed to abstract handling of
44
external memory, and allow block read/write and streaming of data. The
5-
library includes device drivers for SPI SRAM (23LC1024), 2-Wire EEPROM
6-
(AT24CXX) and internal EEPROM.
5+
library includes device drivers for SPI SRAM (23LC512/1024), 2-Wire
6+
EEPROM (AT24CXX) and internal EEPROM.
77

88
Version: 1.0
99

@@ -16,27 +16,29 @@ Version: 1.0
1616
## Drivers
1717

1818
* [2-Wire EEPROM, AT24CXX](./src/Driver/AT24CXX.h)
19+
* [512 Kbit Serial SRAM, 23LC512](./src/Driver/MC23LC512.h)
1920
* [1 Mbit Serial SRAM, 23LC1024](./src/Driver/MC23LC1024.h)
2021
* [Internal EEPROM, EEPROM](./src/Driver/EEPROM.h)
2122

2223
## Example Sketches
2324

24-
* [Benchmarks](./examples/Benchmarks) measurements of characteristics.
25+
* [Benchmarks](./examples/Benchmarks) measurement of characteristics.
2526
* [Block](./examples/Block) read/write eeprom blocks.
2627
* [Persistent](./examples/Persistent) read/write configuration.
2728
* [Stream](./examples/Stream) storage as a print stream.
2829
* [Vector](./examples/Vector) handling large sample vectors.
2930

3031
## Benchmarks
3132

32-
### AT24C32, 2-Wire EEPROM
33+
### AT24C32, 2-Wire EEPROM, 100 KHz
3334
#### Read
3435
N | us | us/byte | kbyte/s
3536
--|----|---------|--------
3637
1 | 528 | 528.00 | 1.89
3738
10 | 1352 | 135.20 | 7.40
3839
100 | 9680 | 96.80 | 10.33
3940
1000 | 93128 | 93.13 | 10.74
41+
4042
#### Write
4143
N | us | us/byte | kbyte/s
4244
--|----|---------|--------
@@ -46,19 +48,21 @@ N | us | us/byte | kbyte/s
4648
1000 | 206280 | 206.28 | 4.85
4749

4850
Note: 1) The read/write operations have a three byte header (8-bit
49-
command, and 16-bit address), 2) Write performance increases up to
51+
command, and 16-bit address). 2) Write performance increases up to
5052
page size. When the block size is larger than the page size the write
5153
operation will wait for the device to complete the page write. Typical
52-
max 10 ms per page.
54+
max 5-10 ms per page. 3) 400 KHz (and even 800 KHz) clock can be
55+
used.
5356

54-
### 23LC1024, SPI SRAM
57+
### 23LC1024, SPI SRAM, 8 MHz
5558
#### Read
5659
N | us | us/byte | kbyte/s
5760
--|----|---------|--------
5861
1 | 24 | 24.00 | 41.67
59-
10 | 40 | 4.00 | 250.00
60-
100 | 172 | 1.72 | 581.40
61-
1000 | 1532 | 1.53 | 652.74
62+
10 | 36 | 3.60 | 277.78
63+
100 | 156 | 1.56 | 641.03
64+
1000 | 1344 | 1.34 | 744.05
65+
6266
#### Write
6367
N | us | us/byte | kbyte/s
6468
--|----|---------|--------

examples/Benchmarks/AT24CXX/AT24CXX.ino

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/*
2-
* eeprom.SIZE = 4096
3-
*
1+
/* Results:
2+
* ----------------------------------------
3+
* twi@100kHz
4+
* ----------------------------------------
45
* write(N, us, us/byte, kbyte/s)
56
* 1, 408, 408.00, 2.45
67
* 10, 1236, 123.60, 8.09
@@ -12,12 +13,43 @@
1213
* 10, 1352, 135.20, 7.40
1314
* 100, 9680, 96.80, 10.33
1415
* 1000, 93128, 93.13, 10.74
16+
*
17+
* ----------------------------------------
18+
* twi@400kHz
19+
* ----------------------------------------
20+
* write(N, us, us/byte, kbyte/s)
21+
* 1, 132, 132.00, 7.58
22+
* 10, 352, 35.20, 28.41
23+
* 100, 12288, 122.88, 8.14
24+
* 1000, 125164, 125.16, 7.99
25+
*
26+
* read(N, us, us/byte, kbyte/s)
27+
* 1, 168, 168.00, 5.95
28+
* 10, 392, 39.20, 25.51
29+
* 100, 2640, 26.40, 37.88
30+
* 1000, 25152, 25.15, 39.76
31+
*
32+
* ----------------------------------------
33+
* twi@800kHz
34+
* ----------------------------------------
35+
* write(N, us, us/byte, kbyte/s)
36+
* 1, 88, 88.00, 11.36
37+
* 10, 204, 20.40, 49.02
38+
* 100, 10916, 109.16, 9.16
39+
* 1000, 112656, 112.66, 8.88
40+
*
41+
* read(N, us, us/byte, kbyte/s)
42+
* 1, 104, 104.00, 9.62
43+
* 10, 228, 22.80, 43.86
44+
* 100, 1468, 14.68, 68.12
45+
* 1000, 13916, 13.92, 71.86
1546
*/
1647

1748
#include "Storage.h"
1849
#include "TWI.h"
1950
#include "Driver/AT24CXX.h"
2051

52+
// Configure: TWI bus manager variant
2153
// #define USE_SOFTWARE_TWI
2254
#define USE_HARDWARE_TWI
2355

@@ -27,15 +59,24 @@
2759
Software::TWI<BOARD::D6, BOARD::D7> twi;
2860
#elif defined(USE_HARDWARE_TWI)
2961
#include "Hardware/TWI.h"
30-
Hardware::TWI twi;
62+
// Configure: Hardware TWI bus clock frequency
63+
//
64+
#define FREQ 800000UL
65+
// #define FREQ 400000UL
66+
// #define FREQ 100000UL
67+
Hardware::TWI twi(FREQ);
3168
#endif
3269

3370
// EEPROM external storage
3471
AT24C32 eeprom(twi);
3572

3673
// Local memory buffer
3774
const int BUF_MAX = 1000;
38-
static uint8_t buf[BUF_MAX];
75+
uint8_t buf[BUF_MAX];
76+
77+
// Buffer sizes
78+
const int N_MAX = 6;
79+
const int N[N_MAX] = { 1, 10, eeprom.PAGE_MAX, eeprom.PAGE_MAX*2, 100, 1000 };
3980

4081
void setup()
4182
{
@@ -46,19 +87,28 @@ void setup()
4687
void loop()
4788
{
4889
static uint8_t n = 0;
90+
uint32_t start;
91+
uint32_t us;
92+
float uspb;
93+
4994
for (int i = 0; i < BUF_MAX; i++) buf[i] = n + i;
5095

51-
Serial.print(F("eeprom.SIZE = "));
52-
Serial.println(eeprom.SIZE);
5396
Serial.println();
97+
Serial.print(F("twi.FREQ(kHz) = "));
98+
Serial.println(FREQ / 1000);
99+
Serial.print(F("eeprom.SIZE(kbyte) = "));
100+
Serial.println(eeprom.SIZE / 1024);
101+
Serial.println();
102+
103+
// Benchmark#1: Measure write with increasing buffer size
54104
Serial.println(F("write(N, us, us/byte, kbyte/s)"));
55105
Serial.flush();
56-
for (int i = 1; i < 10000; i *= 10) {
57-
uint32_t start = micros();
58-
eeprom.write(0x0000, buf, i);
59-
uint32_t us = micros() - start;
60-
float uspb = ((float) us) / i;
61-
Serial.print(i);
106+
for (int i = 0; i < N_MAX; i++) {
107+
start = micros();
108+
eeprom.write(0x0000, buf, N[i]);
109+
us = micros() - start;
110+
uspb = ((float) us) / N[i];
111+
Serial.print(N[i]);
62112
Serial.print(F(", "));
63113
Serial.print(us);
64114
Serial.print(F(", "));
@@ -71,14 +121,15 @@ void loop()
71121

72122
for (int i = 0; i < BUF_MAX; i++) buf[i] = 0;
73123

124+
// Benchmark#2: Measure read with increasing buffer size
74125
Serial.println(F("read(N, us, us/byte, kbyte/s)"));
75126
Serial.flush();
76-
for (int i = 1; i < 10000; i *= 10) {
77-
uint32_t start = micros();
78-
eeprom.read(buf, 0x0000, i);
79-
uint32_t us = micros() - start;
80-
float uspb = ((float) us) / i;
81-
Serial.print(i);
127+
for (int i = 0; i < N_MAX; i++) {
128+
start = micros();
129+
eeprom.read(buf, 0x0000, N[i]);
130+
us = micros() - start;
131+
uspb = ((float) us) / N[i];
132+
Serial.print(N[i]);
82133
Serial.print(F(", "));
83134
Serial.print(us);
84135
Serial.print(F(", "));
@@ -87,7 +138,6 @@ void loop()
87138
Serial.println(1000 / uspb);
88139
Serial.flush();
89140
}
90-
Serial.println();
91141

92142
for (int i = 0; i < BUF_MAX; i++) {
93143
if (buf[i] != ((n + i) & 0xff)) {

examples/Benchmarks/EEPROM/EEPROM.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void loop()
3838
Serial.print(F("eeprom.SIZE: "));
3939
Serial.println(eeprom.SIZE);
4040
Serial.println();
41+
42+
// Benchmark#1: Measure write with increasing buffer size
4143
Serial.println(F("write(N, us, us/byte, kbyte/s)"));
4244
Serial.flush();
4345
for (int i = 1; i < 10000; i *= 10) {
@@ -58,6 +60,7 @@ void loop()
5860

5961
for (int i = 0; i < BUF_MAX; i++) buf[i] = 0;
6062

63+
// Benchmark#2: Measure read with increasing buffer size
6164
Serial.println(F("read(N, us, us/byte, kbyte/s)"));
6265
Serial.flush();
6366
for (int i = 1; i < 10000; i *= 10) {

examples/Benchmarks/MC23LC1024/MC23LC1024.ino

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/*
2-
* sram.SIZE = 131072
2+
* spi.FREQ(MHz) = 8
3+
* sram.SIZE(kbyte) = 128
34
*
45
* write(N, us, us/byte, kbyte/s)
56
* 1, 24, 24.00, 41.67
6-
* 10, 36, 3.60, 277.78
7+
* 10, 40, 4.00, 250.00
78
* 100, 172, 1.72, 581.40
89
* 1000, 1468, 1.47, 681.20
910
*
1011
* read(N, us, us/byte, kbyte/s)
1112
* 1, 24, 24.00, 41.67
12-
* 10, 40, 4.00, 250.00
13-
* 100, 172, 1.72, 581.40
14-
* 1000, 1532, 1.53, 652.74
13+
* 10, 36, 3.60, 277.78
14+
* 100, 156, 1.56, 641.03
15+
* 1000, 1344, 1.34, 744.05
1516
*/
1617

1718
#include "Storage.h"
@@ -52,9 +53,13 @@ void loop()
5253
static uint8_t n = 0;
5354
for (int i = 0; i < BUF_MAX; i++) buf[i] = n + i;
5455

55-
Serial.print(F("sram.SIZE = "));
56-
Serial.println(sram.SIZE);
5756
Serial.println();
57+
Serial.println(F("spi.FREQ(MHz) = 8"));
58+
Serial.print(F("sram.SIZE(kbyte) = "));
59+
Serial.println(sram.SIZE / 1024);
60+
Serial.println();
61+
62+
// Benchmark#1: Measure write with increasing buffer size
5863
Serial.println(F("write(N, us, us/byte, kbyte/s)"));
5964
Serial.flush();
6065
for (int i = 1; i < 10000; i *= 10) {
@@ -75,6 +80,7 @@ void loop()
7580

7681
for (int i = 0; i < BUF_MAX; i++) buf[i] = 0;
7782

83+
// Benchmark#2: Measure read with increasing buffer size
7884
Serial.println(F("read(N, us, us/byte, kbyte/s)"));
7985
Serial.flush();
8086
for (int i = 1; i < 10000; i *= 10) {
@@ -91,7 +97,6 @@ void loop()
9197
Serial.println(1000 / uspb);
9298
Serial.flush();
9399
}
94-
Serial.println();
95100

96101
for (int i = 0; i < BUF_MAX; i++) {
97102
if (buf[i] != ((n + i) & 0xff)) {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version=1.0
33
author=Mikael Patel
44
maintainer=Mikael Patel <[email protected]>
55
sentence=External Memory Storage library for Arduino.
6-
paragraph=This library is designed to abstract handling of external memory and allow block read/write and streaming of data. The library includes device drivers for SPI SRAM (23LC1024), 2-Wire EEPROM (AT24CXX) and internal EEPROM.
6+
paragraph=This library is designed to abstract handling of external memory and allow block read/write and streaming of data. The library includes device drivers for SPI SRAM (23LC512/23LC1024), 2-Wire EEPROM (AT24CXX) and internal EEPROM.
77
category=Data Storage
88
url=https://github.com/mikaelpatel/Arduino-Storage
99
architectures=avr

mainpage.dox

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** @mainpage Arduino-Storage
22

33
The Storage library for Arduino is designed to abstract handling of
4-
external memory, and allow block read/write (Storage::Block) and
5-
streaming of data (Storage::Stream). The library includes device
6-
drivers for SPI SRAM (MC23LC1024), 2-Wire EEPROM (AT24CXX) and
7-
internal EEPROM.
4+
external memory. It allows block and vector read/write
5+
(Storage::Block) and streaming of data (Storage::Stream). The library
6+
includes device drivers for SPI SRAM (MC23LC1024, MC23LC512), 2-Wire
7+
EEPROM (AT24CXX) and internal EEPROM.
88

99
Version: 1.0
1010
*/

0 commit comments

Comments
 (0)