Jump to content

share you dlls for speed


 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Extending my last post.

Here's an example that uses _WinAPI_ReadFile and the standard C library. The difference is significant!

#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 by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

@monoceres

I 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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...

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 by Pain
Link to comment
Share on other sites

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

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