Jump to content

Quick question about FileWriteLine


NiwatiX
 Share

Recommended Posts

Hey guys, from a performance stand point, which one is best?

FileWriteLine($sOpenfile,"some text1" & @CRLF)
FileWriteLine($sOpenfile,"some text2" & @CRLF)
FileWriteLine($sOpenfile,"some text3" & @CRLF)
FileWriteLine($sOpenfile,"some text4" & @CRLF)

 

Or this one
 

FileWriteLine($sOpenfile,"some text1" & @CRLF & "some text2" & @CRLF & "some text3" & @CRLF & "some text4" & @CRLF &"some text5" & @CRLF)

 

Also if second version is better, any way to split it on multiple line for readability inside the IDE? I'm a C programmer so usually white space isn't a problem out of string, I'm not used to that high level coding. I would assume second version is better since you call only once FileWriteLine, but you know sometime in the wrapper they optimize crazy things and I just want to be sure I'm not mistaken.

Edited by NiwatiX
Link to comment
Share on other sites

  • Moderators

NiwatiX,

Why not write a quick script and see? Or do you expect someone else to do all the work for you?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

NiwatiX,

Why not write a quick script and see? Or do you expect someone else to do all the work for you?

M23

Well I expected someone to just.. know the answer. I'm sorry if you misunderstood my question, I don't want someone to build a script for me lol...  I was wondering how things are aligned by the optimizer.

Link to comment
Share on other sites

For future reference this is an example of how to test which of several different methods is the fastest.

#include <FileConstants.au3>

RunTests()

Func RunTests()
Local $sOpenfile = "c:\Temp\TessFile.txt"
Local $Method1Timer = 0
Local $Method2Timer = 0
Local $Method3Timer = 0

    $Method1Timer = TimerInit()
    Method1Test($sOpenfile)
    ConsoleWrite("Method 1 took " & TimerDiff($Method1Timer) & " milliseconds" & @CRLF )

    $Method2Timer = TimerInit()
    Method2Test($sOpenfile)
    ConsoleWrite("Method 2 took " & TimerDiff($Method2Timer) & " milliseconds" & @CRLF )

    $Method3Timer = TimerInit()
    Method3Test($sOpenfile)
    ConsoleWrite("Method 3 took " & TimerDiff($Method3Timer) & " milliseconds" & @CRLF )

EndFunc

Func Method1Test($sOpenfile)
    FileWriteLine($sOpenfile,"some text1")
    FileWriteLine($sOpenfile,"some text2")
    FileWriteLine($sOpenfile,"some text3")
    FileWriteLine($sOpenfile,"some text5")
    FileWriteLine($sOpenfile,"some text6")
    FileWriteLine($sOpenfile,"some text7")
    FileWriteLine($sOpenfile,"some text8")
    FileWriteLine($sOpenfile,"some text9")
    FileWriteLine($sOpenfile,"some text10")
EndFunc

Func Method2Test($sOpenfile)
    FileWriteLine($sOpenfile,"some text1" & @CRLF & "some text2" & @CRLF & "some text3" & @CRLF & "some text4" & @CRLF & "some text5" & @CRLF & "some text6" & @CRLF & "some text7" & @CRLF & "some text8" & @CRLF & "some text9" & @CRLF & "some text10")
EndFunc

Func Method3Test($sOpenfile)
    Local $hFileHandel = FileOpen($sOpenfile,$FO_OVERWRITE+$FO_CREATEPATH )
    FileWriteLine($hFileHandel,"some text1")
    FileWriteLine($hFileHandel,"some text2")
    FileWriteLine($hFileHandel,"some text3")
    FileWriteLine($hFileHandel,"some text4")
    FileWriteLine($hFileHandel,"some text5")
    FileWriteLine($hFileHandel,"some text6")
    FileWriteLine($hFileHandel,"some text7")
    FileWriteLine($hFileHandel,"some text8")
    FileWriteLine($hFileHandel,"some text9")
    FileWriteLine($hFileHandel,"some text10")
    FileClose($hFileHandel)
EndFunc

 

 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

also

...... any way to split it on multiple line for readability inside the IDE? .......

to split long lines, you can use the underscore sign _ within the IDE:

FileWriteLine($sOpenfile, "some text1" & @CRLF & _
        "some text2" & @CRLF & _
        "some text3" & @CRLF & _
        "some text4" & @CRLF & _
        "some text5" & @CRLF)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...