# test.py import string text = string.ascii_letters + '\n' with open("data.txt", "w") as f: for i in range(50000): f.write(text) python2.6 -m cProfile -stime test.py 50007 function calls in 0.144 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 50000 0.070 0.000 0.070 0.000 {method 'write' of 'file' objects} 1 0.068 0.068 0.144 0.144 test.py:1() 1 0.003 0.003 0.003 0.003 {range} 1 0.003 0.003 0.003 0.003 {open} 1 0.000 0.000 0.144 0.144 {execfile} 1 0.000 0.000 0.144 0.144 :1() 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {method '__enter__' of 'file' objects} ./python -m cProfile -stime test.py 801983 function calls (801982 primitive calls) in 3.686 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 50000 1.035 0.000 1.781 0.000 io.py:1031(write) 50000 0.862 0.000 3.505 0.000 io.py:1477(write) 250002 0.342 0.000 0.342 0.000 {built-in method len} 100645 0.244 0.000 0.244 0.000 io.py:755(closed) 50000 0.242 0.000 0.393 0.000 utf_8.py:19(encode) 50001 0.216 0.000 0.339 0.000 io.py:1463(closed) 100004 0.180 0.000 0.180 0.000 {built-in method isinstance} 1 0.179 0.179 3.686 3.686 :1() 50000 0.151 0.000 0.151 0.000 {built-in method utf_8_encode} 50002 0.094 0.000 0.094 0.000 {method '__enter__' of '_thread.lock' objects} 50000 0.090 0.000 0.090 0.000 {method 'extend' of 'bytearray' objects} 642 0.041 0.000 0.041 0.000 {method 'write' of '_FileIO' objects} 643 0.008 0.000 0.051 0.000 io.py:1073(_flush_unlocked) 1 0.001 0.001 0.001 0.001 io.py:614(__init__) 2/1 0.000 0.000 3.686 3.686 {built-in method exec} 1 0.000 0.000 0.001 0.001 io.py:82(open) 1 0.000 0.000 0.000 0.000 io.py:1379(__init__) 1 0.000 0.000 0.000 0.000 io.py:1020(__init__) 3 0.000 0.000 0.000 0.000 {built-in method setlocale} 3 0.000 0.000 0.000 0.000 locale.py:487(setlocale) 1 0.000 0.000 0.000 0.000 io.py:618(close) 1 0.000 0.000 0.000 0.000 locale.py:536(getpreferredencoding) 2 0.000 0.000 0.000 0.000 io.py:1069(flush) 1 0.000 0.000 0.000 0.000 io.py:1498(_get_encoder) 1 0.000 0.000 0.000 0.000 io.py:736(close) 1 0.000 0.000 0.000 0.000 io.py:1456(close) 1 0.000 0.000 0.000 0.000 io.py:427(_checkWritable) 1 0.000 0.000 0.000 0.000 codecs.py:937(getincrementalencoder) 1 0.000 0.000 0.000 0.000 io.py:746(seekable) 1 0.000 0.000 0.000 0.000 {built-in method fstat} 1 0.000 0.000 0.000 0.000 io.py:451(__enter__) 1 0.000 0.000 0.000 0.000 io.py:1452(flush) 1 0.000 0.000 0.000 0.000 io.py:364(close) 1 0.000 0.000 0.001 0.001 io.py:277(__new__) 1 0.000 0.000 0.000 0.000 io.py:456(__exit__) 1 0.000 0.000 0.000 0.000 io.py:442(_checkClosed) 1 0.000 0.000 0.000 0.000 codecs.py:164(__init__) 1 0.000 0.000 0.000 0.000 io.py:769(fileno) 1 0.000 0.000 0.000 0.000 {built-in method lookup} 1 0.000 0.000 0.000 0.000 io.py:708(__init__) 1 0.000 0.000 0.000 0.000 {method 'isatty' of '_FileIO' objects} 1 0.000 0.000 0.000 0.000 {built-in method nl_langinfo} 1 0.000 0.000 0.000 0.000 {built-in method device_encoding} 2 0.000 0.000 0.000 0.000 {method 'fileno' of '_FileIO' objects} 1 0.000 0.000 0.000 0.000 {method 'seekable' of '_FileIO' objects} 1 0.000 0.000 0.000 0.000 io.py:355(flush) 1 0.000 0.000 0.000 0.000 {built-in method allocate_lock} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 1 0.000 0.000 0.000 0.000 {method 'writable' of '_FileIO' objects}