OregonStateRocketry / 30k2018-CS-Capstone

30k CS Capstone repository
Apache License 2.0
2 stars 0 forks source link

Compare program speed using file.write() instead of piping output to file #13

Closed lwillmeth closed 6 years ago

lwillmeth commented 6 years ago

Right now the avionics loop prints each line to the screen. Let's see if there are any speed gains to be had by either batching files, or writing directly to a file instead.

The number and type of sensor doesn't matter as long as all 3 tests use the same sensors and output formats. All 3 CSV files should be identical.

lwillmeth commented 6 years ago

Baseline, 10k lines being piped to file one at a time:

$ time python3 MPU6050.py > 10kbaseline
real    1m44.841s
user    0m12.590s
sys 0m7.140s

10k lines being piped to file in blocks of 100:

$ time python3 MPU6050.py > 10kblocks
real    1m45.573s
user    0m13.000s
sys 0m6.910s

10k lines using file.write, open/flush the file for every block of 100 lines:

$ time python3 MPU6050.py
real    1m46.250s
user    0m13.010s
sys 0m7.720s

10k lines using file.write one at a time: (note, this only opens/closes the file once)

$ time python3 MPU6050.py
real    1m45.449s
user    0m12.720s
sys 0m7.160s

Conclusion:

The method we use to write to file does not really affect the run time. We should use the method that gives us the best results. Writing each line directly to file probably gives us the highest margin of safety because if the pi unexpectedly shuts down mid-write, very little data is lost.