Python Forum
Performance options for sys.stdout.writelines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performance options for sys.stdout.writelines
#11
Thanks all, tried a few things and will keep it as it is. Does anyone have a suggestion for enhancing performance using sys.stdout.writelines? Have not tried import multiprocessing, but I do think this would work. Is there any standard library functions that allow writelines to be faster for large files? Appreciated the input, it helped.

Dave
Reply
#12
@Yoriz: that made it work! Not quite light speed, but close!

In the Idle shell things go a little slower than running the programme directly, I believe!

Output:
621 function calls in 0.054 seconds ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.054 0.054 <pyshell#2>:1(myApp) 1 0.000 0.000 0.054 0.054 <string>:1(<module>) 2 0.000 0.000 0.000 0.000 _bootlocale.py:33(getpreferredencoding) 2 0.000 0.000 0.000 0.000 codecs.py:260(__init__) 2 0.000 0.000 0.000 0.000 codecs.py:309(__init__) 4 0.000 0.000 0.000 0.000 codecs.py:319(decode) 77 0.000 0.000 0.000 0.000 rpc.py:153(debug) 11 0.000 0.000 0.048 0.004 rpc.py:216(remotecall) 11 0.000 0.000 0.001 0.000 rpc.py:226(asynccall) 11 0.000 0.000 0.047 0.004 rpc.py:246(asyncreturn) 11 0.000 0.000 0.000 0.000 rpc.py:252(decoderesponse) 11 0.000 0.000 0.046 0.004 rpc.py:290(getresponse) 11 0.000 0.000 0.000 0.000 rpc.py:298(_proxify) 11 0.000 0.000 0.046 0.004 rpc.py:306(_getresponse) 11 0.000 0.000 0.000 0.000 rpc.py:328(newseq) 11 0.000 0.000 0.001 0.000 rpc.py:332(putmessage) 10 0.000 0.000 0.027 0.003 rpc.py:559(__getattr__) 11 0.000 0.000 0.000 0.000 rpc.py:57(dumps) 1 0.000 0.000 0.027 0.027 rpc.py:577(__getmethods) 10 0.000 0.000 0.000 0.000 rpc.py:601(__init__) 10 0.000 0.000 0.022 0.002 rpc.py:606(__call__) 20 0.000 0.000 0.000 0.000 run.py:420(encoding) 20 0.000 0.000 0.000 0.000 run.py:424(errors) 10 0.000 0.000 0.049 0.005 run.py:441(write) 22 0.000 0.000 0.000 0.000 threading.py:1306(current_thread) 11 0.000 0.000 0.000 0.000 threading.py:222(__init__) 11 0.000 0.000 0.046 0.004 threading.py:270(wait) 11 0.000 0.000 0.000 0.000 threading.py:81(RLock) 4 0.000 0.000 0.000 0.000 {built-in method _codecs.utf_8_decode} 2 0.000 0.000 0.000 0.000 {built-in method _locale.nl_langinfo} 11 0.000 0.000 0.000 0.000 {built-in method _struct.pack} 11 0.000 0.000 0.000 0.000 {built-in method _thread.allocate_lock} 22 0.000 0.000 0.000 0.000 {built-in method _thread.get_ident} 1 0.000 0.000 0.054 0.054 {built-in method builtins.exec} 22 0.000 0.000 0.000 0.000 {built-in method builtins.isinstance} 36 0.000 0.000 0.000 0.000 {built-in method builtins.len} 5 0.000 0.000 0.049 0.010 {built-in method builtins.print} 2 0.000 0.000 0.000 0.000 {built-in method io.open} 11 0.000 0.000 0.000 0.000 {built-in method select.select} 11 0.000 0.000 0.000 0.000 {method '_acquire_restore' of '_thread.RLock' objects} 11 0.000 0.000 0.000 0.000 {method '_is_owned' of '_thread.RLock' objects} 11 0.000 0.000 0.000 0.000 {method '_release_save' of '_thread.RLock' objects} 11 0.000 0.000 0.000 0.000 {method 'acquire' of '_thread.RLock' objects} 22 0.045 0.002 0.045 0.002 {method 'acquire' of '_thread.lock' objects} 11 0.000 0.000 0.000 0.000 {method 'append' of 'collections.deque' objects} 5 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects} 10 0.000 0.000 0.000 0.000 {method 'decode' of 'bytes' objects} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} 11 0.000 0.000 0.000 0.000 {method 'dump' of '_pickle.Pickler' objects} 10 0.000 0.000 0.000 0.000 {method 'encode' of 'str' objects} 10 0.000 0.000 0.000 0.000 {method 'get' of 'dict' objects} 11 0.000 0.000 0.000 0.000 {method 'getvalue' of '_io.BytesIO' objects} 2 0.005 0.002 0.005 0.002 {method 'readlines' of '_io._IOBase' objects} 11 0.000 0.000 0.000 0.000 {method 'release' of '_thread.RLock' objects} 11 0.000 0.000 0.000 0.000 {method 'send' of '_socket.socket' objects}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 481 Jan-26-2024, 07:26 PM
Last Post: snippsat
  writelines only writes one line to file gr3yali3n 2 2,380 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  changing stdout and stderr Skaperen 4 2,690 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  print a line break in writelines() method leodavinci1990 1 6,467 Oct-12-2020, 06:36 AM
Last Post: DeaD_EyE
  Get stdout of a running process yok0 0 3,031 Aug-20-2020, 10:12 AM
Last Post: yok0
  Can argparse support undocumented options? pjfarley3 3 2,210 Aug-14-2020, 06:13 AM
Last Post: pjfarley3
  Performance enhancement fimmu 0 1,625 Feb-12-2020, 02:42 PM
Last Post: fimmu
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,617 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  performance kerzol81 1 1,916 Oct-07-2019, 10:19 AM
Last Post: buran
  Help with options raiden 1 1,929 Aug-30-2019, 12:57 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020