Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[object] QPX() - test how fast the code runs


  • Please log in to reply
10 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

WARNING: This is old thread. It is continued here.
[object] QPX()
- tests how fast functions and/or subroutines run and diplays results in a window. When you are in doubt which coding approach/style will do specific job fastest, this test will give you the answer.
- no globals, encapsulated
- simple usage
- based on SKAN's QPX() function
 
QPX window preview. Click here to see explanation.
QPX%20window%20preview.png
Left edit = Summary with average run time for each item in test collection + percentages + fastest tested item mark (<<)
Right edit = Details with minimum (fastest), average, maximum (slowest) and total run times for each item in test collection + percentages
 
Basic usage concept.


QPX.Add("MyFunc")                          ; adds MyFunc function to the test collection
QPX.Add("AnotherFunc", "param1", "param2") ; adds AnotherFunc function to the test collection and passes 2 parameters to that function
QPX.Add("MySub")                           ; adds MySub subroutine to the test collection
QPX.Add("AnotherSub")                      ; adds AnotherSub subroutine to the test collection
QPX.Test()                                 ; starts test and displays results in a window. Left edit = Summary. Right edit = Details.
return

 
Download.
QPX.ahk - includes [QPX object] + [example, documentation, etc. in comments]
 
 
Credits.
Thanks to SKAN for his QPX() function.
 
See also.
- QPX() by SKAN
- AutoHotkey Benchmarks by Uberi
- Minimal Benchmark by R3gX


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Updated to version 1.02
- added percentages and fastest tested item mark (<<)


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


m3nth0l
  • Members
  • 27 posts
  • Last active: Feb 13 2015 11:34 PM
  • Joined: 19 Oct 2011

Very nice! Thanks for this.



Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Thanks!

Added one more example (in QPX.ahk comments)


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


R3gX
  • Members
  • 307 posts
  • Last active: Dec 29 2013 04:50 PM
  • Joined: 28 Feb 2011

Woooaaahhh !!! 

learning_one_great_scripts++

I really like this script!

 

I have a little question : How can I use your script with some of my functions that expect ByRef parameters ?


signature.png
Previously known as TomXIII
AutoHotkey version : 1.1.10


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Hi R3gX,

you can test functions with ByRef param, however, that param and the caller's variable will both refer to the same contents in memory only in the moment when you add such function to the test collection via .Add() method, and later, when the function is really called in the testing loop (started via .Test() method), you won't have ByRef effect.

To have real ByRef testing effect, use this trick; make subroutines which will execute functions with ByRef parameters.

Like this (adapted Example script 1);

;===Auto-execute===
Loop, 100        ; makes a comma delimited list for testing; "1,2,3, ...etc."
    List .= A_Index ","
List := RTrim(List, ",")

QPX.Add("Sub1", List)    ; adds Sub1 subroutine to a test collection
QPX.Add("Sub2", List)    ; adds Sub2 subroutine to a test collection
QPX.Test()                ; starts test and displays results in a window
return

;===Hotkeys===
F1::QPX.Test(50)                ; starts test again, but this time with 50 iterations (instead of 10 - default)
Esc::ExitApp

;===Subroutines===
Sub1:    ; executes function with ByRef parameter
ReverseList1(List)
;MsgBox,,, % List, 0.3    ; just a proof that ByRef List really reverses
return

Sub2:    ; executes function with ByRef parameter
ReverseList2(List)
;MsgBox,,, % List, 0.3    ; just a proof that ByRef List really reverses
return

;===Functions===
#Include QPX.ahk    ; by Learning one
ReverseList1(ByRef List, Delimiter=",") {
    StringSplit, p, List, % Delimiter
    Loop, % p0
    {
        CurItemNum := (A_Index = 1) ? p0 : p0 - A_Index + 1
        OutList .= p%CurItemNum% Delimiter
    }
    List := RTrim(OutList, Delimiter)
}
ReverseList2(ByRef List, Delimiter=",") {    ; from the Sort command documentation in AHK kelp
    Sort, List, F ReverseList2_Helper D%Delimiter%  ; Reverses the list so that it contains 4,3,2,1
}
ReverseList2_Helper(a1, a2, offset) { ; a helper function
    return offset  ; Offset is positive if a2 came after a1 in the original list; negative otherwise.
}

Uncomment MsgBoxes to have a proof that ByRef List really reverses on each testing loop.


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Just wanted to say: thanks L1, great work! happy.png


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


R3gX
  • Members
  • 307 posts
  • Last active: Dec 29 2013 04:50 PM
  • Joined: 28 Feb 2011
Hi everyone!
 
@Learning one : TTHHHANNNK YYYOOOOUUUU !!! It works very well !
I have my own script to test scripts but I really like yours.
(sorry for the late)

signature.png
Previously known as TomXIII
AutoHotkey version : 1.1.10


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

@MasterFocus: Thanks!
@R3gX: Thanks! If you posted your script, let me know where it is, and I'll put a link to it in See also section.


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


R3gX
  • Members
  • 307 posts
  • Last active: Dec 29 2013 04:50 PM
  • Joined: 28 Feb 2011

Hi Learning one !
 
For my own benchmarks script, I didn't post the code but here is a new version

Spoiler
Spoiler

signature.png
Previously known as TomXIII
AutoHotkey version : 1.1.10


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Nice. I added a link to your work. happy.png


My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy