JavaScript vs AutoHotKey (Simple Speed Test)

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: JavaScript vs AutoHotKey (Simple Speed Test)

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by smschulz » 01 Jan 2020, 08:19

truly amazing

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 23 Oct 2019, 09:47

I have a method which may be 4 times faster than the previous best method at around 47 msec.
Previous results for comparison:
JavaScript vs AutoHotKey (Simple Speed Test) - Page 3 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=61602&p=262559#p262559

The idea is to use _wcsnicmp/_strnicmp to compare blocks of characters, and then to home in on the first differing character within that block. The approach is described in the comments.

There's a lot going on in the function, so do notify of any issues. Cheers.

Code: Select all

q:: ;compare strings case insensitive (and get 1-based char index where differ)
vText1 := StrReplace(Format("{:20100100}", ""), " ", "a")
vText2 := vText1
vText1 .= "A"
vText2 .= "b"
;vText2 .= "a"

;vText1 := "abc", vText2 := "abd"
;vText1 := "abc", vText2 := "abcd"
;vText1 := "abc", vText2 := "abC"
;JEE_Swap(vText1, vText2)

vTickCount1 := A_TickCount
vRet := StrCmpI(vText1, vText2,, vOffsetDiff)
vTickCount2 := A_TickCount
MsgBox, % Clipboard := (vTickCount2 - vTickCount1) "`r`n" vRet " " vOffsetDiff
return

;e.g. results:
;47
;47
;31

;==================================================

;principles:
;use _wcsnicmp/_strnicmp to compare blocks of characters, find the first difference
;use memmove to copy blocks
;use CharLowerBuff to make them lower case
;use RtlCompareMemory to compare characters, find the first difference (its char index)

;note: vOffsetParam is for use with comparator functions for AHK's Sort command
;note: vText1/vText2 are ByRef for better performance (to avoid copying massive strings)
StrCmpI(ByRef vText1, ByRef vText2, vOffsetParam:=0, ByRef vOffsetOut:=0)
{
	local
	static vChrSize := A_IsUnicode ? 2 : 1
	static vFunc := A_IsUnicode ? "msvcrt\_wcsnicmp" : "msvcrt\_strnicmp"
	static vBlockLen := 1000000
	vLen1 := StrLen(vText1)
	vLen2 := StrLen(vText2)
	if !(vLen := Min(vLen1, vLen2))
		return -vOffsetParam ;return 0/-vOffsetParam if both empty strings
	vRem := Mod(vLen, vBlockLen)
	vOffset := vOffsetOut := vRet := 0
	Loop % Floor(vLen/vBlockLen)
	{
		if vRet := DllCall(vFunc, "Ptr",&vText1+vOffset*vChrSize, "Ptr",&vText2+vOffset*vChrSize, "Ptr",vBlockLen, "Cdecl")
			break
		vOffset += vBlockLen
	}
	if !vRet && (vBlockLen := vRem)
		vRet := DllCall(vFunc, "Ptr",&vText1+vOffset*vChrSize, "Ptr",&vText2+vOffset*vChrSize, "Ptr",vRem, "Cdecl")
	if !vRet
	{
		if (vLen1 = vLen2)
			return -vOffsetParam ;return 0/-vOffsetParam if equal
		vOffsetOut := vLen + 1
		return (vLen1 > vLen2) ? 1 : -1
	}
	VarSetCapacity(vTemp1, vBlockLen*vChrSize)
	VarSetCapacity(vTemp2, vBlockLen*vChrSize)
	DllCall("msvcrt\memmove", "Ptr",&vTemp1, "Ptr",&vText1+vOffset*vChrSize, "UPtr",vBlockLen*vChrSize, "Cdecl Ptr")
	DllCall("msvcrt\memmove", "Ptr",&vTemp2, "Ptr",&vText2+vOffset*vChrSize, "UPtr",vBlockLen*vChrSize, "Cdecl Ptr")
	DllCall("user32\CharLowerBuff", "Ptr",&vTemp1, "UInt",vBlockLen, "UInt")
	DllCall("user32\CharLowerBuff", "Ptr",&vTemp2, "UInt",vBlockLen, "UInt")
	vOffset2 := DllCall("ntdll\RtlCompareMemory", "Ptr",&vTemp1, "Ptr",&vTemp2, "UPtr",vBlockLen*vChrSize, "UPtr")
	;note: use Floor, since, for a Unicode string, the first byte that differs could be at an odd offset:
	vOffsetOut := vOffset + Floor(vOffset2/vChrSize) + 1
	return (vRet > 0) ? 1 : -1
}

