Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up SpeedTest output, avoid div-by-0 #8340

Merged
merged 3 commits into from
Oct 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions libraries/LittleFS/examples/SpeedTest/SpeedTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
// How large of a file to test
#define TESTSIZEKB 512

// Format speed in bytes/second. Static buffer so not re-entrant safe
const char *rate(long start, long stop, long bytes) {
static char buff[64];
if (stop == start) {
strcpy_P(buff, PSTR("Inf b/s"));
} else {
float r = 1000.0 * (float)bytes / (float)(stop - start);
mcspr marked this conversation as resolved.
Show resolved Hide resolved
if (r >= 1000000.0) {
mcspr marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand Down Expand Up @@ -59,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 = %ld 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();
Expand All @@ -72,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 = %ld 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();
Expand All @@ -92,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 = %ld milliseconds = %s\n", TESTSIZEKB, stop - start, rate(start, stop, TESTSIZEKB * 1024));

Serial.printf("Writing 64K file in 1-byte chunks\n");
start = millis();
Expand All @@ -103,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 = %ld milliseconds = %s\n", stop - start, rate(start, stop, 65536));

Serial.printf("Reading 64K file in 1-byte chunks\n");
start = millis();
Expand All @@ -114,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 = %ld milliseconds = %s\n", stop - start, rate(start, stop, 65536));
}

void setup() {
Expand Down