Unverified Commit 2c97bffc authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Update to latest upstream LittleFS (#425)

Also clean up output in SpeedTest, make more human friendly
parent 626b62c4
......@@ -13,6 +13,25 @@
// How large of a file to test
#define TESTSIZEKB 256
// Format speed in bytes/second. Static buffer so not re-entrant safe
const char *rate(unsigned long start, unsigned long stop, unsigned long bytes) {
static char buff[64];
if (stop == start) {
strcpy_P(buff, PSTR("Inf b/s"));
} else {
unsigned long delta = stop - start;
float r = 1000.0 * (float)bytes / (float)delta;
if (r >= 1000000.0) {
sprintf_P(buff, PSTR("%0.2f MB/s"), r / 1000000.0);
} else if (r >= 1000.0) {
sprintf_P(buff, PSTR("%0.2f KB/s"), r / 1000.0);
} else {
sprintf_P(buff, PSTR("%d bytes/s"), (int)r);
}
}
return buff;
}
void DoTest(FS *fs) {
if (!fs->format()) {
Serial.printf("Unable to format(), aborting\n");
......@@ -29,7 +48,7 @@ void DoTest(FS *fs) {
}
Serial.printf("Creating %dKB file, may take a while...\n", TESTSIZEKB);
long start = millis();
unsigned long start = millis();
File f = fs->open("/testwrite.bin", "w");
if (!f) {
Serial.printf("Unable to open file for writing, aborting\n");
......@@ -41,11 +60,11 @@ void DoTest(FS *fs) {
}
}
f.close();
long stop = millis();
Serial.printf("==> Time to write %dKB in 256b chunks = %ld milliseconds\n", TESTSIZEKB, stop - start);
unsigned long stop = millis();
Serial.printf("==> Time to write %dKB in 256b chunks = %lu milliseconds\n", TESTSIZEKB, stop - start);
f = fs->open("/testwrite.bin", "r");
Serial.printf("==> Created file size = %d\n", f.size());
Serial.printf("==> Created file size = %zu\n", f.size());
f.close();
Serial.printf("Reading %dKB file sequentially in 256b chunks\n", TESTSIZEKB);
......@@ -58,7 +77,7 @@ void DoTest(FS *fs) {
}
f.close();
stop = millis();
Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %ld milliseconds = %ld bytes/s\n", TESTSIZEKB, stop - start, TESTSIZEKB * 1024 / (stop - start) * 1000);
Serial.printf("==> Time to read %dKB sequentially in 256b chunks = %lu milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));
Serial.printf("Reading %dKB file MISALIGNED in flash and RAM sequentially in 256b chunks\n", TESTSIZEKB);
start = millis();
......@@ -71,8 +90,7 @@ void DoTest(FS *fs) {
}
f.close();
stop = millis();
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);
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));
Serial.printf("Reading %dKB file in reverse by 256b chunks\n", TESTSIZEKB);
start = millis();
......@@ -91,8 +109,7 @@ void DoTest(FS *fs) {
}
f.close();
stop = millis();
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);
Serial.printf("==> Time to read %dKB in reverse in 256b chunks = %lu milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));
Serial.printf("Writing 64K file in 1-byte chunks\n");
start = millis();
......@@ -102,7 +119,7 @@ void DoTest(FS *fs) {
}
f.close();
stop = millis();
Serial.printf("==> Time to write 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000);
Serial.printf("==> Time to write 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));
Serial.printf("Reading 64K file in 1-byte chunks\n");
start = millis();
......@@ -113,9 +130,7 @@ void DoTest(FS *fs) {
}
f.close();
stop = millis();
Serial.printf("==> Time to read 64KB in 1b chunks = %ld milliseconds = %ld bytes/s\n", stop - start, 65536 / (stop - start) * 1000);
Serial.printf("==> Time to read 64KB in 1b chunks = %lu milliseconds = %s\n", stop - start, rate(start, stop, 65536));
}
void setup() {
......@@ -124,6 +139,7 @@ void setup() {
Serial.printf("Beginning test\n");
Serial.flush();
DoTest(&TESTFS);
Serial.println("done");
}
void loop() {
......
Subproject commit 1863dc7883d82bd6ca79faa164b65341064d1c16
Subproject commit ead50807f1ca3fdf2da00b77a0ce02651ded2d13
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment