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

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Blackholyman
Posts: 1222
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

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

14 Jun 2017, 08:25

Hello,

I'd like your help :)

Can you try the piece of code below and tell me what the msgbox's tells you (simply press Ctrl+c when the msgbox is displayed to copy the text in it)

I'm trying to find out if one method of determining if an integer is between two integers (inclusive) is faster then the other

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



Do try a few numbers both between and outside the range to see if one if faster then the other

Please let me know what you find :)

PS: Also let me know if you find something that's not working or is off with the way i'm doing this...
Last edited by Blackholyman on 16 Jun 2017, 06:49, edited 1 time in total.
Reason: Code typo
WalkerOfTheDay
Posts: 257
Joined: 24 Mar 2016, 03:01

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

14 Jun 2017, 08:33

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

BoBo
Posts: 1215
Joined: 13 May 2014, 17:15

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

14 Jun 2017, 08:47

---------------------------
_Test37.ahk
---------------------------
First check method:
If number 88 is between 50-100 is true and it took 2.075298

Second check method:
If number 88 is between 50-100 is true and it took 2.792947
---------------------------
OK
---------------------------
User avatar
jNizM
Posts: 2273
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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

14 Jun 2017, 08:55

Should this not be more like this? (Added a third example similar to first example but do the math every time)

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


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

0.371957
0.458114
0.384696
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
IMEime
Posts: 411
Joined: 20 Sep 2014, 06:15

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

14 Jun 2017, 10:06

캡처.jpg
캡처.jpg (24.79 KiB) Viewed 571 times

i7 3.6GHz
AHK 64 Unicode
User avatar
Blackholyman
Posts: 1222
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

14 Jun 2017, 10:21

Thank you for helping :)

@WalkerOfTheDay, @BoBo and @IMEime you seem to be getting something along the same line as me :)

@jNizM

well I think you did an edit after the first time i read your post :) something about the first part of the first method needing to be in the timer :) this i'd say you are right about as below



As to the code in your post now, about doing the every time, this i'm not sure about, I did a few tests on the code you posted and two of the methods did not work the correct way aka assigning true when the magic number is outside the range :(

eksample:

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



the method that works if (number_magic >= number_lower) && (number_magic <= number_upper) was the one i'm trying to beat :)

so with the assignment inside the time it looks like this

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



tests:
First check method:
If number 11 is between 50-100 is false and it took 0.251963

Second check method:
If number 11 is between 50-100 is false and it took 0.242396

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

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

First check method:
If number 133 is between 50-100 is false and it took 0.249932

Second check method:
If number 133 is between 50-100 is false and it took 0.467136


unsure if this answers what you're asking about jNizM please let me know :)
BoBo
Posts: 1215
Joined: 13 May 2014, 17:15

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

14 Jun 2017, 10:28

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

First check method:
If number 1234567890 is between 50-100 is true and it took 2.072417

Second check method:
If number 1234567890 is between 50-100 is true and it took 2.006599


Without any doubt (and any other tranquilizing noobish effort :thumbup: ) I proclaim to have the slowest box east of Covfefe :dance:
Ooops, that wasn't the requested task :shock:

OK, I've to admit that I've added an additional line of real sophisticated code to the script - what might have cost ~1.999999 sec :silent:
ClipBoard := "First check method:`nIf number " number " is between " lower "-" upper " is " (inrange?"true":"false") " and it took " time1 "`n`nSecond check method:`nIf number " number " is between " lower "-" upper " is " (inrange?"true":"false") " and it took " time2
Last edited by BoBo on 14 Jun 2017, 10:33, edited 1 time in total.
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

14 Jun 2017, 10:33

FYI, the code does not check the value of inrange2, it always uses inrange, so if method #2 gets the wrong answer, you would not know:

msgbox % "First check method:`nIf number " number " is between " lower "-" upper " is " (inrange?"true":"false") " and it took " time1 "`n`nSecond check method:`nIf number " number " is between " lower "-" upper " is " (inrange?"true":"false") " and it took " time2
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

14 Jun 2017, 10:48

On my work PC, #1 is quicker (Xeon E5-2630 @ 2.3 Ghz)

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

User avatar
Blackholyman
Posts: 1222
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

14 Jun 2017, 13:45

hehe @BoBo it happens

Thanks @evilC

nice catch :) and you're the first where the first method is also faster when the needle is below the range that is nice to know

@jNizM still hoping to hear more on your take on this :) as i'm not sure if this is truly fast enough to be of real use...
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

14 Jun 2017, 14:39

I wonder if I could make you a C# DLL that would be quicker?
I guess if the code is compiled, not only would it run quicker, but the compiler could potentially optimize it.
I dunno if the overhead of calling a DLL would negate any of those benefits though.
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

14 Jun 2017, 14:59

I keep forgetting you can inline compile... duh.

Here you go, two methods to play with:
(Obviously, both examples require CLR)

Syntax is same for both - IsInRange(number, low, high)

#1
Returns an Int

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



#2
Returns a bool (AHK seems to interpret as -1 for true ?)

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

User avatar
Blackholyman
Posts: 1222
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

14 Jun 2017, 16:19

Hey thank you evilC :)

the idea for all of this comes from me looking at the c++ source of Autohotkey

and in a well known command i fell over something that looked as if it may hold a chance for optimization :)

here is the ahk version of what i was looking at :)

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



^ this is not really working code but it may give you a better idea of what i'm trying to test... i've never worked with C++ so i had the idea to first try it in AHK and see if that worked better and if so try and do it in c++

AHK

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

N_Y := NumGet( NumPut( search_N-N_low, Var:="ABCD" )-4, 0,"UInt" )
N_Q := (N_high-N_low)+1
if (!(N_Y < N_Q))
in_range(search_N)

c++

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

if ((unsigned)(search_N-N_low) <= (N_high-N_low))
in_range(search_N);
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

15 Jun 2017, 04:35

What is this, pixel search?

If you are replicating AHK's C++ source in AHK, then surely you might see quite different results?
AHK's C source will be optimized by the compiler I would guess, but AHK code would not be? So if a certain way of doing the maths runs quicker in AHK, it may not run quicker in C?

If you want the most efficient pixel operations, then why not look around for some highly optimized code, then we can try to make it available from AHK? This looks like it could form the basis of a candidate: https://www.codeproject.com/Articles/61 ... thout-unsa
User avatar
Blackholyman
Posts: 1222
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

15 Jun 2017, 06:33

modified but yes it comes from the pixel/imagesearch source https://github.com/Lexikos/AutoHotkey_L ... .cpp#L5052

And together with this post https://stackoverflow.com/questions/170 ... usive-with

I just wished to test that method out, and to me, it seems that when using the method in Autohotkey it does give a speed improvement, just as the poster doing it in c/c++ says it does for him in he's complied project.
User avatar
evilC
Posts: 3441
Joined: 27 Feb 2014, 12:30

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

15 Jun 2017, 07:55

Yeah, but what happens if you do the same technique in C# and call it from AHK? Is it even quicker?

Also, is the code not giving a fair comparison?

Should QPX( True ) ; Initialise Counter not be before

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

Y := number-lower
Y := NumGet( NumPut( Y, Var:="ABCD" )-4, 0,"UInt" ) ; Convert Y to unSigned Integer
Q := (upper-lower)+1
?
User avatar
Blackholyman
Posts: 1222
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

15 Jun 2017, 08:20

Well Im not sure if calling from C# or submitting the changed c++ on github is better.

As to the numput and numget being inside the timer well kinda but i was only trying to test the speed of the if compaisum

As in c++ it looks as if you simply tell the if to do the if without the sign on the first value if ((unsigned)
User avatar
jNizM
Posts: 2273
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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

16 Jun 2017, 01:22

You can also try mcode =)

and this is what I did in my post
// diff = (end - start) + 1
#define POINT_IN_RANGE_AND_INCREMENT(p, range) ((p++ - range.start) < range.diff)

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

; number_diff := (number_upper - number_lower) + 1    ; for fixed values outside of timer

QPC(True)

number_diff := (number_upper - number_lower) + 1 ; for changing values inside of timer

loop 2073600
if ((number_magic - number_lower) < number_diff)
number_found := true

Timer1 := QPC(False)
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
Helgef
Posts: 2230
Joined: 17 Jul 2016, 01:02
Contact:

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

16 Jun 2017, 04:10

You have to compile the loop to gain a performance vs script. You cannot loop DllCall(.). You need 1 DllCall doing 2M compairisons, not 2M DllCAll doing 1 compairson. :wave:

Return to “Ask For Help”

Who is online

Users browsing this forum: ikrananka, miksica, Thorx and 49 guests