Skip to content

Commit 2c97bff

Browse files
Update to latest upstream LittleFS (#425)
Also clean up output in SpeedTest, make more human friendly
1 parent 626b62c commit 2c97bff

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

libraries/LittleFS/examples/SpeedTest/SpeedTest.ino

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
// How large of a file to test
1414
#define TESTSIZEKB 256
1515

16+
// Format speed in bytes/second. Static buffer so not re-entrant safe
17+
const char *rate(unsigned long start, unsigned long stop, unsigned long bytes) {
18+
static char buff[64];
19+
if (stop == start) {
20+
strcpy_P(buff, PSTR("Inf b/s"));
21+
} else {
22+
unsigned long delta = stop - start;
23+
float r = 1000.0 * (float)bytes / (float)delta;
24+
if (r >= 1000000.0) {
25+
sprintf_P(buff, PSTR("%0.2f MB/s"), r / 1000000.0);
26+
} else if (r >= 1000.0) {
27+
sprintf_P(buff, PSTR("%0.2f KB/s"), r / 1000.0);
28+
} else {
29+
sprintf_P(buff, PSTR("%d bytes/s"), (int)r);
30+
}
31+
}
32+
return buff;
33+
}
34+
1635
void DoTest(FS *fs) {
1736
if (!fs->format()) {
1837
Serial.printf("Unable to format(), aborting\n");
@@ -29,7 +48,7 @@ void DoTest(FS *fs) {
2948
}
3049

3150
Serial.printf("Creating %dKB file, may take a while...\n", TESTSIZEKB);
32-
long start = millis();
51+
unsigned long start = millis();
3352
File f = fs->open("/testwrite.bin", "w");
3453
if (!f) {
3554
Serial.printf("Unable to open file for writing, aborting\n");
@@ -41,11 +60,11 @@ void DoTest(FS *fs) {
4160
}
4261
}
4362
f.close();
44-
long stop = millis();
45-
Serial.printf("==> Time to write %dKB in 256b chunks = %ld milliseconds\n", TESTSIZEKB, stop - start);
63+
unsigned long stop = millis();
64+
Serial.printf("==> Time to write %dKB in 256b chunks = %lu milliseconds\n", TESTSIZEKB, stop - start);
4665

4766
f = fs->open("/testwrite.bin", "r");
48-
Serial.printf("==> Created file size = %d\n", f.size());
67+
Serial.printf("==> Created file size = %zu\n", f.size());
4968
f.close();
5069

5170
Serial.printf("Reading %dKB file sequentially in 256b chunks\n", TESTSIZEKB);
@@ -58,7 +77,7 @@ void DoTest(FS *fs) {
5877
}
5978
f.close();
6079
stop = millis();
61-
Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000);
80+
Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %lu milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));
6281

6382
Serial.printf("Reading %dKB file MISALIGNED in flash and RAM sequentially in 256b chunks\n", TESTSIZEKB);
6483
start = millis();
@@ -71,8 +90,7 @@ void DoTest(FS *fs) {
7190
}
7291
f.close();
7392
stop = millis();
74-
Serial.printf("==> Time to read %dKB sequentially MISALIGNED in flash and RAM in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000);
75-
93+
Serial.printf("==> Time to read %dKB sequentially MISALIGNED in flash and RAM in 256b chunks = %lu milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));
7694

7795
Serial.printf("Reading %dKB file in reverse by 256b chunks\n", TESTSIZEKB);
7896
start = millis();
@@ -91,8 +109,7 @@ void DoTest(FS *fs) {
91109
}
92110
f.close();
93111
stop = millis();
94-
Serial.printf("==> Time to read %dKB in reverse in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000);
95-
112+
Serial.printf("==> Time to read %dKB in reverse in 256b chunks = %lu milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));
96113

97114
Serial.printf("Writing 64K file in 1-byte chunks\n");
98115
start = millis();
@@ -102,7 +119,7 @@ void DoTest(FS *fs) {
102119
}
103120
f.close();
104121
stop = millis();
105-
Serial.printf("==> Time to write 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000);
122+
Serial.printf("==> Time to write 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));
106123

107124
Serial.printf("Reading 64K file in 1-byte chunks\n");
108125
start = millis();
@@ -113,9 +130,7 @@ void DoTest(FS *fs) {
113130
}
114131
f.close();
115132
stop = millis();
116-
Serial.printf("==> Time to read 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000);
117-
118-
133+
Serial.printf("==> Time to read 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));
119134
}
120135

121136
void setup() {
@@ -124,6 +139,7 @@ void setup() {
124139
Serial.printf("Beginning test\n");
125140
Serial.flush();
126141
DoTest(&TESTFS);
142+
Serial.println("done");
127143
}
128144

129145
void loop() {

libraries/LittleFS/lib/littlefs

0 commit comments

Comments
 (0)