jeeswg's benchmark tests

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's benchmark tests

04 Oct 2017, 17:39

I will add to this collection of benchmark tests periodically.

ASSUME ALWAYS:
The benchmark test examples work best with the following settings, and require the QPC function.

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


I welcome any other suggestions re. conditions for a good benchmark test.

Links:
[note: I have two posts on Page 5 which are included in this thread also]
How to optimize the speed of a script as much as possible. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6413
How to optimize the speed of a script as much as possible. - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/94455-how-to-optimize-the-speed-of-a-script-as-much-as-possible/

==================================================

BENCHMARK TESTS

[STRINGS] 4 REGEXMATCH / REGEXREPLACE TESTS
[this post]

STRING / ARRAY - CHECK IF LIST CONTAINS ITEM
https://autohotkey.com/boards/viewtopic.php?p=192029#p192029

[STRINGS] REPEAT STRING: LOOP V. VARSETCAPACITY
[STRINGS] PARSE LINES: LOOP WITH OMITTED CHARACTERS V. STRREPLACE
[STRINGS] INSTR: CASE SENSITIVE V. CASE INSENSITIVE
https://autohotkey.com/boards/viewtopic.php?p=194669#p194669

[STRINGS] RTRIM V. STRREPLACE
[STRINGS] TRUNCATE STRING
https://autohotkey.com/boards/viewtopic.php?p=194672#p194672

STRINGS: SUBSTR: CROP FIRST CHARACTER V. CROP LAST CHARACTER
https://autohotkey.com/boards/viewtopic.php?p=195571#p195571

NUMBER: SWAP BYTES (e.g. 0x11223344 to 0x44332211)
https://autohotkey.com/boards/viewtopic.php?p=194681#p194681

[CLIPBOARD] CLIPWAIT / DLLCALL - CHECK IF CLIPBOARD EMPTY
https://autohotkey.com/boards/viewtopic.php?p=190278#p190278

[WINDOWS] WINGETPOS V. GETWINDOWRECT (BUILT-IN COMMANDS/FUNCTIONS V. DLLCALL)
[WINDOWS] WINGET ID: A (ACTIVE WINDOW) V. 'AHK_CLASS NOTEPAD'
[WINDOWS] TWO-WAY COMPATIBILITY FUNCTIONS: WINGETPOS COMMAND V. CUSTOM WINGETPOS FUNCTION
https://autohotkey.com/boards/viewtopic.php?p=194662#p194662

[LOOPS] LOOPED CODE V. HARDCODED CODE
https://autohotkey.com/boards/viewtopic.php?p=194666#p194666

==================================================

4 REGEXMATCH / REGEXREPLACE TESTS

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



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



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



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

Last edited by jeeswg on 01 Feb 2018, 10:44, edited 11 times in total.
User avatar
jNizM
Posts: 2317
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: jeeswg's benchmark tests

05 Oct 2017, 00:47

QueryPerformanceFrequency should not be called every time in a loop. It's enough if you call it once at scripts loadtime.
global InitQPC := DllCall("QueryPerformanceFrequency", "Int64P", QPF)
[AHK] 1.1.28.02 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
RUNIE
Posts: 275
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: jeeswg's benchmark tests

08 Oct 2017, 09:48

I use a pretty simple Timer class:

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



Timer.Start(id) starts a timer, Timer.Stop(id) stops a timer and returns the timers result.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

23 Dec 2017, 11:05

CLIPWAIT / DLLCALL - CHECK IF CLIPBOARD EMPTY

Based on:
Clipboard Bug, copying a file from a compressed folder (zip) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=14&t=41769&p=190237#p190237

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

User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

01 Jan 2018, 10:33

STRING / ARRAY - CHECK IF LIST CONTAINS ITEM

Regarding:
conversion logic, v1 = -> v1 := -> v2, two-way compatibility - Page 6 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=27069&start=100

Should ControlGetList (possibly 'ControlGetItems' in future) return an array, an LF-delimited list, or provide an option to choose. An array seems like the natural default, however, an option to return an LF-delimited list seems sensible (for faster searching).

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

iPhilip
Posts: 273
Joined: 02 Oct 2013, 12:21

Re: jeeswg's benchmark tests

02 Jan 2018, 01:31

RUNIE wrote:I use a pretty simple Timer class:

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



Timer.Start(id) starts a timer, Timer.Stop(id) stops a timer and returns the timers result.
There are a couple of errors in the class as posted:
  1. Debug.Timer.Init() should be Timer.Init()
  2. The variable Timer in the function Current() should be renamed to something else as it resets the class object.
The version below incorporates the above 2 changes:

Code: [Select all] [Expand] [Download] (Timers.ahk)GeSHi © Codebox Plus

Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
User avatar
RUNIE
Posts: 275
Joined: 03 May 2014, 14:50
GitHub: Run1e

Re: jeeswg's benchmark tests

03 Jan 2018, 03:22

Yeah, that's an old version I barely even used. This is what I use now:

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

User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 10:37

WINGETPOS V. GETWINDOWRECT (BUILT-IN COMMANDS/FUNCTIONS V. DLLCALL)

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


==================================================

WINGET ID: A (ACTIVE WINDOW) V. 'AHK_CLASS NOTEPAD'

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



==================================================

TWO-WAY COMPATIBILITY FUNCTIONS: WINGETPOS COMMAND V. CUSTOM WINGETPOS FUNCTION

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

User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 11:16

LOOPED CODE V. HARDCODED CODE

Prompted by this post:
How to genuinely compile a script? Is there any "loop" faster alternative? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39925

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

just me
Posts: 5331
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: jeeswg's benchmark tests

16 Jan 2018, 11:21

Hi jeeswg,

#Include will be processed only once (see #Include / #IncludeAgain).

Edit: Sorry, must have been blind for a moment.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 11:31

STRINGS

REPEAT STRING: LOOP V. VARSETCAPACITY
PARSE LINES: LOOP WITH OMITTED CHARACTERS V. STRREPLACE
INSTR: CASE SENSITIVE V. CASE INSENSITIVE
How to optimize the speed of a script as much as possible. - Page 5 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6413&p=132230#p132230

REVERSE LIST: VARIABLES V. ARRAYS
How to optimize the speed of a script as much as possible. - Page 5 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6413&p=140139#p140139

==================================================

@just me: Haha sorry, I fixed it, it was only incorrect momentarily.
Last edited by jeeswg on 20 Jan 2018, 14:54, edited 2 times in total.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 11:49

STRING TESTS

RTRIM V. STRREPLACE

Prompted by this post:
Base64PNG_to_HICON() : Uses native PNG Decompression (requires WIN VISTA and later) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=36636&p=168792#p168792

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



==================================================

TRUNCATE STRING

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

Last edited by jeeswg on 17 Jan 2018, 06:53, edited 2 times in total.
User avatar
derz00
Posts: 478
Joined: 02 Feb 2016, 17:54
GitHub: derz00
Location: Middle of the round cube

Re: jeeswg's benchmark tests

16 Jan 2018, 12:06

Hi jeeswg, You might have missed this:
jNizM wrote:QueryPerformanceFrequency should not be called every time in a loop. It's enough if you call it once at scripts loadtime.
global InitQPC := DllCall("QueryPerformanceFrequency", "Int64P", QPF)
try it and see
...
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 12:12

- @derz00: AFAICT I've called it once in every example (and I checked again just now). There may have been an example where I used it multiple times that I since corrected. If you can spot any errors of any kind, do post them. Thanks.
- QueryPerformanceFrequency at the start of each example.
- QueryPerformanceCounter used twice for each test, to get the start/end times.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

16 Jan 2018, 12:47

NUMBER: SWAP BYTES (e.g. 0x11223344 to 0x44332211)

Prompted by this post:
LoadPicture() from variable - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=39002&p=181462#p181462

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

Helgef
Posts: 2898
Joined: 17 Jul 2016, 01:02
Contact:

Re: jeeswg's benchmark tests

17 Jan 2018, 06:48

Hello, thanks for sharing your tests :wave:.
It's enough if you call it once at scripts loadtime.

:thumbup:. Although, global InitQPC := DllCall("QueryPerformanceFrequency", "Int64P", QPF) is probably a mistake ;)
- QueryPerformanceFrequency at the start of each example.

You have it in the hotkey routine, not in the auto-exec. That is a minor offense, littering the examples with

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

DllCall("QueryPerformanceCounter", Int64P,vQPC1)
; ...
DllCall("QueryPerformanceCounter", Int64P,vQPC2)
MsgBox, % Clipboard := (((vQPC2-vQPC1)/vQPF)*1000)

