13
13
// How large of a file to test
14
14
#define TESTSIZEKB 256
15
15
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
+
16
35
void DoTest (FS *fs) {
17
36
if (!fs->format ()) {
18
37
Serial.printf (" Unable to format(), aborting\n " );
@@ -29,7 +48,7 @@ void DoTest(FS *fs) {
29
48
}
30
49
31
50
Serial.printf (" Creating %dKB file, may take a while...\n " , TESTSIZEKB);
32
- long start = millis ();
51
+ unsigned long start = millis ();
33
52
File f = fs->open (" /testwrite.bin" , " w" );
34
53
if (!f) {
35
54
Serial.printf (" Unable to open file for writing, aborting\n " );
@@ -41,11 +60,11 @@ void DoTest(FS *fs) {
41
60
}
42
61
}
43
62
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);
46
65
47
66
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 ());
49
68
f.close ();
50
69
51
70
Serial.printf (" Reading %dKB file sequentially in 256b chunks\n " , TESTSIZEKB);
@@ -58,7 +77,7 @@ void DoTest(FS *fs) {
58
77
}
59
78
f.close ();
60
79
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 ) );
62
81
63
82
Serial.printf (" Reading %dKB file MISALIGNED in flash and RAM sequentially in 256b chunks\n " , TESTSIZEKB);
64
83
start = millis ();
@@ -71,8 +90,7 @@ void DoTest(FS *fs) {
71
90
}
72
91
f.close ();
73
92
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 ));
76
94
77
95
Serial.printf (" Reading %dKB file in reverse by 256b chunks\n " , TESTSIZEKB);
78
96
start = millis ();
@@ -91,8 +109,7 @@ void DoTest(FS *fs) {
91
109
}
92
110
f.close ();
93
111
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 ));
96
113
97
114
Serial.printf (" Writing 64K file in 1-byte chunks\n " );
98
115
start = millis ();
@@ -102,7 +119,7 @@ void DoTest(FS *fs) {
102
119
}
103
120
f.close ();
104
121
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 ) );
106
123
107
124
Serial.printf (" Reading 64K file in 1-byte chunks\n " );
108
125
start = millis ();
@@ -113,9 +130,7 @@ void DoTest(FS *fs) {
113
130
}
114
131
f.close ();
115
132
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 ));
119
134
}
120
135
121
136
void setup () {
@@ -124,6 +139,7 @@ void setup() {
124
139
Serial.printf (" Beginning test\n " );
125
140
Serial.flush ();
126
141
DoTest (&TESTFS);
142
+ Serial.println (" done" );
127
143
}
128
144
129
145
void loop () {
0 commit comments