ReadLn vs Powershell

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1116
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

ReadLn vs Powershell

Post by Grovkillen » Mon Jul 29, 2024 5:51 pm

I have done some benchmarking on the ReadLn vs reading the line using PS.

For large files the ReadLn is noticeable slow and thus I needed to find another way to read large files (in my case a 22GB csv file).

My results:

test1: 24.267s
test2: 3.951s

Code: Select all

Let>FILE_PATH=C:\path\to\huge\file\test.csv
Let>ROW_TO_READ=7713125

Timer>START
ReadLn>FILE_PATH,ROW_TO_READ,TEMP_row
Timer>END
Let>DURATION_test1={(%END%-%START%)/1000}

//PS start with index 0
Let>ROW_TO_READ=ROW_TO_READ-1

Timer>START
Let>RP_CAPTURESTDOUT=1
Let>POWERSHELL_COMMAND=[Linq.Enumerable]::ElementAt([System.IO.File]::ReadLines('%FILE_PATH%'), %ROW_TO_READ%)
RunProgram>cmd /c chcp 65001 > nul & cmd /c PowerShell -Command " & {%POWERSHELL_COMMAND%}"
Let>RP_CAPTURESTDOUT=0
Timer>END
Let>DURATION_test2={(%END%-%START%)/1000}

MDL>test1: %DURATION_test1%s%CRLF%test2: %DURATION_test2%s

/*
test1: 24.267s
test2:  3.951s
*/
Perhaps we could use this approach within MS in future versions?

BUT! ReadLn is faster than the PS way for line number < 26000
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts