title: Is it better to constantly write to a file, or keep data in memory and write at the end?
body: <p>I'm writing a test suite for timing my algorithms against publicly available code. Each test run takes less than a second, ranging from very fast for small problem sizes, to ~900 ms for larger problems. </p>
  
  <p>I expect to write one line per test, no more than 200 characters per line. I need to print the time taken by each of the two algorithms, the error between them, and the seed used to generate the problem. I expect to run 2000 tests in a single run, but this number should also be flexible. If necessary, I could break up them into smaller runs.</p>
  
  <p>I expect to run several thousand tests in a single session, which may take several hours. Therefore, it is critical to ensure the data is not lost should anything happen half-way through a batch of tests. But constantly writing to a file might be too slow.</p>
  
  <p>I am trying to decide if I should write to the log file after every test, or store the results in memory and only print them after a batch of, say, 10 tests, or at the end of all the tests.  How much of a difference (in speed) would these different approaches make on average?</p>