Jump to content

LUCY! You have some 'splainin' to do!


Recommended Posts

I was just working at re-writing a function and I noticed something that made no sence so I whipped up a test script to check the time differences.

Here is the test script using a large file.

$sFile = "wordlist.txt"
$Time1 = 0
$Time2 = 0
$iLoops = 200
For $i = 1 To $iLoops
    $Time1 += _Time1()
Next

For $i = 1 To $iLoops
    $Time2 += _Time2()
Next
ConsoleWrite("Average Read Only: " & Round(($Time1/$iLoops)/1000, 5) & "Seconds" & @CRLF)
ConsoleWrite("Average Open/Read/Close: " & Round(($Time2/$iLoops)/1000, 5) & "Seconds" & @CRLF)

Func _Time1()
    Local $iTime = 0;; Just to be safe lets flush the timer
    $iTime = TimerInit()
    FileRead($sFile)
    Return TimerDiff($iTime)
EndFunc

Func _Time2()
    Local $iTime = 0;; Just to be safe lets flush the timer
    $iTime = TimerInit()
    $hFile = FileOpen($sFile)
    FileRead($hFile)
    FileClose($hFile)
    Return TimerDiff($iTime)
EndFunc

If I run that script 10 or so times the returns will differ but that's not the issue. 9 out of 10 times FileOpen/Read/Close() will be faster than a simple FileRead() and that makes no sense to me. I even restarted my system to see if File cache was coming into play and it doesn't appear to be.

You can use any file but to test it with the one I used you can download it here

http://dundats.mvps.org/autoit/files/wordlist.zip

Would someone like to hazard a guess as to why a simple FileRead is slower?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

A FileRead without FileOpen/Close has to call FileOpen and FileClose internally, so they should need about the same time.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I had forgotten that part but in most tests using FileOpen/Read/Close() was faster and that makes no sense to me at all. I should also mention that changing the value of $iLoops can vary the results by a considerable amount. That is considerable as in milliseconds which is not really a large amount.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I saw the same results as you GEOSoft when I ran it from my hard drive. When I ran it from a thumb drive I saw the opposite results in that FileOpen was faster by a few milliseconds. Even though, both scenarios ran in comparable timeframes regardless of which drive it was being run on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I can see drive read speeds making a difference and I'm actually running it from my slowest drive which is also my largest drive.

The way I see it is even though using a simple FileRead() makes internal calls for FileOpen and FileClose those I would think are API calls so they should be faster.

Maybe a dev will come along and shed some light on this.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Not for me. I'll try again after my next restart and see what I get then. I have a suspicion that file caching is coming into play somehow.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, todays tests show that no matter what order I call the functions; FileOpen/Read?Close is still faster although the actual times did change by a very slight amount.

First test was _Time1() first followed by a test with _Time2() first

Then a reboot of the system

Tested _Time2() first followed by a test with _Time1()first

Then a reboot into Win 7 and repeat the tests

Same results as under Vista although the times were slightly better in 7 which has been pretty much the norm for W7 on this system anyway probably because it doesn't have a lot of crap installs that my Vista does. I didn't bother testing under XP at all. I was seeing slightly larger differences yesterday and I still think part of the discrepancy is File Cache related.

Here are the actual values

Average Read Only: 0.04251Seconds Test 1 = timer 1 first

Average Open/Read/Close: 0.04322Seconds

Average Read Only: 0.04248Seconds Test 2 = timer 2 first

Average Open/Read/Close: 0.04245Seconds

After reboot -- Vista

Average Read Only: 0.0423Seconds Test 3 = timer 2 first

Average Open/Read/Close: 0.04215Seconds

Average Read Only: 0.04195Seconds Test 4 = timer 1 first

Average Open/Read/Close: 0.04199Seconds

After Reboot Win 7

Average Read Only: 0.04142Seconds Test 5 = timer 1 first

Average Open/Read/Close: 0.0411Seconds

Average Read Only: 0.04134Seconds Test 6 = timer 2 first

Average Open/Read/Close: 0.04187Seconds

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I got the same results on Win 7 x64. I use FileOpen/FileRead in most of my applications anyway.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I just can't figure out why using 3 calls to AutoIt functions should be faster than using a single AutoIt function call which I assume internally makes the required API calls. If indeed thay are API calls; and Valik didn't clarify that point in his reply.

This is more for curiosity anyway since I do know that what I was attempting to do with the UDF I was looking at would be much slower than it is now anyway and that is not because of these time differences either.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...