/
main.cpp
74 lines (65 loc) · 2.01 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <Arduino.h>
#ifndef SERIAL_TO_TEST
#define SERIAL_TO_TEST Serial
#endif
#ifndef BAUDRATE
#define BAUDRATE 115200
#endif
void setup() { SERIAL_TO_TEST.begin(BAUDRATE); }
void printWithScaleChar(float val) {
if (val >= 1000000) {
SERIAL_TO_TEST.print(val / 1000000);
SERIAL_TO_TEST.print("M");
} else if (val >= 1000) {
SERIAL_TO_TEST.print(val / 1000);
SERIAL_TO_TEST.print("K");
} else {
SERIAL_TO_TEST.print(val);
}
}
// String chars100 = String("0aaaaaaaaa") + "1aaaaaaaaa" + "2aaaaaaaaa" +
// "3aaaaaaaaa" + "4aaaaaaaaa" + "5aaaaaaaaa" + "6aaaaaaaaa" +
// "7aaaaaaaaa" + "8aaaaaaaaa" + "9aaaaaaaaa";
// String chars1000 = chars100 + chars100 + chars100 + chars100 + chars100 +
// chars100 + chars100 + chars100 + chars100 + chars100;
String chars10 = "abcdefghij";
// String chars20 = chars10 + chars10;
void printKiloBytes(uint32_t kiloBytes) {
auto start = millis();
// for (int i = 0; i < kiloBytes * 1000; ++i) {
// SERIAL_TO_TEST.print("a");
// }
for (int i = 0; i < kiloBytes * 100; ++i) {
SERIAL_TO_TEST.print(chars10);
}
// for (int i = 0; i < kiloBytes * 50; ++i) {
// SERIAL_TO_TEST.print(chars20);
// }
// for (int i = 0; i < kiloBytes * 10; ++i) {
// SERIAL_TO_TEST.print(chars100);
// }
// for (int i = 0; i < kiloBytes; ++i) {
// SERIAL_TO_TEST.print(chars1000);
// }
Serial.println();
auto diffMs = millis() - start;
SERIAL_TO_TEST.println("print " + String(kiloBytes) + "K for " +
String(diffMs) + "ms");
if (diffMs == 0) {
SERIAL_TO_TEST.println("so fast not to measure speed");
} else {
auto bytePerSec = (double)kiloBytes * 1000 * 1000 / diffMs;
printWithScaleChar(bytePerSec);
SERIAL_TO_TEST.println(" byte/s");
auto bitPerSec = bytePerSec * 10;
printWithScaleChar(bitPerSec);
SERIAL_TO_TEST.println(" bit/s");
}
SERIAL_TO_TEST.flush();
}
void loop() {
printKiloBytes(10);
delay(1000);
printKiloBytes(1);
delay(1000);
}