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
#9
All was able to get the script 20% improvement, seems the sys.stdout.writelines takes the longest. Not sure if it can be enhanced for speed in case larger files come.

Dave

import difflib
import concurrent.futures
import sys
import time
import os

fromfile = "some20MB.dat"
tofile = "another20MB.dat"

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

with concurrent.futures.ProcessPoolExecutor() as executor:
diff = difflib.HtmlDiff().make_file(fromlines,tolines,fromfile,tofile)

with concurrent.futures.ProcessPoolExecutor() as executor:
sys.stdout.writelines(diff)
Reply


Messages In This Thread
RE: Performance options for sys.stdout.writelines - by dgrunwal - Aug-22-2022, 05:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  argparser not showing all options bigal 1 310 May-22-2024, 02:54 AM
Last Post: deanhystad
  [subprocess] Why stdout sent to stderr? Winfried 3 640 Jan-26-2024, 07:26 PM
Last Post: snippsat
  writelines only writes one line to file gr3yali3n 2 2,591 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  changing stdout and stderr Skaperen 4 2,863 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  print a line break in writelines() method leodavinci1990 1 6,687 Oct-12-2020, 06:36 AM
Last Post: DeaD_EyE
  Get stdout of a running process yok0 0 3,202 Aug-20-2020, 10:12 AM
Last Post: yok0
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,912 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  performance kerzol81 1 1,999 Oct-07-2019, 10:19 AM
Last Post: buran
  Help with options raiden 1 2,036 Aug-30-2019, 12:57 AM
Last Post: scidam
  Distilling strings using .writelines() and .read() tedie 1 2,126 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