instead of using a function is more annoying, for visual reasons, and also because you set the clipboard. And the q:: is annoying too :P. It would be convenient if you included the ASSUME ALWAYS: code.

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

JEE_StrTruncate

Where is it?

Cheers.
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

17 Jan 2018, 06:59

- Re. 'assume always', what about what's convenient for me? The point is I'm trying to keep everything as uncluttered and stand-alone as possible, by keeping everything self-contained and avoiding the use of functions. Is there any problem re. *functionality*, if calling QueryPerformanceFrequency in every hotkey subroutine? (A separate but related point, why would doing Random new seed every time, cause a problem?)
- Come on, this is easy street: DllCall("QueryPerformanceCounter", Int64P,vQPC1), that doesn't need wrapping.
- This isn't too bad: MsgBox, % Clipboard := (((vQPC2-vQPC1)/vQPF)*1000).
- And q:: is cool, very cool.
- I try and make everything so you can just copy and paste to the bottom of your temporary testing script, and not need to flood your PC with individual separate scripts.
- JEE_StrTruncate has now been added above, thanks for mentioning it.
User avatar
nnnik
Posts: 2790
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: jeeswg's benchmark tests

17 Jan 2018, 07:04

I think this doesn't belong into the tutorials section as you only provide scripts and no explination or discussion as to which method is better and you don't even deliver any results of that tests.
It's like your saying "run this script and think about the results" something that is an unfairness to all the tutorials that were created through hard work.
Recommends AHK Studio
User avatar
jeeswg
Posts: 4277
Joined: 19 Dec 2016, 01:58
Location: UK

Re: jeeswg's benchmark tests

17 Jan 2018, 07:19

nnnik wrote:I think this doesn't belong into the tutorials section as you only provide scripts and no explination or discussion as to which method is better and you don't even deliver any results of that tests.
It's like your saying "run this script and think about the results" something that is an insult to all the people that try very hard to create their tutorials.

- @nnnik: This tutorial is perfectly acceptable as a tutorial. It's about explaining to people how to speed up their scripts. It is essentially an extension of this tutorial:
How to optimize the speed of a script as much as possible. - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=6413
- Some of the examples do provide results, otherwise at least a summary. Also, I may furnish some of them with more information, although I was interested in getting feedback on the examples, before publishing information in full. I like to do things thoroughly, sometimes that involves double-checking things.
- Btw re. explanations of why one method is better than another, anyone is welcome to contribute information, that I will then review and possibly incorporate. If I had more detailed behind-the-scenes information for some of these scripts, I would write an explanation. Can you help with some of these examples? Sometimes the explanation is simply: RegEx is slow, or, this approach happens to be slightly slower.
- On about half-a-dozen of my threads, you've appeared and stated that there is a problem, and not elaborated, therefore helping neither me, nor the readers. Please return to those pages and complete your posts, at present, those posts are an insult to all the people that try very hard to contribute to or learn from the forum. Btw I should warn you that your tutorials are not above criticism, there are a lot of criticisms that I could expand upon. Also, perhaps if you tried to think in a less linear way, and in a more associative way, you'd appreciate some of the things that I'm trying to do here, instead of jumping in with unwarranted criticisms. It's as though you're trying to find fault where there isn't any, instead of respecting and appreciating the author. I previously wrote to you a direct message, in a spirit of friendship, and welcome cooperating with you on projects in the future.

[EDIT:] Ah, you've toned down your post a bit, (although I don't see any Edit notification, perhaps that's an admin privilege,) to which I'll say, I looked over your GitHub scripts recently, looking to see if you'd done any nice scripts, and I enjoyed your 3D maze script, very nice.
User avatar
boiler
Posts: 2369
Joined: 21 Dec 2014, 02:44

Re: jeeswg's benchmark tests

17 Jan 2018, 08:56

jeeswg wrote:It's about explaining to people how to speed up their scripts.
I don't see it explaining anything. It's providing tools for people to use if they're interested in comparing the speed of different approaches. Even if or when it includes results, I don't see that as a tutorial.

I agree that this thread should be moved. Scripts and Functions seems to be the most appropriate destination. I am one that likes the Tutorials sub-forum to be fully "read" so it's highlighted when there is a new tutorial. Updates to this thread cause me to open it just to clear the "unread" indication for the sub-forum.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest