-
Notifications
You must be signed in to change notification settings - Fork 0
Performance.md
Want to make Bang scream with speed while keeping your Arduino’s command-line domination on point? This page dives into performance factors for ! (shell), & (sketch uploads), and @ (macro) commands, ensuring your BANG("echo Hello") or BANG("&blink\n") runs like a champ. From serial speeds to host command latency, we’ll optimize Bang to stay lean for Arduino’s tight memory and maximize your project’s punch. Let’s rev up this beast!
- Purpose: Optimize Bang’s performance for Arduino and host interaction.
-
Key Factors:
- Serial-USB communication speed (baud rate).
- Host command execution latency (
!and@). - Sketch upload time (
&). - Arduino memory usage.
- Goal: Balance speed and reliability for smooth operation.
- Impact: Higher baud rates (e.g., 115200 vs. 38400) reduce command/response latency but may increase errors on some Arduino boards.
- Default: 38400 baud.
-
Optimization:
-
Increase baud rate in sketch and
arduino_exec.py:void setup() { Serial.begin(115200); // Faster than 38400 while (!Serial) ; }
Run
arduino_exec.pywith matching rate:sudo python3 arduino_exec.py -p /dev/cu.usbserial-00100 -b 115200
-
Test Stability: Some boards (e.g., Uno) may need lower rates (e.g., 57600) for reliability.
-
Tip: Match baud rates exactly to avoid communication errors.
-
-
Impact:
!(shell) and@(macro) commands depend on host shell or script execution speed. -
Optimization:
-
Use simple shell commands:
BANG("echo Hello"); // Faster than complex scripts
-
Predefine macros for frequent commands:
macros = {'weather': 'curl wttr.in?format=3'} # In arduino_exec.py
Then:
BANG("@weather")(faster thanBANG("curl wttr.in?format=3")). -
Minimize host load: Close unnecessary apps to speed up command execution.
-
Cache results for repetitive macros if supported in
arduino_exec.py.
-
-
Impact:
&sketch_name\nuploads involve compiling and flashing, which can take seconds. -
Optimization:
-
Use small sketches to reduce compile/upload time:
// In blink.ino #include <Bang.h> Bang bang(Serial); void setup() { Serial.begin(38400); pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); }
-
Optimize
arduino-cli:arduino-cli compile --fqbn arduino:avr:uno blink.ino --optimize-for-size
-
Precompile sketches if possible to reduce upload time.
-
Ensure fast host CPU and SSD for quicker compilation.
-
- Impact: Bang’s lean design minimizes RAM usage, but complex sketches or many macros can strain Arduino’s memory.
-
Optimization:
-
Use
BANG_Pfor static commands to save RAM:BANG_P(PSTR("echo Hello")); // Stored in PROGMEM
-
Limit
Stringusage:// Avoid String cmd = "curl https://example.com"; BANG_S(cmd); // Prefer BANG("curl https://example.com");
-
Keep sketches minimal to leave room for Bang’s operations.
-
Monitor memory with Arduino IDE’s compiler output.
-
-
Measure Latency:
-
Add timing in sketch:
unsigned long start = millis(); BANG("echo Hello"); Serial.print("Latency: "); Serial.println(millis() - start);
-
-
Log Upload Time:
-
Modify
arduino_exec.py:def compile_and_upload(sketch): start_time = time.time() # Upload logic print(f"Upload took {time.time() - start_time} seconds")
-
-
Check Macro Speed:
-
Test
@macrovs. direct!commands:BANG("@weather"); // Should be faster than BANG("curl wttr.in?format=3")
-
- Slow Commands: Lower baud rate (e.g., 57600) or simplify commands.
-
Upload Delays: Check
arduino-clilogs or host CPU load. -
Memory Issues: Use
BANG_Pand minimizeStringobjects. - See Troubleshooting for more fixes.
- Check Testing for validating performance tweaks.
- Explore Examples for optimized sketches.
- See FAQ for performance questions.