;==================================================
[EDIT:] Simplified the function. And corrected RtlCompareMemory to point to the right locations.
[EDIT:] Note: if I run the script around half-a-dozen times, it starts to slow down!?

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by guest3456 » 17 Feb 2019, 18:20

tank wrote:
04 Feb 2019, 09:36
I am tempted to lock this debate but i am honestly curious how stupid it can get.
this "User" user has been just as stupid in other threads as well.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by gregster » 16 Feb 2019, 07:07

nnnik wrote:
16 Feb 2019, 04:11
First time I hear about ß being turned into SS. Imo it's either a flaw a bug or yeah something like that
It's pretty natural, that ss is used for ß...
https://www.autohotkey.com/boards/viewtopic.php?f=23&t=61602&start=20#p261456 wrote:Then again, until 1996's spelling reform it was Kuß instead of Kuss (in Germany) - while in Liechtenstein and Switzerland, german-speaking people never use ß - always ss.
A living language changes over time. Only dead languages never change... in 1996 and after, people hated the spelling reform and made fun of it - today, younger people aren't even aware that there was one...

Of course, the mentioned uppercase version of ß (not available on my german keyboard) is still pretty new uncommon - I think it is mainly motivated by typographical reasonings (especially if you use all capitalized letters) - then, depending on the font, a lowercase ß often looks out of place (that's why people often used SS or SZ (!) instead - the latter one is not used anymore)

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by nnnik » 16 Feb 2019, 04:11

First time I hear about ß being turned into SS. Imo it's either a flaw a bug or yeah something like that

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 15 Feb 2019, 21:51

@gregster: ß/ss is mentioned in these links. Also, Turkish i, another classic, is mentioned in the second link.
towupper - cppreference.com
https://en.cppreference.com/w/c/string/wide/towupper
java - How do I make my string comparison case insensitive? - Stack Overflow
https://stackoverflow.com/questions/2220400/how-do-i-make-my-string-comparison-case-insensitive

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 07 Feb 2019, 14:41

- The machine code doesn't use StrLower, in the code example above I use 3 methods.
- These are the results.
case sensitive:
15 RtlCompareMemory

case insensitive:
202 StringLower + RtlCompareMemory
203 SubStr (divide and conquer)
655 Format + RtlCompareMemory
780 machine code

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by nnnik » 07 Feb 2019, 13:01

How does it compare to my code? Also you need to copy the string when using StrLower - this might further decrease the performance of your method.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 07 Feb 2019, 12:54

- I tried writing machine code for this but it wasn't particularly fast. Any suggestions/improvements are welcome.

Code: Select all

;[MCode function]
;GitHub - joedf/MCode4GCC: MCode4GCC is an MCode generator using the GCC Compiler.
;https://github.com/joedf/MCode4GCC

q:: ;string compare case-insensitive Unicode get position
;VarSetCapacity(x, 20100100*2+2)
;Loop, 20100100
;	x .= "a"
x := StrReplace(Format("{:20100100}", ""), " ", "a")
y := x
x .= "A"
y .= "a"

;NumPut(Ord("z"), &x, 10000000, "UShort")

Clipboard .= "`r`n" "BENCHMARK TEST:"
vSize := StrLen(x)*2
MsgBox, % "vars ready"

;case-sensitive comparison
vTickCount := A_TickCount
vRet := DllCall("ntdll\RtlCompareMemory", Ptr,&x, Ptr,&y, UPtr,vSize, UPtr)
Clipboard .= "`r`n" (A_TickCount - vTickCount)
MsgBox, % vRet " " (vRet = vSize)

;case-insensitive comparison
vTickCount := A_TickCount
StringLower, x, % x
StringLower, y, % y
vRet := DllCall("ntdll\RtlCompareMemory", Ptr,&x, Ptr,&y, UPtr,vSize, UPtr)
Clipboard .= "`t" (A_TickCount - vTickCount)
MsgBox, % vRet " " (vRet = vSize)

;case-insensitive comparison
pFuncToWUpper := DllCall("kernel32\GetProcAddress", Ptr,DllCall("kernel32\GetModuleHandle", Str,"msvcrt", Ptr), AStr,"towupper", Ptr)
pFunc := MCode("2,x86:VVdWU4PsHItEJDiLbCQ0i1wkPIXAdDMx/+sOkI10JgCDxwE5fCQ4dCGLRCQwD7cEeIkEJP/TicYPt0R9AIkEJP/TOcZ02ol8JDiLRCQ4g8QcW15fXcM=,x64:QVZBVUFUVVdWU0iD7CBFhcBJicxJidVFicZMic50MkGNaP8x20iDxQHrDg8fRAAASIPDAUg53XQYQQ+3DFz/1kEPt0xdAInH/9Y5x3TiQYneRInwSIPEIFteX11BXEFdQV7D")
vTickCount := A_TickCount
vRet := DllCall(pFunc, Ptr,&x, Ptr,&y, UInt,vSize/2, Ptr,pFuncToWUpper, "Cdecl")
Clipboard .= "`t" (A_TickCount - vTickCount)
MsgBox, % vRet " " (vRet = vSize/2)
return

;e.g. results
;15	203	780
;31	203	780
;15	202	764
return

/*
unsigned int customstrcmpi(unsigned short* str1, unsigned short* str2, unsigned int count, int _cdecl(*MyFunction)(int))
{
	for (unsigned int i = 0; i < count; ++i)
	{
		//if (str1[i] != str2[i])
		if ((*MyFunction)(str1[i]) != (*MyFunction)(str2[i]))
		{
			count = i;
			break;
		}
	}
	return count;
}
*/
- I fixed the 'call MessageBox' example (at the top of this page), here:
C++: TDM-GCC: error with bool - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=23&t=59979&p=262531#p262531

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by SOTE » 05 Feb 2019, 02:05

User wrote:
31 Jan 2019, 18:58
Wow, now I am really surprised!

I wrote "Is()" function (click here) for AutoHotKey just to test speed! (which is really slow, it takes 14000 milliseconds (14 seconds) to compare 2 strings of ~= 20 megabytes each!)

I decided to write the same function for JavaScript (almost a clone), and I was expecting it to be 10x to 20x slower than "Is()" function from AHK!

Guess what, "Is()" function from JavaScript takes only 741 milliseconds (less than 1 second) to compare 2 strings of ~= 20 megabytes each!
Speed of AutoHotkey 3X faster than your JavaScript example. 235 milliseconds to your 741 milliseconds. Improved script by nnnik.
Image

It's quite telling that you ignored the request and improved script by nnnik.
@User then again I posted an example which is extremly fast.
Could you implement the same algorythm in javascript to see it's speed?
Which begs the question, how fast is fast enough? Wouldn't it depend on what the script is being used for and if the user is satisfied that the script accomplishes what they needed? The unsatisfied user is free to improve their script (however they see fit), add requests to update the AutoHotkey source code, seek to mix in code from other programming languages, or use other programming languages, but let's be clear that's an individual decision and based on their problem.

Code: Select all

x := StrReplace(Format("{:20100100}", ""), " ", "a")
y := x . "A"
x .= "B"
SetBatchLines, -1
qSortErrorLookup(x, y)
qSortErrorLookup(x, y)
qSortErrorLookup(x, y)
;a few dry runs
start := A_TickCount
difference := qSortErrorLookup(x, y)
total := A_TickCount - start
Msgbox % Clipboard := "Found difference at character position: " . difference . "`ntook " . total . " ms"

;Found difference at character position: 20100101
;took 156 ms
;Found difference at character position: 20100101
;took 141 ms
;Found difference at character position: 20100101
;took 172 ms

qSortErrorLookup(byref string1, byref string2, partCount := 2) {
	Local
	if (string1 = string2) {
		return false
	}
	
	cLeftBorder := 1
	cLen := max(strLen(string1), strLen(string2))
	loop {
		stepSize := (cLen)/partCount
		leftBorder := cLeftBorder
		loop %partCount% {
			leftB := round(leftBorder)
			len := Round((leftBorder+=stepSize)-leftB)
			if (subStr(string1, leftB, len) != subStr(string2, leftB, len)) {
				if (len = 1)
					return leftB
				cLeftBorder := leftB
				cLen := len
				break
			}
		}
	}
	return false
}

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by User » 04 Feb 2019, 11:36

tank wrote:
04 Feb 2019, 09:36
Comparing ECMA speed which has been optimized for 30+ years and AHK is both idiotic and trollish. Comparing speed of a compiled language to an interpreted one is similarly idiotic and trollish. What honestly is your point? AHK is an automation language. Unless one of you is an expert at RPA like I am, i doubt your competent to compare automation language performance. As automation tools go, i dont know of a faster one than AHK( i will admit to not knowing EVERYTHING). The bottleneck with automation languages is however the speed of the desktop application or browser page being automated. in this case automation language speed is nearly irrelevant.

AHK is only suitable as a generalized scripting language because of it's ease to learn and use. Otherwise i would rather Python or ECMA.

I am tempted to lock this debate but i am honestly curious how stupid it can get.
"Unless one of you is an expert at RPA like I am" (Haha! Lol!)

Hehe, go on and lock this thread! (I'm so afraid of your stupidity ...!) Image

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by User » 04 Feb 2019, 10:10

SOTE wrote:
04 Feb 2019, 06:59
My friend, it's clear here that you are a troll trolling all the time on this matter and it is even more clear that you have big problems in understand things! (thus the reason why you are trolling!)

Listen Mister troll,

- People use AHK and others scripting languages in order to write simple, short and readable codes! (Fact! You argue this because you are a troll!)

- AHK loop is slow to very slow, so people are automatically forced to write complex, longer and unreadable codes in order to avoid it! (Fact! You argue this because you are a troll!)

If people are forced to write complex, longer and unreadable codes in order to make AHK loop a little bit more efficient, well, there is no point to use AHK anymore in what concerns loop (in which is needed most of the time)!

Worst, there are scripting languages out there that do real compilation, like Javascript for example (in which for(;;) loop is 19x faster than AHK loop), allowing people to write simple, short and readable codes without worrying about loop iteration!

And my friend Mister troll, remember that, optimizations can be applied to any languages! Yes, I can apply optimizations to Javascript for example by writing complex, longer and unreadable codes, in which makes AHK lags behind even more!

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by tank » 04 Feb 2019, 09:36

Comparing ECMA speed which has been optimized for 30+ years and AHK is both idiotic and trollish. Comparing speed of a compiled language to an interpreted one is similarly idiotic and trollish. What honestly is your point? AHK is an automation language. Unless one of you is an expert at RPA like I am, i doubt your competent to compare automation language performance. As automation tools go, i dont know of a faster one than AHK( i will admit to not knowing EVERYTHING). The bottleneck with automation languages is however the speed of the desktop application or browser page being automated. in this case automation language speed is nearly irrelevant.

AHK is only suitable as a generalized scripting language because of it's ease to learn and use. Otherwise i would rather Python or ECMA.

I am tempted to lock this debate but i am honestly curious how stupid it can get.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by nnnik » 04 Feb 2019, 08:27

You use strings that are static values. You cannot use static values in MCode - it might cause issues.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 04 Feb 2019, 08:21

@nnnik: Can you see why the following code isn't working? The next step would be to replace MessageBoxW with towupper.

Code: Select all

;C++: C++ to machine code via TDM-GCC - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=23&t=49554
;MCode Tutorial (Compiled Code in AHK) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=32

q:: ;test call MessageBox
pFuncMessageBox := DllCall("kernel32\GetProcAddress", Ptr,DllCall("kernel32\GetModuleHandle", Str,"user32", Ptr), AStr,"MessageBoxW", Ptr)
DllCall(pFuncMessageBox, Ptr,0, Str,"prompt", Str,"title", UInt,0)
pFunc := MCode("2,x86:dABpAHQAbABlAAAAcAByAG8AbQBwAHQAIAAxAAAAcAByAG8AbQBwAHQAIAAyAAAAcAByAG8AbQBwAHQAIAAzAAAAAABTg+wYi1wkIMdEJAwAAAAAx0QkCAAAAADHRCQEDAAAAMcEJAAAAAD/04PsEMdEJAwAAAAAx0QkCAAAAADHRCQEHgAAAMcEJAAAAAD/04PsEMdEJAwAAAAAx0QkCAAAAADHRCQEMAAAAMcEJAAAAAD/04PsEIPEGFvD,x64:dABpAHQAbABlAAAAcAByAG8AbQBwAHQAIAAxAAAAcAByAG8AbQBwAHQAIAAyAAAAcAByAG8AbQBwAHQAIAAzAAAAAAAAAAAAAAAAAAAAAABTSIPsIEUxyUyNBQAAAABIjRUMAAAASInLMcn/00UxyTHJTI0FAAAAAEiNFR4AAAD/00yNBQAAAABIjRUwAAAARTHJMclIidhIg8QgW0j/4A==")
DllCall(pFunc, Ptr,pFuncMessageBox, "Cdecl")
SoundBeep
return

/*
void callmsgbox(int _stdcall(*MyFunction)(void*,short*,short*,unsigned int))
{
	//MessageBoxW(0, L"prompt", L"title", 0);
	(*MyFunction)(0, L"prompt 1", L"title", 0);
	(*MyFunction)(0, L"prompt 2", L"title", 0);
	(*MyFunction)(0, L"prompt 3", L"title", 0);
	return;
}
*/

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by SOTE » 04 Feb 2019, 06:59

User wrote:
03 Feb 2019, 22:03
SOTE wrote:
03 Feb 2019, 11:11
Hehe! You are the only troll trolling here anyway!

Who is here ignoring that AutoHotkey can solve problems differently?

Who said that other viable solutions to increase performance can't be used in AHK?

Fact: AHk loop is slow! (You argue this because you are a troll!)

loop is a practical solution for any language, but in AHK it is too slow in such a way that forces people to write complex\longer\unreadable codes in order to avoid it!

My friend, stop trolling ok?
Since your original post, notice that a number of people have submitted code that addresses your non real world claims against AutoHotkey. The impression that you are giving is that you don't want nor care for an AutoHotkey solution, but rather stick with your bias and attempt to crap on the scripting language for personal enjoyment (thus troll).
I didn't test your code, but I think you should remove "Local" statement (because not everybody uses AHK 1.1.27+)
So people can't update their version of AutoHotkey? If a solution is to be found in a later version, unless that person has a good or particular reason for doing so, they are free to upgrade. The majority would likely upgrade, if it was going to actually solve their problem.
Saying that, the matter here is not how to make "Is()" function more efficient anymore!
This gives the impression that you don't want changes concerning the "Is()" function, because it will reduce the time difference or show AutoHotkey as being faster (which the other scripts are arguably doing).
Of course "Is()" function can be made more efficient in AHK by avoiding less loop iterations in many ways!
If the function can be made more efficient, and you are agreeing with such, then why wouldn't an AutoHotkey programmer not allow for the use of various options? It appears that you don't want the use of such options.
But there are a lot of situations where heavy loop iteration is a must and can't be avoided! (so in these situations, AHK is not recommended!)
This statement is debatably wrong. If there are other options besides a heavy loop iteration, then the AutoHotkey programmer should be free to choose such. It's not for you or me to impose on people what they should choose. As mentioned, they can use different coding methods, add machine code, or even put other programming/scripting languages into the script.

Lastly, it doesn't seem like you want a solution or would rather prevent others from thinking up workarounds that address this "made up problem" that isn't an actual project or problem.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by User » 03 Feb 2019, 22:03

SOTE wrote:
03 Feb 2019, 11:11
Hehe! You are the only troll trolling here anyway!

Who is here ignoring that AutoHotkey can solve problems differently?

Who said that other viable solutions to increase performance can't be used in AHK?

Fact: AHk loop is slow! (You argue this because you are a troll!)

loop is a practical solution for any language, but in AHK it is too slow in such a way that forces people to write complex\longer\unreadable codes in order to avoid it!

My friend, stop trolling ok?

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by nnnik » 03 Feb 2019, 15:53

But you have to write too much.(Yes I'm lazy)
Actually you dont need this part: ,"int",1,"cdecl") We could create a caller function that does the thing we want.
In order to use the stdcall convention(Wich is the standard for the DllCall function) you have to put a _stdcall before the function.
Your C++ code will look like this:

Code: Select all

unsigned int MyFunction(unsigned int a,unsigned int b)
{
if (a>0)  
return MyFunction(a-1,b*a);
else
return b;
}

unsigned int _stdcall MyFunctionCaller(unsigned int a)
{
return MyFunction(a,1);
}
The result:

Code: Select all

MyFunction := MCode("2,x86:i0wkBItEJAiFyXQKjWQkAA+vwUl1+sM=,x64:hcl0Bw+v0f/JdfmLwsM=")
MyFunctionCaller := MCode("
(LTrim Join
2,x86:i0QkBIXAdA5QSFDoAAAAAIPECMIEALgBAAAAwgQA,x64:i9GFyXQH/8npAAAAALgBAAAAww==
)")
Msgbox % DllCall(MyFunctionCaller,"uint",3)
But the Messagebox is empty. :o
No we didn't make a mistake. The Problems name is MCode:
OK Lets imagine you have a AHK script, but you have to call every function by its position: (e.g. call Char nr. 144.).
This is where your function starts at Char 144.
Now lets imagine we put some new code in front of your function.
Your function will be moved backwards e.g. 20 Chars.
If you don't change the starting nr. of your function you wont be able to call it properly.
In Machine Code it is exactly like this:
A function is called by calling the start address of the function.
But the function is added after the AHK stuff.
That's why your function is calling something else. This leads to errors.
The compiler is able to tell you the starting address it expected:
(Note: Not for 64 bit PCs)

Code: Select all

/*
unsigned int MyFunction(unsigned int a,unsigned int b)
{
if (a>0)  
return MyFunction(a-1,b*a);
else
return b;
}

unsigned int MyFunctionaddress()
{
return (unsigned int)(&MyFunction);
}
*/
MyFunction := MCode("2,x86:i0wkBItEJAiFyXQKjWQkAA+vwUl1+sM=,x64:hcl0Bw+v0f/JdfmLwsM=")
MyFunctionaddress := MCode("2,x86:uAAAAADD,x64:SI0FAAAAAMM=")
Msgbox % "The expected Address of the function is :" DllCall(MyFunctionaddress)
Msgbox % "The actual address of the function is :" MyFunction
So you cant call functions in a normal way. :evil:
So what do we do now :?:
The answer is function pointers. :!:...:?:
Functionpointers are documented here:
http://www.cplusplus.com/doc/tutorial/pointers/
Please read through the site mentioned before reading further.


To call our function in MCode we have to give it the pointer to our function.

Code: Select all

unsigned int MyFunction(unsigned int a,unsigned int b)
{
if (a>0)  
return MyFunction(a-1,b*a);
else
return b;
}

unsigned int _stdcall MyFunctionCaller(unsigned int a,unsigned int(*MyFunction)(unsigned int,unsigned int) )
{
return (*MyFunction)(a,1);
}
Results in:

Code: Select all

MyFunction := MCode("2,x86:i0wkBItEJAiFyXQKjWQkAA+vwUl1+sM=,x64:hcl0Bw+v0f/JdfmLwsM=")
MyFunctionCaller := MCode("2,x86:i0QkBGoBUP9UJBCDxAjCCAA=,x64:SIvCugEAAABI/+A=")

When we call the new function we also have to add the Function pointer.

Code: Select all

MyFunction := MCode("2,x86:i0wkBItEJAiFyXQKjWQkAA+vwUl1+sM=,x64:hcl0Bw+v0f/JdfmLwsM=")
MyFunctionCaller := MCode("2,x86:i0QkBGoBUP9UJBCDxAjCCAA=,x64:SIvCugEAAABI/+A=")
Msgbox % DllCall(MyFunctionCaller,"uint", 3,"UPtr",MyFunction)
6 was expected and if you did everything right it should be the result.
Same thing applies to any function you need to call.

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by jeeswg » 03 Feb 2019, 15:13

- @nnnik: I've compiled before with TDM-GCC, i.e. joedf's script.
- In the tutorial, I didn't see any mention of include (a problem which user 'quantum' mentioned in another thread) or types (incompatibility between Visual Studio and TDM-GCC).
- A machine code function that uses the Winapi MessageBox function would be a good example.
- I did see what looks like a script for compiling via Visual Studio, is that what you had in mind?

Re: JavaScript vs AutoHotKey (Simple Speed Test)

Post by nnnik » 03 Feb 2019, 14:54

@jeeswg you might be interested in this topic:
https://www.autohotkey.com/boards/viewtopic.php?f=7&t=32

@swagfag:
even if js is jit compiled it is not as fast as compiled languages. It is slower by a rather large margin.
Also the fact that it is faster is not as important as the information how much faster it is.

Top