Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Weiyuan-Lane/0e4f36ff85251ddf4747b4220973c850 to your computer and use it in GitHub Desktop.
Save Weiyuan-Lane/0e4f36ff85251ddf4747b4220973c850 to your computer and use it in GitHub Desktop.
Comparison of file writing strategies
user system total real
Write all lines to file at once, mode "w" 0.349308 0.955585 1.304893 ( 1.321532)
Write all lines to file at once, mode "a" 0.215273 0.786001 1.001274 ( 1.008887)
Write all lines to file at once, mode "w+" 0.206097 0.729586 0.935683 ( 0.943146)
Write all lines to file at once, mode "a+" 0.219936 0.732151 0.952087 ( 0.960331)
Iterate and write per line to file, mode "w" 0.014412 0.014297 0.028709 ( 0.047540)
Iterate and write per line to file, mode "a" 0.015421 0.000931 0.016352 ( 0.035943)
Iterate and write per line to file, mode "w+" 0.014933 0.001423 0.016356 ( 0.038612)
Iterate and write per line to file, mode "a+" 0.016904 0.000542 0.017446 ( 0.040842)
Iterate and write per line to file (manual), mode "w" 0.014541 0.000552 0.015093 ( 0.034744)
Iterate and write per line to file (manual), mode "a" 0.014172 0.002943 0.017115 ( 0.041018)
Iterate and write per line to file (manual), mode "w+" 0.016473 0.000000 0.016473 ( 0.036743)
Iterate and write per line to file (manual), mode "a+" 0.016505 0.000368 0.016873 ( 0.037577)
Iterate and write per line to file chunks, mode "w" 0.021093 0.021610 0.042703 ( 0.504697)
Iterate and write per line to file chunks, mode "a" 0.032414 0.010477 0.042891 ( 0.474308)
Iterate and write per line to file chunks, mode "w+" 0.028983 0.017011 0.045994 ( 0.483656)
Iterate and write per line to file chunks, mode "a+" 0.029736 0.016745 0.046481 ( 0.689312)
Iterate and write per line to file chunks (manual), mode "w" 0.036542 0.020255 0.056797 ( 0.527364)
Iterate and write per line to file chunks (manual), mode "a" 0.030160 0.017156 0.047316 ( 0.515649)
Iterate and write per line to file chunks (manual), mode "w+" 0.025164 0.018600 0.043764 ( 0.530540)
Iterate and write per line to file chunks (manual), mode "a+" 0.030291 0.021771 0.052062 ( 0.553764)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment