[Testers Needed] Please give me feedback on which method is the fastest

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jNizM
Posts: 2120
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 05:06

Since I dont know c++, I'm not sure if this is correct ^^

Code: [Select all] [Download] GeSHi © Codebox Plus

int IsBetween( int num, int low, int high, int loops )
{
int found = 0;
int diff = ( high - low ) + 1;

for( int i = 1; i <= loops; i++ )
if ( ( num - low ) < diff )
found++;

return found;
}

The return with 2073600 is correct, so it loops really 2073600 times

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Code: [Select all] [Download] GeSHi © Codebox Plus

0.324321
0.432744
0.369919
0.000006 ; mcode
[AHK] 1.1.25.02 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.1198) x64
My GitHub Profile | Donations are appreciated if I could help you
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 05:24

Try to compile it without any opimasation flags jNizM
User avatar
jNizM
Posts: 2120
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 05:26

MyFunction := MCode("2,x64:VUiJ5UiD7BCJTRCJVRhEiUUgRIlNKMdF/AAAAACLRSArRRiDwAGJRfTHRfgBAAAAi0X4O0UofxWLRRArRRg5RfR+BINF/AGDRfgB6+OLRfxIg8QQXcOQkJCQkJCQkJCQ")

Code: [Select all] [Download] GeSHi © Codebox Plus

0.310448
0.398040
0.351051
0.004427 (mcode)
[AHK] 1.1.25.02 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.1198) x64
My GitHub Profile | Donations are appreciated if I could help you
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 05:36

Your first code was probably optimised to do one check and either return 0 or loops.
User avatar
Nextron
Posts: 963
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 06:41

It looks like (repeatedly) setting the variable to true about doubles the time execution takes. Would breaking out of the loop be beneficial?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

The more I know:
The more I know,
I know nothing.
User avatar
Blackholyman
Posts: 1181
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 06:44

Nice tests :) happy to see all the results

but for the math to work the first value needs to be unsigned or else you will not get the correct result when testing with values that are NOT between the high and low end

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



the over all idea is still a pre test to see if this comparison really seems faster before trying it with the Autohotkey pixel/image search code as i believe that those functions does that comparison so many times that something as simple as making the if quicker can give a useful speed boost with very little source editing

@Nextron well it will not simply set the variable :) but sure if it was simply a test to make the loop faster, then sure :)
User avatar
jNizM
Posts: 2120
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 07:53

The unsinged conversion needs to much time.. without the results are wrong

Tested with 4K (3840x2160)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Download] GeSHi © Codebox Plus

Timer 1:
1.209854 (4147201)

Timer 2:
1.105824 (4147201)

Timer 3:
0.014799 (4147201)


Code: [Select all] [Download] GeSHi © Codebox Plus

int IsBetween(unsigned int low, unsigned int high, int loops)
{
int found = 0;
unsigned int diff = (high - low) + 1;

for(int i = 1; i <= loops; i++)
if ((unsigned)(i - low) < diff)
found++;

return found;
}

Not sure if cpp is correct =)
[AHK] 1.1.25.02 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.1198) x64
My GitHub Profile | Donations are appreciated if I could help you
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 08:35

@Blackholyman, if you have the numbers on the unsigned form from the beginning the gain is from skipping the && number <= upper, the acutal Y<Q is not quicker than number <= upper, if you cannot put the number on the unsigned form quicker than && number <= upper, forget about it.

Also in the context of the code you posted here, I would start optimising anything but the compairson. ;)
SirRFI
Posts: 105
Joined: 25 Nov 2015, 16:52

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 17:17

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I used the code as seen in first post at time of posting this one. Second method seems to be worse everytime.
Last edited by SirRFI on 16 Jun 2017, 17:54, edited 1 time in total.
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

16 Jun 2017, 17:35

Code: [Select all] [Download] (Untitled.txt)GeSHi © Codebox Plus

First check method:
If number 200 is between 50-100 is true and it took 0.488592

Second check method:
If number 200 is between 50-100 is false and it took 0.475797

:crazy: The test now seems broken for number > upper. There was an example earlier where 200 gave the correct result.
User avatar
Blackholyman
Posts: 1181
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 02:19

thanks for all the info...

i just tried the code from my OP and it still seems to work just fine

Code: [Select all] [Download] GeSHi © Codebox Plus

First check method:  If number 200 is between 50-100 is false and it took 0.284955
Second check method: If number 200 is between 50-100 is false and it took 0.506049

First check method: If number 77 is between 50-100 is true and it took 0.514196
Second check method: If number 77 is between 50-100 is true and it took 0.767994

First check method: If number 44 is between 50-100 is false and it took 0.281468
Second check method: If number 44 is between 50-100 is false and it took 0.274572


@Helgef what test example did you test?

Note: I had made a typo in my OP where the check for building the text string for the msgbox's second methods "true/false" text was done on the variable that was set by the first method as pointed out by evilC here: https://autohotkey.com/boards/viewtopic ... 39#p153839
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 03:07

I ran the code in your first post. Copy-paste, result,

Code: [Select all] [Download] (Untitled.txt)GeSHi © Codebox Plus

First check method:
If number 200 is between 50-100 is true and it took 0.486039

Second check method:
If number 200 is between 50-100 is false and it took 0.480104

It seems to work on AHK 32bit though, I run 64 bit by default.

Cheers.
User avatar
Blackholyman
Posts: 1181
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 03:29

well the method of making the value unsigned is an old one i copied...

maybe if you replace Y := NumGet( NumPut( Y, Var:="ABCD" )-4, 0,"UInt" ) with Y := Format("{1:u}", Y) it will work for both 32b and 64b (it does for 32b), I don't have access to 64b here so can't test right now
Helgef
Posts: 1649
Joined: 17 Jul 2016, 01:02

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 03:54

It seems to work on 64 bit that way :thumbup:
just me
Posts: 4301
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 04:06

Y := NumGet( NumPut( Y, Var:="ABCD" )-4, 0,"UInt" ) should be

Code: [Select all] [Download] GeSHi © Codebox Plus

Y := NumGet( NumPut( Y, Var:="ABCD", "Int" )-4, 0,"UInt" )
; or
Y := NumGet( NumPut( Y, Var:="ABCD" )-A_PtrSize, 0,"UInt" )
to work on 64-bit.
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
User avatar
jNizM
Posts: 2120
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 04:14

Should this not work too (not tested with 32-Bit)? Y := Y & 0xFFFFFFFF (see my example https://autohotkey.com/boards/viewtopic ... 57#p154257 )
[AHK] 1.1.25.02 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.1198) x64
My GitHub Profile | Donations are appreciated if I could help you
just me
Posts: 4301
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 05:53

@jNizM:
Of course!

@Blackholyman:
After some testing I think your benchmark approach is wrong. In a real application number would get a new value for each comparison. So the calculation of Y should be part of the first loop.
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
User avatar
Blackholyman
Posts: 1181
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: [Testers Needed] Please give me feedback on which method is the fastest

19 Jun 2017, 07:00

Yes that may be true.

AHK source code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I was not really trying to test autohotkey's ability in this benchmark more trying to benchmark the 2 if comparisons in the hope that this

Code: [Select all] [Download] GeSHi © Codebox Plus

if (!(found = red >= red_low && red <= red_high
&& green >= green_low && green <= green_high
&& blue >= blue_low && blue <= blue_high
could be reduced to something like this

Code: [Select all] [Download] GeSHi © Codebox Plus

if (!(found = ((unsigned)(red) < red_diff)
&& ((unsigned)(Green) < Green_diff)
&& ((unsigned)(Blue) < Blue_diff)
but do see that a more correct way maybe this

Code: [Select all] [Download] GeSHi © Codebox Plus

if (!(found = ((unsigned)(red - red_low) < red_diff)
&& ((unsigned)(Green - Green_low) < Green_diff)
&& ((unsigned)(Blue - Blue_low) < Blue_diff)
the issue with testing that in AHK code is that any of the methods ("I knew at the time") to make the value of red - red_low unsigned also takes the added time of doing the function call, in the OP code i was hoping to cut that function time out of the benchmark result but do see that this was most likely wrong.

my hope was/is that in c++ (unsigned) is simply a flag, so takes close to no time, where as in ahk it takes some time to do the convert to unsigned

2 examples:
OP code with the math within the timer

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Download] GeSHi © Codebox Plus

First check method:  If number 44 is between 50-100 is false and it took 0.568369
Second check method: If number 44 is between 50-100 is false and it took 0.277781

First check method: If number 88 is between 50-100 is true and it took 0.763220
Second check method: If number 88 is between 50-100 is true and it took 0.757578

First check method: If number 222 is between 50-100 is false and it took 0.589628
Second check method: If number 222 is between 50-100 is false and it took 0.511960


more like what i think is happening in the c++ code

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Code: [Select all] [Download] GeSHi © Codebox Plus

First check method:  If number 44 is between 50-100 is false and it took 0.292560
Second check method: If number 44 is between 50-100 is false and it took 0.292357

First check method: If number 88 is between 50-100 is true and it took 0.534627
Second check method: If number 88 is between 50-100 is true and it took 0.773438

First check method: If number 222 is between 50-100 is false and it took 0.288689
Second check method: If number 222 is between 50-100 is false and it took 0.521938


to me that last example mimics the pixel/image search code better as it is checking the same image pixel ageist many screen pixels

Return to “Ask For Help”

Who is online

Users browsing this forum: Exaskryz, guest3456, Lem2001 and 30 guests