Influx Posted January 3, 2009 Posted January 3, 2009 I know by use of DLLS functions can be sped up (by using UDFs with the dll) Basicaly what i would like is some speedly dlls for doing the following *reading a file *checking stringinsrt() and any toher usefull ones you have laying arround. thanks, Influx note:please include the udfs or instructions
Influx Posted January 3, 2009 Author Posted January 3, 2009 wouldnt that still be just as slow as autoit? if not what is an example dll call to read a file, and do a stringinstr() functions
junkew Posted January 4, 2009 Posted January 4, 2009 Whats slow on fileread?It can read a file at once in a stringstringinstr alternatives: http://en.wikipedia.org/wiki/String_searching_algorithmHow large are the strings you want to search in? FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Influx Posted January 4, 2009 Author Posted January 4, 2009 200kb-100MB files. Autoit takes about half a second or more to read. C++ takes like 10/1000 of a second. im attempting to rewrite in C++ bu ti dont know if it will be a sucess.
monoceres Posted January 4, 2009 Posted January 4, 2009 200kb-100MB files.Autoit takes about half a second or more to read. C++ takes like 10/1000 of a second.im attempting to rewrite in C++ bu ti dont know if it will be a sucess.It depends on how you read the file. Try use _WinAPI_ReadFile and you will get great speed Broken link? PM me and I'll send you the file!
monoceres Posted January 4, 2009 Posted January 4, 2009 (edited) Extending my last post. Here's an example that uses _WinAPI_ReadFile and the standard C library. The difference is significant! expandcollapse popup#include <winapi.au3> ConsoleWrite("Using pure AutoIt"&@CRLF) $timer2=TimerInit() $data=FileRead("test.data") $pos=StringInStr($data,"andreas") If $pos Then ConsoleWrite("Substring found at position: "&$pos&@CRLF) Else ConsoleWrite("Substring not found"&@CRLF) EndIf ConsoleWrite("Total processing time: "&Round(TimerDiff($timer2))&" ms."&@CRLF&@CRLF) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ConsoleWrite("Using WinAPI and the standard C library"&@CRLF) $timer=TimerInit() $fsize=FileGetSize("test.data") $handle=_WinAPI_CreateFile("test.data",2,2) $buffer=DllStructCreate("char["&$fsize+1&"]") DllStructSetData($buffer,1,Chr(0),$fsize+1) Local $red _WinAPI_ReadFile($handle,DllStructGetPtr($buffer),$fsize,$red) _WinAPI_CloseHandle($handle) $call=DllCall("msvcrt.dll","ptr:cdecl","strstr","ptr",DllStructGetPtr($buffer),"str","andreas") If $call[0] Then ConsoleWrite("Substring found at position: "&1+Dec(StringTrimLeft($call[0]-DllStructGetPtr($buffer),2))&@CRLF) Else ConsoleWrite("Substring not found"&@CRLF) EndIf ConsoleWrite("Total processing time: "&Round(TimerDiff($timer))&" ms."&@CRLF) Here's a script that creates the test file: $str="" For $i=0 To 10^6 $str&=Chr(Random(97,122,1)) If $i=Round(10^6/2) Then $str&="andreas" Next FileWrite("test.data",$str) Results on my computer: WinAPI+C lib = 2 ms. AutoIt = 147 ms. Edited January 4, 2009 by monoceres Broken link? PM me and I'll send you the file!
FireFox Posted January 4, 2009 Posted January 4, 2009 @monoceres I think I will now use _WinAPI_ReadFile instead of file read Cheers, FireFox.
monoceres Posted January 4, 2009 Posted January 4, 2009 @monoceresI think I will now use _WinAPI_ReadFile instead of file read Cheers, FireFox.Well just make sure you know how to handle a null-terminated C string. They're not quite as easy to work with as autoit's string type.Oh and you should know that most of the difference is made in the finding of the substring. Just reading the file look like this:AutoIt: 18 ms_WinAPI_ReadFile: 1 ms Broken link? PM me and I'll send you the file!
trancexx Posted January 4, 2009 Posted January 4, 2009 This is so strange. I mean, I know that devs are making things as robust as they can be (so that we don't brake something), but this is almost too much. What kind of file or error checking are they doing there? Great comparison monoceres! ♡♡♡ . eMyvnE
monoceres Posted January 4, 2009 Posted January 4, 2009 This is so strange. I mean, I know that devs are making things as robust as they can be (so that we don't brake something), but this is almost too much. What kind of file or error checking are they doing there? Great comparison monoceres!Yeah, however I just realized something. My comparison wasn't really fair. StringInStr() is not case-sensitive by default which means that autoit needs to determine a whole lot more combinations. Changing StringInStr() to be case-sensitive makes the match a whole lot better:_WinAPI_ReadFile + C Lib: 2 ms.Pure AutoIt: 25 ms.Sorry for that. Broken link? PM me and I'll send you the file!
trancexx Posted January 4, 2009 Posted January 4, 2009 It's a bit faster this like too: $hwnd = FileOpen("test.data", 16) $data = BinaryToString(FileRead($hwnd)) FileClose($hwnd) ♡♡♡ . eMyvnE
Influx Posted January 5, 2009 Author Posted January 5, 2009 question.... lol your code was confusing. lets sat i just want to read database.viri to the variable $db... how would I do that?
trancexx Posted January 17, 2009 Posted January 17, 2009 (edited) I find interesting that strstr function from msvcrt.dll can be found in ntdll.dll too.Same calling convention, same everything. And that one is not the only one. Edited January 17, 2009 by trancexx ♡♡♡ . eMyvnE
Pain Posted January 17, 2009 Posted January 17, 2009 (edited) The one from ntdll.dll should be faster because you skip one step. Instead of calling the function from your application to msvcrt.dll to ntdll.dll you go from your application to ntdll.dll. If I'm not mistaken they should be in kernel32 too, still ntdll should be fastest. Edited January 17, 2009 by Pain
trancexx Posted January 17, 2009 Posted January 17, 2009 The one from ntdll.dll should be faster because you skip one step. Instead of calling the function from your application to msvcrt.dll to ntdll.dll you go from your application to ntdll.dll. If I'm not mistaken they should be in kernel32 too, still ntdll should be fastest.In both cases they are not imported. Code is in msvcrt.dll as well as in ntdll.dll (this one have no imports at all). There should be no difference in speed.But ntdll.dll is what they call "NT Layer DLL". Fundamental one. ♡♡♡ . eMyvnE
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now