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
#1
Pythonistas,

I am trying to improve performance of a simple script reading and comparing two 20KB .dat files. The diff assignment takes 42 seconds and the sys.stdout.writelines 82 seconds. Is there an approach to shaving down these times using standard library features. Would concurrent.futures work. It would be nice to have a settable thread pool like used in multiprocessing module but that doesn't come in the standard library.

with multiprocessing.Pool(processes=(2)) as pool
Is there a way to use multiple threads or processes than can be "set" depending on the size of the .dat?

import difflib
import sys
import time
import os

fromfile = "some1.dat"
tofile = "some2.dat"

fromlines = open(fromfile, "r").readlines()
tolines = open(tofile, "r").readlines()

# takes 42 secs
diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile)

#takes 82 secs
sys.stdout.writelines(diff)
Best,
Dave
Reply


Messages In This Thread
Performance options for sys.stdout.writelines - by dgrunwal - Aug-19-2022, 08:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [subprocess] Why stdout sent to stderr? Winfried 3 527 Jan-26-2024, 07:26 PM
Last Post: snippsat
  writelines only writes one line to file gr3yali3n 2 2,431 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  changing stdout and stderr Skaperen 4 2,725 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  print a line break in writelines() method leodavinci1990 1 6,526 Oct-12-2020, 06:36 AM
Last Post: DeaD_EyE
  Get stdout of a running process yok0 0 3,068 Aug-20-2020, 10:12 AM
Last Post: yok0
  Can argparse support undocumented options? pjfarley3 3 2,275 Aug-14-2020, 06:13 AM
Last Post: pjfarley3
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,677 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  performance kerzol81 1 1,943 Oct-07-2019, 10:19 AM
Last Post: buran
  Help with options raiden 1 1,954 Aug-30-2019, 12:57 AM
Last Post: scidam
  Distilling strings using .writelines() and .read() tedie 1 2,049 Jun-24-2019, 09:56 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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