Leaderboard
Popular Content
Showing content with the highest reputation on 01/30/2023 in all areas
-
Runtimes and Speed Comparisons
argumentum reacted to LarsJ for a topic
Overview The interest in time measurements and speed comparisons arose primarily from these examples of using compiled code in AutoIt: Accessing AutoIt Variables Using C# and VB Code in AutoIt The first versions of Runtime and Speed Comparison reports appear in this post from March 2017 and in this post half a year later. Over the last 5 - 6 years, a set of small helper functions have been developed to make it easier and faster to create a new report. It's these small helper functions that are now gathered in an include file. The functions handle settings and options to test a new script during the development process, and to generate the final report through a complete test cycle, where the script can be executed as both 32 and 64 bit code. The include file also contains functions to present the time measurements with header sections and aligned rows and columns in the report. During the same years, the individual Runtime scripts have developed in a direction where existing scripts can be used as templates for creating new scripts. First of all, the Runtime scripts have achieved a common structure, such that the most important updates during the creation of a new script consist of adjusting the code to perform the specific time measurements. Development of this project has mainly taken place during the last year at the same time as development of Virtual TreeViews. This thread is a summary of the entire development process over the last 5 - 6 years. Basic ideasThe ideas for the whole project have been somewhat diffuse throughout this long period. The first time measurements 5 - 6 years ago were performed with very simple scripts that were run first as 32 and then as 64 bit code and resulted in 2 small reports. Using an editor, the reports were combined into a single report. It was a slow and tedious process. The considerations surrounding the entire project have mainly revolved around the possibilities of creating easy-to-use and flexible time measurement code, which can also be implemented relatively simply, preferably through a single include file and a single Runtime script. The following considerations are copies of old notes. The overall purpose of runtime measurements and speed comparisons: Time measurements to compare the execution speed of different implementations of code to perform the same task. To create simple, clear reports with headers and time measurements presented in aligned rows and columns. At the same time, the reports must appear so that they actually provide useful and usable information. The overall objectives expressed in more concrete development goals: Time measurements and comparisons must be easy and flexible Ideally, you should not spend too much time coding a new test Must also contain enough features to provide real information Preferably only one include file and only one script file Clear and manageable reports in a simple text file Code implementation of the ideas in an include file and Runtime scripts: Create a number of small but generally useful helper functions Structured script files that can be run in test and report modes Step-by-step development from a simple test towards the desired result Create example scripts that can act as templates for new scripts Posts below Below in this post there is first a presentation of the project illustrated through 2 Runtime reports. Then there is a description of Runtime scripts and the include file. Then follows an example of comparison of the Map data type and Dictionary object. Finally, there is a description of some selected features. The second post concerns the comparison of AutoIt and VB.NET code for executing functions used in Virtual TreeViews. It's a more advanced example that, among other things, deals with the time measurement of a GUI creation, which is complicated by a GUI main loop. The example also covers time measurement of sub-tasks of larger AutoIt functions and VB.NET methods. Old reports Fast Array Management Functions UDF Fast Array Sorting and Management Functions UDF Fast General Array Management Functions UDF Fast SQLite Management Functions UDF Runtimes and Speed Comparisons If code performance is a significant or decisive factor in a project, it's necessary to be able to measure and compare runtimes in different implementations of the code. These topics are the focus of this example. The basic ideaOf course, depending on the code that's target of runtime measurements and speed comparisons, there can be a lot of difference in performing these measurements and comparisons. There may also be a difference in the degree of detail. Therefore, it's not easy to create a set of generally applicable functions that can be used in all cases. The basic idea is to make some small but generally useful helper functions as well as a number of example scripts that can act as templates for other scripts. It's illustrated by this result of a comparison of the Map data type and the Dictionary object: (Examples\Map vs Dict Obj\7) Map vs Dict Obj - Large data.txt) Map Data Type vs Dictionary Object Map Data Type vs Dictionary Object Map Data Type: Int and Str Keys Dictionary Object: Floats and Strings Code executed as 32-bit code Code executed as 64-bit code Code executed as 32-bit code Code executed as 64-bit code ================================== ================================== ================================== ================================== 100 key/item pairs 100 key/item pairs 100 key/item pairs 100 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.0704 Time to SET integers: 0.0565 Time to SET floats: 0.3754 Time to SET floats: 0.2815 Time to SET strings: 0.1532 Time to SET strings: 0.1446 Time to SET strings: 0.4269 Time to SET strings: 0.3360 Time to GET integers: 0.0294 Time to GET integers: 0.0310 Time to GET floats: 0.1330 Time to GET floats: 0.1103 Time to GET strings: 0.0856 Time to GET strings: 0.0848 Time to GET strings: 0.2383 Time to GET strings: 0.1792 500 key/item pairs 500 key/item pairs 500 key/item pairs 500 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.2845 Time to SET integers: 0.3155 Time to SET floats: 0.9314 Time to SET floats: 0.7657 Time to SET strings: 0.5161 Time to SET strings: 0.5386 Time to SET strings: 1.4497 Time to SET strings: 1.2165 Time to GET integers: 0.1438 Time to GET integers: 0.1430 Time to GET floats: 0.6120 Time to GET floats: 0.4779 Time to GET strings: 0.3881 Time to GET strings: 0.4250 Time to GET strings: 1.1522 Time to GET strings: 0.8680 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.5815 Time to SET integers: 0.4222 Time to SET floats: 1.6464 Time to SET floats: 1.4813 Time to SET strings: 1.2519 Time to SET strings: 0.8450 Time to SET strings: 2.9247 Time to SET strings: 2.2897 Time to GET integers: 0.2640 Time to GET integers: 0.2058 Time to GET floats: 1.6777 Time to GET floats: 1.0068 Time to GET strings: 1.1744 Time to GET strings: 0.6352 Time to GET strings: 2.6382 Time to GET strings: 1.9479 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 1.0220 Time to SET integers: 0.8984 Time to SET floats: 3.0832 Time to SET floats: 2.5471 Time to SET strings: 2.3870 Time to SET strings: 1.9143 Time to SET strings: 5.4236 Time to SET strings: 4.5600 Time to GET integers: 0.5757 Time to GET integers: 0.4635 Time to GET floats: 2.7094 Time to GET floats: 1.9528 Time to GET strings: 1.6085 Time to GET strings: 1.3010 Time to GET strings: 4.9349 Time to GET strings: 3.7270 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 3.3220 Time to SET integers: 2.2484 Time to SET floats: 7.4964 Time to SET floats: 6.1954 Time to SET strings: 6.3406 Time to SET strings: 5.0748 Time to SET strings: 13.6452 Time to SET strings: 10.7693 Time to GET integers: 1.5223 Time to GET integers: 1.2511 Time to GET floats: 6.3741 Time to GET floats: 4.9845 Time to GET strings: 5.3801 Time to GET strings: 3.9012 Time to GET strings: 12.0680 Time to GET strings: 9.0251 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 6.0779 Time to SET integers: 14.7813 Time to SET floats: 15.8554 Time to SET floats: 13.1285 Time to SET strings: 14.6669 Time to SET strings: 30.0126 Time to SET strings: 27.9988 Time to SET strings: 21.5308 Time to GET integers: 3.4560 Time to GET integers: 3.1868 Time to GET floats: 13.3380 Time to GET floats: 10.5645 Time to GET strings: 12.5274 Time to GET strings: 27.8362 Time to GET strings: 25.2268 Time to GET strings: 18.8272 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 15.1094 Time to SET integers: 15.7496 Time to SET floats: 31.8926 Time to SET floats: 26.1521 Time to SET strings: 31.4898 Time to SET strings: 29.5214 Time to SET strings: 56.7112 Time to SET strings: 44.5216 Time to GET integers: 10.6543 Time to GET integers: 10.3457 Time to GET floats: 27.6738 Time to GET floats: 23.0620 Time to GET strings: 27.5882 Time to GET strings: 25.7260 Time to GET strings: 52.1412 Time to GET strings: 39.0526 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 83.3686 Time to SET integers: 83.2603 Time to SET floats: 87.4275 Time to SET floats: 76.2308 Time to SET strings: 189.6272 Time to SET strings: 213.1701 Time to SET strings: 169.7711 Time to SET strings: 133.3019 Time to GET integers: 54.5296 Time to GET integers: 74.2480 Time to GET floats: 83.1935 Time to GET floats: 72.8659 Time to GET strings: 165.4224 Time to GET strings: 223.6139 Time to GET strings: 156.2999 Time to GET strings: 124.4494 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 287.5362 Time to SET integers: 424.6736 Time to SET floats: 228.1745 Time to SET floats: 222.7141 Time to SET strings: 1160.2881 Time to SET strings: 1312.8416 Time to SET strings: 495.5310 Time to SET strings: 374.6756 Time to GET integers: 260.1878 Time to GET integers: 436.5270 Time to GET floats: 253.5833 Time to GET floats: 251.1678 Time to GET strings: 1141.9491 Time to GET strings: 1229.7874 Time to GET strings: 463.2597 Time to GET strings: 338.7806 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 2282.7196 Time to SET integers: 3625.0477 Time to SET floats: 1025.6096 Time to SET floats: 1077.6101 Time to SET strings: 5437.2090 Time to SET strings: 5723.4847 Time to SET strings: 2153.5655 Time to SET strings: 1670.7098 Time to GET integers: 2192.6946 Time to GET integers: 3519.7249 Time to GET floats: 1386.6677 Time to GET floats: 1458.5401 Time to GET strings: 5335.2307 Time to GET strings: 5642.7701 Time to GET strings: 2107.6820 Time to GET strings: 1588.3297 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 10214.3356 Time to SET integers: 13896.4168 Time to SET floats: 3139.8242 Time to SET floats: 3657.8827 Time to SET strings: 33276.5766 Time to SET strings: 34839.8803 Time to SET strings: 8217.9557 Time to SET strings: 5754.7453 Time to GET integers: 9894.3836 Time to GET integers: 13681.4498 Time to GET floats: 5346.3679 Time to GET floats: 5819.9051 Time to GET strings: 32589.8393 Time to GET strings: 34073.4712 Time to GET strings: 8167.2764 Time to GET strings: 5622.3269 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET floats: 6649.1308 Time to SET floats: 7796.9872 Time to SET strings: >10000.0000 Time to SET strings: >10000.0000 Time to SET strings: 18203.5605 Time to SET strings: 12103.5838 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET floats: 12250.9218 Time to GET floats: 13320.5233 Time to GET strings: >10000.0000 Time to GET strings: >10000.0000 Time to GET strings: 18109.2658 Time to GET strings: 11949.4221 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET floats: 11376.8179 Time to SET floats: 13575.6015 Time to SET strings: >10000.0000 Time to SET strings: >10000.0000 Time to SET strings: >10000.0000 Time to SET strings: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET floats: >10000.0000 Time to GET floats: >10000.0000 Time to GET strings: >10000.0000 Time to GET strings: >10000.0000 Time to GET strings: >10000.0000 Time to GET strings: >10000.0000 The idea also includes a step-by-step development from a very simple test towards the desired result. If the report above is an expression of the desired result, then this report can be the result of the very first step: (Examples\Map vs Dict Obj\1) First test.txt) Map Data Type Integer Key Type Code executed as 64-bit code ================================== 50 key/item pairs ---------------------------------- Time to SET integers: 0.0424 Time to GET integers: 0.0130 100 key/item pairs ---------------------------------- Time to SET integers: 0.0407 Time to GET integers: 0.0213 250 key/item pairs ---------------------------------- Time to SET integers: 0.1100 Time to GET integers: 0.0532 500 key/item pairs ---------------------------------- Time to SET integers: 0.1931 Time to GET integers: 0.1072 750 key/item pairs ---------------------------------- Time to SET integers: 0.3153 Time to GET integers: 0.1657 1,000 key/item pairs ---------------------------------- Time to SET integers: 0.4527 Time to GET integers: 0.2069 1,250 key/item pairs ---------------------------------- Time to SET integers: 0.5125 Time to GET integers: 0.2848 1,500 key/item pairs ---------------------------------- Time to SET integers: 0.6048 Time to GET integers: 0.3319 2,000 key/item pairs ---------------------------------- Time to SET integers: 0.8835 Time to GET integers: 0.4269 2,500 key/item pairs ---------------------------------- Time to SET integers: 1.1045 Time to GET integers: 0.5984 3,000 key/item pairs ---------------------------------- Time to SET integers: 1.3860 Time to GET integers: 0.6671 5,000 key/item pairs ---------------------------------- Time to SET integers: 3.9250 Time to GET integers: 2.1894 7,500 key/item pairs ---------------------------------- Time to SET integers: 3.7580 Time to GET integers: 2.0071 10,000 key/item pairs ---------------------------------- Time to SET integers: 4.9168 Time to GET integers: 2.9690 12,500 key/item pairs ---------------------------------- Time to SET integers: 6.6247 Time to GET integers: 4.1951 15,000 key/item pairs ---------------------------------- Time to SET integers: 8.7360 Time to GET integers: 7.6631 20,000 key/item pairs ---------------------------------- Time to SET integers: 20.5859 Time to GET integers: 11.6363 Runtime scripts All Runtime scripts are identical in structure. A script starts with a Runtime settings section, then follows a Runtime data section and finally a larger Runtime functions section. The result of a Runtime script is a report with 1 - 4 columns as shown above. The absolute easiest way to create a new Runtime script is to copy and use an existing script as a template. Settings sectionThis is the Runtime settings section in Examples\Map vs Dict Obj\1) First test.au3: ; === Runtime and Speed Comparison settings === If Not Runtime_Settings( _ ; Settings for the current Runtime and Speed Comparison script. 2, _ ; Number of time measurements in each Runtime function. Default 2. ; <<<<<<<<<< 0, _ ; Max time in milliseconds for a single time measurement. 0 to disable. ; <<<<<<<<<< 0, _ ; Visual validation of Runtime data for $aRuntime_Rows[0]. 0 to disable. ; <<<<<<<<<< 1, _ ; 0 to NOT delete report file given by $gsRuntime_File. Only used when $lbRuntime_Main = 0. ; <<<<<<<<<< 1, _ ; Indicate the current of up to 4 Runtime test functions. Only used when $lbRuntime_Main = 0. ; <<<<<<<<<< 0 ) Then ; 1 to perform a complete test cycle through Runtime_Main() function. 0 to test the function above. ; <<<<<<<<<< ConsoleWrite( "Runtime_Settings(): @error = " & @error & @CRLF ) Exit 1 EndIf ; Command line parameters when Runtime_Main() is performing a complete test cycle. Must be ; executed after Runtime_Settings() and before Runtime_Main() because it updates settings. If $CmdLine[0] Then Runtime_CmdLineParams() If $gbRuntime_Main = 1 Then ; Runtime_Main() performs a complete test cycle, where up to 4 Runtime test functions are executed. ; Parameters must be set to match the test cycle of the current Runtime and Speed Comparison script. If Not Runtime_Main( _ 1, _ ; $giRuntime_Test_Functions = 1 ; The number of Runtime test functions to run. Must be defined below. ; <<<<<<<<<< 3, _ ; $giRuntime_Test_Bitness = 3 ; 1, 2 or 3 for 32/64 bit test or both for each Runtime test function. ; <<<<<<<<<< 1 ) Then ; $giRuntime_Test_LogInfo = 1 ; Runtime LogInfo is enabled as default to update the LogInfo ListView. ; <<<<<<<<<< ConsoleWrite( "Runtime_Main(): @error = " & @error & @CRLF ) Exit 1 EndIf EndIf The Settings section is used to define settings and options for executing the Runtime script. More information on the Settings section below. Data sectionThe default Runtime data section is coded this way: ; === Runtime and Speed Comparison data === Func Runtime_Data() ; Number of test rows ; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Local $aRuntime_Rows = [ 50, 100, 250, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000, 5000, 7500, 10000, 12500, 15000, 20000 ] ;Local $aRuntime_Rows = [ 100, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 250000, 500000, 750000, 1000000, 2500000, 5000000, 10000000, 16000000 ] ;ReDim $aRuntime_Rows[12] ; Limit row numbers to 50 - 5,000 or 100 - 750,000 rows ; Row numbers must be in ascending order ; --- Additional data for the current Runtimes --- Local $aRuntime_Data = 0 ; ------------------------------------------------ Local $aRuntime_Data_All = [ $aRuntime_Rows, Runtime_Times(), $aRuntime_Data ] Return $aRuntime_Data_All EndFunc Using the Runtime data section will be demonstrated in next post. Functions sectionThe Runtime functions section connects $giRuntime_Test variable to Runtime functions and implements the functions: ; === Runtime and Speed Comparison functions === ; For each Runtime test from 1 - 4, the output will result in a ; vertical column when the function is executed via Runtime_Main(). If $giRuntime_Test = 1 Then Runtimes1( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 2 Then Runtimes2( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 3 Then Runtimes3( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 4 Then Runtimes4( Runtime_Data() ) ; <<<<<<<<<< ; === Runtime and Speed Comparison test 1 === ; Map data type Func Runtimes1( $aRuntime_Data_All ) ; --- General local variables --- Local $iLineLen = 34 ; Length of a Runtime info line <= 80 Local $iTest, $iTests = $giRuntime_Time_Tests, $iBit = @AutoItX64 ? 64 : 32;, $bDisplay = $gbRuntime_Display_Once Local $aRuntime_Rows = $aRuntime_Data_All[0], $iRuntime_Rows = UBound( $aRuntime_Rows ), $aRuntime_Info[5+$iRuntime_Rows*($iTests+3)] Local $hTimer, $aTimes = $aRuntime_Data_All[1] ; Set individual max times by updating $aTimes[$i][2] Runtime_InitStorage( $aRuntime_Info ) ;$aTimes[1][2] = 30000 ; --- Local variables for the current function --- Local $iRows, $sRows = "key/item pairs" ; --- Create header information --- ; Both $sHeader1 and $sHeader2 must always be specified Local $sHeader1 = "Map Data Type" Local $sHeader2 = "Integer Key Type" Runtime_HeaderInfo( $iBit, $sHeader1, $sHeader2, $iLineLen, $aRuntime_Info ) ; --- Execute Runtime and Speed Comparison code for the current function --- For $i = 0 To $iRuntime_Rows - 1 $iRows = $aRuntime_Rows[$i] Local $mMap[], $v ; Visual validation of Runtime data for $aRuntime_Rows[0] ;If $iRows = $aRuntime_Rows[0] Then ;EndIf Runtime_RowsInfo( $i, $iRows, $sRows, 0, $iTests, $iLineLen, $aRuntime_Info ) ; 0 = $iCols ; Time test 1 $iTest = 0 If Not $aTimes[$iTest][2] Or ( $aTimes[$iTest][1] < $aTimes[$iTest][2] ) Then $hTimer = TimerInit() ; Time test 1 For $j = 0 To $iRows - 1 $mMap[$j] = $j Next $aTimes[$iTest][1] = TimerDiff( $hTimer ) Runtime_Info1( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][1], $aRuntime_Info, "Time to SET integers:" ) Else Runtime_Info2( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][2], $aRuntime_Info, "Time to SET integers:" ) EndIf ; Time test 2 $iTest += 1 If Not $aTimes[$iTest][2] Or ( $aTimes[$iTest][1] < $aTimes[$iTest][2] ) Then $hTimer = TimerInit() ; Time test 2 For $j = 0 To $iRows - 1 $v = $mMap[$j] Next $aTimes[$iTest][1] = TimerDiff( $hTimer ) Runtime_Info1( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][1], $aRuntime_Info, "Time to GET integers:" ) Else Runtime_Info2( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][2], $aRuntime_Info, "Time to GET integers:" ) EndIf Next ; Store Runtime information _FileWriteFromArray( $gsRuntime_File, $aRuntime_Info ) #forceref $v EndFunc ; === Runtime and Speed Comparison test 2 === Func Runtimes2( $aRuntime_Data_All ) #forceref $aRuntime_Data_All EndFunc ; === Runtime and Speed Comparison test 3 === Func Runtimes3( $aRuntime_Data_All ) #forceref $aRuntime_Data_All EndFunc ; === Runtime and Speed Comparison test 4 === Func Runtimes4( $aRuntime_Data_All ) #forceref $aRuntime_Data_All EndFunc The names of the Runtime functions are only used in this section and not in the include file. The function names can therefore be chosen freely. The code at top of the functions in the local variables sections is the same in all scripts in the Map vs Dict Obj example below. In the header sections, there are changes to the header texts. Otherwise, the biggest updates to the code take place in the For loops above. More information about Runtime functions in the walkthrough of the Map vs Dict Obj example below. Include filesIncludes\Runtimes.au3 Includes\Runtimes.au3 contains helper functions to perform runtime measurements and speed comparisons from a very simple test that generates a report with a single data column, to a complete test cycle of both 32 and 64 bit code, where the report consists of up to 4 data columns. There are three groups of main functions. The first group is about running a Runtime script with different settings and options that can generate reports with up to 4 columns of output. The output is genereted of up to 4 Runtime functions that run as either 32 or 64 bit code. Or of up to 2 Runtime functions that run as both 32 and 64 bit code. The second group handles vertical division and alignment of single and multiple columns into sections with headings and time measurements. The third group handles horizontal alignment of single and multiple columns. Includes\LogInfoDisplay.au3 Includes\LogInfoDisplay.au3 displays report output in a ListView when a complete test cycle is performed. This output can be turned on and off. A single test (as opposed to a complete test cycle) generates report output in SciTE console. SettingsThis is the Runtime_Settings() function in Includes\Runtimes.au3: ; Settings for the current Runtime and Speed Comparison script. ; ; Error code in @error Return value ; 1 -> Invalid parameter value Success -> 1 ; Failure -> 0 Func Runtime_Settings( _ $liRuntime_Time_Tests = 2, _ ; Number of time measurements in each Runtime function. Default 2. $lfRuntime_Max_Time = 0, _ ; Max time in milliseconds for a single time measurement. 0 to disable. $lbRuntime_Display_Once = 1, _ ; Visual validation of Runtime data for $aRuntime_Rows[0]. 0 to disable. $lbRuntime_File_Del = 1, _ ; 0 to NOT delete report file given by $gsRuntime_File. Only used when $lbRuntime_Main = 0. $liRuntime_Test = 1, _ ; Indicate the current of up to 4 Runtime test functions. Only used when $lbRuntime_Main = 0. $lbRuntime_Main = 0 ) ; 1 to perform a complete test cycle through Runtime_Main() function. 0 to test the function above. If Not ( 1 <= $liRuntime_Time_Tests ) Then Return SetError( 1, 0, 0 ) ; Integer If Not ( 0 <= $lfRuntime_Max_Time ) Then Return SetError( 1, 0, 0 ) ; Float If Not ( 0 = $lbRuntime_Display_Once Or $lbRuntime_Display_Once = 1 ) Then Return SetError( 1, 0, 0 ) ; Boolean If Not ( 0 = $lbRuntime_File_Del Or $lbRuntime_File_Del = 1 ) Then Return SetError( 1, 0, 0 ) ; Boolean If Not ( 1 <= $liRuntime_Test And $liRuntime_Test <= 4 ) Then Return SetError( 1, 0, 0 ) ; Integer If Not ( 0 = $lbRuntime_Main Or $lbRuntime_Main = 1 ) Then Return SetError( 1, 0, 0 ) ; Boolean $giRuntime_Time_Tests = $liRuntime_Time_Tests ; Must be the same number in each function to ensure vertical column alignment. $gfRuntime_Max_Time = $lfRuntime_Max_Time ; Set individual max times by updating $aTimes[$i][2] in the Runtime functions. $gbRuntime_Display_Once = $lbRuntime_Display_Once $gbRuntime_File_Del = $lbRuntime_File_Del ; 0: Possible to run the same script on several PCs with output in same report. $giRuntime_Test = $liRuntime_Test $gbRuntime_Main = $lbRuntime_Main Return 1 EndFunc The last parameter, $lbRuntime_Main, is also the most crucial, and is used to execute the Runtime script in two different modes. Note that the function referenced in the last part of the comment line: "0 to test the function above", is the function given by $liRuntime_Test = 1. The function identified through this variable is defined at top of the Function section this way: ; === Runtime and Speed Comparison functions === ; For each Runtime test from 1 - 4, the output will result in a ; vertical column when the function is executed via Runtime_Main(). If $giRuntime_Test = 1 Then Runtimes1( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 2 Then Runtimes2( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 3 Then Runtimes3( Runtime_Data() ) ; <<<<<<<<<< If $giRuntime_Test = 4 Then Runtimes4( Runtime_Data() ) ; <<<<<<<<<< The $liRuntime_Test / $giRuntime_Test variables define which Runtime function is to be executed. In default mode when $lbRuntime_Main = 0 the Runtime script is executed directly in SciTE with report output in the console. The report always contains only one column. This mode is used to develop and test the Runtime script. When $lbRuntime_Main = 1 a complete Runtime test cycle is performed, running the Runtime script up to 4 times through the RunWait() command. A report with up to 4 columns is generated. Optional output in a ListView in a LogInfoDisplay GUI. In both modes, the output is saved as a report in the form of a text file with the same name as the Runtime script. Settings and options are discussed in more detail below in the review of Map vs Dict Obj example. Map vs Dict Obj In Examples\Map vs Dict Obj\, the Map data type is compared to the Dictionary object. The example is developed from a simple test in 1) First test.au3 to a complete test with both 32 and 64 bit code in 7) Map vs Dict Obj - Large data.au3. Run the examples in SciTE with F5. 1) First test.au31) First test.au3 is shown in the code boxes above. Runtime settings Default Runtime settings except that visual validation of Runtime data is disabled. Visual validation of Runtime data is demonstrated in next post. Runtime data Only default Runtime data in the Map vs Dict Obj example. Using the Runtime data section is demonstrated in next post. Runtime functions Runtime functions can be executed in two modes. Either by running the script without calling Runtime_Main() (at bottom of the settings section), whereby a single Runtime function is executed directly and results in a single column in the report. This mode displays ConsoleWrite() output in SciTE console. This makes it possible to find and correct errors in the Runtime function. Or by calling Runtime_Main(), which indirectly executes up to 4 Runtime functions (or 2 functions as both 32 and 64 bit) through the RunWait() command and thus performs a complete test cycle and produces a report with up to 4 columns. Runtime_Main() may optionally generate output in a ListView in a LogInfoDisplay GUI. Whether or not Runtime_Main() is called is determined by the last parameter, $lbRuntime_Main, in Runtime_Settings() (at top of the settings section). If this parameter is 1, Runtime_Main() is called. If the parameter is 0, Runtime_Main() isn't called. In 1) First test.au3 $lbRuntime_Main = 0 and thus the script is executed in development and test mode with output in SciTE console. Only one Runtime function is used: Runtimes1(). The actual Runtime tests are performed in loops in the middle of Runtimes1(). Here, how long it takes to write and read different numbers of key/item pairs of integer type in a Map variable is measured. In the first scripts, small numbers of key/item pairs are used to avoid spending too much time running and testing scripts in SciTE. The script generates a report as shown above. 2) First cycle.au32) First cycle.au3 performs a complete test cycle of both 32 and 64 bit code through Runtime_Main() function. The only change to the code in 2) First cycle.au3 is that the last parameter, $lbRuntime_Main, in Runtime_Settings() is changed from 0 to 1. When the script is run in SciTE, progress information for script execution shows up in the console. A report is generated with output in the LogInfoDisplay ListView. The report with 2 columns is also stored in 2) First cycle.txt. In addition to settings in Runtime_Settings(), which are modified in Runtime_CmdLineParams(), execution of Runtime_Main() is determined through 3 additional function parameters. Last part of Runtime_Settings() ; Command line parameters when Runtime_Main() is performing a complete test cycle. Must be ; executed after Runtime_Settings() and before Runtime_Main() because it updates settings. If $CmdLine[0] Then Runtime_CmdLineParams() If $gbRuntime_Main = 1 Then ; Runtime_Main() performs a complete test cycle, where up to 4 Runtime test functions are executed. ; Parameters must be set to match the test cycle of the current Runtime and Speed Comparison script. If Not Runtime_Main( _ 1, _ ; $giRuntime_Test_Functions = 1 ; The number of Runtime test functions to run. Must be defined below. ; <<<<<<<<<< 3, _ ; $giRuntime_Test_Bitness = 3 ; 1, 2 or 3 for 32/64 bit test or both for each Runtime test function. ; <<<<<<<<<< 1 ) Then ; $giRuntime_Test_LogInfo = 1 ; Runtime LogInfo is enabled as default to update the LogInfo ListView. ; <<<<<<<<<< ConsoleWrite( "Runtime_Main(): @error = " & @error & @CRLF ) Exit 1 EndIf EndIf Runtime_CmdLineParams() ; Command line parameters when Runtime_Main() ; is performing a complete test cycle. Func Runtime_CmdLineParams() $giRuntime_Test = $CmdLine[1]+0 $gbRuntime_Main = $CmdLine[2]+0 $gbRuntime_3264 = $CmdLine[3]+0 If $gbRuntime_Main Then $gbRuntime_File_Del = 1 If $CmdLine[0] = 4 Then $ghRuntime_Info = HWnd( $CmdLine[4] ) ; To update Runtimes and Speed Comparisons LogInfo GUI EndFunc Runtime_Main() ; Runtime_Main() performs a complete test cycle, where up to 4 Runtime test functions ; are executed. ; ; Error code in @error Return value ; 1 -> Invalid parameter value Success -> 1 ; Failure -> 0 Func Runtime_Main( _ $giRuntime_Test_Functions = 1, _ ; The number of Runtime test functions $giRuntime_Test_Bitness = 3, _ ; 1, 2 or 3 for 32/64 bit test or both $giRuntime_Test_LogInfo = 1 ) ; Runtime LogInfo is enabled as default ; Maximum up to 4 Runtime test functions for EITHER 32 OR 64 bit tests If Not ( 1 <= $giRuntime_Test_Functions And $giRuntime_Test_Functions <= 4 ) Then Return SetError( 1, 0, 0 ) If Not ( 1 <= $giRuntime_Test_Bitness And $giRuntime_Test_Bitness <= 3 ) Then Return SetError( 1, 0, 0 ) If $giRuntime_Test_Functions > 2 And $giRuntime_Test_Bitness = 3 Then Return SetError( 1, 0, 0 ) ; Maximum up to 2 Runtime test functions for BOTH 32 AND 64 bit tests $gbRuntime_3264 = $giRuntime_Test_Bitness = 3 ? 1 : 0 Local $sAutoItExePath = StringLeft( @AutoItExe, StringInStr( @AutoItExe, "\", 0, -1 ) ) If $giRuntime_Test_LogInfo Then ; Start Runtimes and Speed Comparisons LogInfo GUI Local $sScriptName = $gsRuntime_Path & "\LogInfoDisplay.au3" Run( $sAutoItExePath & "AutoIt3_x64.exe" & " /AutoIt3ExecuteScript " & """" & $sScriptName & """" & " " & """" & @ScriptName & """" ) $ghRuntime_Info = WinWaitActive( "[TITLE:LogInfoDisplay;CLASS:AutoIt v3 GUI]" ) EndIf FileDelete( $gsRuntime_File ) ; Runtime and Speed Comparison test 1 is always performed $giRuntime_Test = 1 ; Execute @ScriptName as 32 bit If BitAND( $giRuntime_Test_Bitness, 1 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 1 - Performing 32-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 32 bit code EndIf ; Execute @ScriptName as 64 bit If BitAND( $giRuntime_Test_Bitness, 2 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 1 - Performing 64-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3_x64.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 64 bit code EndIf ; Runtime and Speed Comparison test 2 is only performed if $giRuntime_Test_Functions >= 2 If $giRuntime_Test_Functions >= 2 Then $giRuntime_Test = 2 ; Execute @ScriptName as 32 bit If BitAND( $giRuntime_Test_Bitness, 1 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 2 - Performing 32-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 32 bit code EndIf ; Execute @ScriptName as 64 bit If BitAND( $giRuntime_Test_Bitness, 2 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 2 - Performing 64-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3_x64.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 64 bit code EndIf EndIf ; Runtime and Speed Comparison test 3 is only performed if $giRuntime_Test_Functions >= 3 ; And if you only test with EITHER 32 OR 64 bit code If $giRuntime_Test_Functions >= 3 Then $giRuntime_Test = 3 ; Execute @ScriptName as 32 bit If BitAND( $giRuntime_Test_Bitness, 1 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 3 - Performing 32-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 32 bit code EndIf ; Execute @ScriptName as 64 bit If BitAND( $giRuntime_Test_Bitness, 2 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 3 - Performing 64-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3_x64.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 64 bit code EndIf EndIf ; Runtime and Speed Comparison test 4 is only performed if $giRuntime_Test_Functions = 4 ; And if you only test with EITHER 32 OR 64 bit code If $giRuntime_Test_Functions >= 4 Then $giRuntime_Test = 4 ; Execute @ScriptName as 32 bit If BitAND( $giRuntime_Test_Bitness, 1 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 4 - Performing 32-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 32 bit code EndIf ; Execute @ScriptName as 64 bit If BitAND( $giRuntime_Test_Bitness, 2 ) Then ConsoleWrite( @ScriptName & ": Runtime Test 4 - Performing 64-bit Runtimes and Speed Comparison Tests ..." & @CRLF ) RunWait( $sAutoItExePath & "AutoIt3_x64.exe" & " /AutoIt3ExecuteScript " & """" & @ScriptName & """" & " " & $giRuntime_Test & " 2 " & $gbRuntime_3264 & " " & $ghRuntime_Info ) ; 64 bit code EndIf EndIf Exit ; Exit is needed to prevent code in the calling script that EndFunc ; follows execution of Runtime_Main() from being executed. 3) Add strings.au3In 3) Add strings.au3, time measurements are also made when the Map key consists of strings. This gives 4 time tests in Runtimes1(). 4) Strings cycle.au3 executes both 32 and 64 bit code. 5) Map vs Dict Obj.au3Runtimes2() is implemented in 5) Map vs Dict Obj.au3 to measure write and read times for key/item pairs of types floats and strings in Dictionary objects. When the script is run in SciTE, both Runtimes1() and Runtimes2() are executed in a complete test cycle but only as 64 bit code and generates 2 columns in the report. This is determined through parameters in Runtime_Settings() and Runtime_Main(). A new complete test cycle is performed in 6) Map vs Dict Obj - Cycle.au3, where Runtimes1() and Runtimes2() are executed as both 32 and 64 bit code and generates 4 columns in the report. The difference between script 5) and 6) is the $giRuntime_Test_Bitness parameter in Runtime_Main() which is 2 in script 5) (64 bit only) and 3 in script 6) (32 and 64 bit). Note that there appears to be an issue with AutoIt integer keys in Dictionary objects. In these 4 small pieces of code, it's thus only the last one, where the integer key is converted to a floating point number, that works. $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict( 2^3 ) = 2^3 $iItem = $oDict( 2^3 ) ; Err $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict( 2^3+0 ) = 2^3+0 $iItem = $oDict( 2^3+0 ) ; Err $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict( Int( 2^3 ) ) = Int( 2^3 ) $iItem = $oDict( Int( 2^3 ) ) ; Err $oDict = ObjCreate( "Scripting.Dictionary" ) $oDict( 2^3+0.0 ) = 2^3+0.0 $iItem = $oDict( 2^3+0.0 ) ; OK Therefore, floats have been chosen instead of integers to test Dictionary objects. Script 7) perform the same Runtime tests as script 6), but with larger numbers of key/item pairs. Therefore, a limit has been set on all time tests of 10 seconds. When a specific test takes 10 seconds or more, this test isn't repeated for higher numbers of key/item pairs. The purpose is to limit the total time consumption of a Runtime test. And especially during the execution of a complete test cycle. The report with 4 columns generated by script 7) is the desired result of the Map vs Dict Obj Runtime and Speed Comparison test. The report is shown above. Script 8 ) is the same as script 7) but without a time limit. Therefore, some time measurements with large numbers of key/item pairs will take an unacceptably long time. Script 8 ) has been tested on a 6½-year-old Windows 7 medium PC, and a 1½-year-old Windows 10 PC, which is a medium PC in the higher end. Feature examplesExamples\Features\ contains au3- and txt-files to demonstrate and implement various features and techniques in Runtime scripts. The scripts are customized copies of the Map vs Dict Obj examples above. Blank lineIn the case of 2 Runtime functions with different numbers of time measurements, the vertical alignment of the columns in the report will not be correct. In this situation, one or more blank lines can be added to ensure correct vertical alignment: ; Blank line $iTest = 0 ; Runtime_Info2() must be used as code to add a blank line is only included in this function Runtime_Info2( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][2], $aRuntime_Info, "" ) Since $iTest = 0, a blank line is inserted before the first time measurement. Multiple PCsThe documentation also applies to Repeat test.au3. Func Runtime_Settings( _ $liRuntime_Time_Tests = 2, _ ; Number of time measurements in each Runtime function. Default 2. $lfRuntime_Max_Time = 0, _ ; Max time in milliseconds for a single time measurement. 0 to disable. $lbRuntime_Display_Once = 1, _ ; Visual validation of Runtime data for $aRuntime_Rows[0]. 0 to disable. $lbRuntime_File_Del = 1, _ ; 0 to NOT delete report file given by $gsRuntime_File. Only used when $lbRuntime_Main = 0. $liRuntime_Test = 1, _ ; Indicate the current of up to 4 Runtime test functions. Only used when $lbRuntime_Main = 0. $lbRuntime_Main = 0 ) ; 1 to perform a complete test cycle through Runtime_Main() function. 0 to test the function above. If the parameters $lbRuntime_File_Del and $lbRuntime_Main are both set to the value 0, the same Runtime script can be executed several times with output in the same report. $lbRuntime_File_Del = 0 prevents the report from being deleted between each run. This adds output to the existing report and can generate a report with up to 4 columns. If an old report already exists, e.g. after a test of the Runtime script during the development process, such an old report must be deleted manually. $lbRuntime_File_Del = 0 also prevents this old report from being deleted. The technique can be used to repeat the same test on multiple PCs and thus compare the performance of the PCs. Copy the include file, Runtime script and report from one PC to the other and execute the Runtime script. Up to 4 PCs can be compared. Multiple PCs.txt: Dictionary Object Dictionary Object Dictionary Object Dictionary Object Lenovo labtop, Win 7, 10½ year Lenovo labtop, Win 10, 1½ year Windows 7, medium, 6½ year Win 10, medium (high end), 1½ year Code executed as 64-bit code Code executed as 64-bit code Code executed as 64-bit code Code executed as 64-bit code ================================== ================================== ================================== ================================== 100 key/item pairs 100 key/item pairs 100 key/item pairs 100 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 0.8063 Time to SET floats: 0.5487 Time to SET floats: 0.2867 Time to SET floats: 0.3784 Time to SET strings: 0.5148 Time to SET strings: 0.6275 Time to SET strings: 0.3344 Time to SET strings: 0.3988 Time to GET floats: 0.1741 Time to GET floats: 0.2134 Time to GET floats: 0.1092 Time to GET floats: 0.1147 Time to GET strings: 0.2902 Time to GET strings: 0.3827 Time to GET strings: 0.2130 Time to GET strings: 0.2039 500 key/item pairs 500 key/item pairs 500 key/item pairs 500 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 1.1392 Time to SET floats: 1.3766 Time to SET floats: 0.7685 Time to SET floats: 0.7832 Time to SET strings: 2.4873 Time to SET strings: 2.2805 Time to SET strings: 1.1439 Time to SET strings: 1.2693 Time to GET floats: 0.7677 Time to GET floats: 0.9510 Time to GET floats: 0.4909 Time to GET floats: 0.5043 Time to GET strings: 1.4032 Time to GET strings: 1.9148 Time to GET strings: 0.8824 Time to GET strings: 0.9730 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 2.0752 Time to SET floats: 2.4859 Time to SET floats: 1.3481 Time to SET floats: 1.3554 Time to SET strings: 3.3659 Time to SET strings: 4.3570 Time to SET strings: 2.2315 Time to SET strings: 2.3319 Time to GET floats: 1.5033 Time to GET floats: 1.8988 Time to GET floats: 0.9696 Time to GET floats: 1.0115 Time to GET strings: 2.8129 Time to GET strings: 3.8353 Time to GET strings: 1.7586 Time to GET strings: 1.9669 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 8.5532 Time to SET floats: 4.8982 Time to SET floats: 2.5667 Time to SET floats: 2.5717 Time to SET strings: 13.5443 Time to SET strings: 8.7610 Time to SET strings: 4.4963 Time to SET strings: 8.2610 Time to GET floats: 3.0875 Time to GET floats: 3.8538 Time to GET floats: 2.2520 Time to GET floats: 1.9955 Time to GET strings: 5.6032 Time to GET strings: 7.8478 Time to GET strings: 3.5303 Time to GET strings: 3.8151 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 9.9753 Time to SET floats: 20.1038 Time to SET floats: 6.2331 Time to SET floats: 6.2076 Time to SET strings: 16.4886 Time to SET strings: 23.9255 Time to SET strings: 10.9092 Time to SET strings: 11.0983 Time to GET floats: 8.0573 Time to GET floats: 16.2224 Time to GET floats: 5.1293 Time to GET floats: 4.9316 Time to GET strings: 165.4877 Time to GET strings: 23.7091 Time to GET strings: 97.2250 Time to GET strings: 10.2493 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 24.4564 Time to SET floats: 26.8007 Time to SET floats: 13.2881 Time to SET floats: 13.3160 Time to SET strings: 45.0839 Time to SET strings: 55.7773 Time to SET strings: 22.2477 Time to SET strings: 22.2675 Time to GET floats: 16.2213 Time to GET floats: 23.9157 Time to GET floats: 10.8169 Time to GET floats: 11.1769 Time to GET strings: 28.8736 Time to GET strings: 44.6960 Time to GET strings: 19.0022 Time to GET strings: 20.1813 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 39.3476 Time to SET floats: 66.9533 Time to SET floats: 42.9892 Time to SET floats: 26.5579 Time to SET strings: 70.2702 Time to SET strings: 102.8037 Time to SET strings: 45.2218 Time to SET strings: 45.4328 Time to GET floats: 32.2920 Time to GET floats: 49.4208 Time to GET floats: 23.5141 Time to GET floats: 21.7608 Time to GET strings: 64.1431 Time to GET strings: 99.0432 Time to GET strings: 39.1290 Time to GET strings: 40.4980 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 156.7391 Time to SET floats: 162.8337 Time to SET floats: 80.6036 Time to SET floats: 71.8760 Time to SET strings: 226.3471 Time to SET strings: 278.2435 Time to SET strings: 136.6088 Time to SET strings: 125.2966 Time to GET floats: 117.4066 Time to GET floats: 128.5505 Time to GET floats: 74.6459 Time to GET floats: 63.8180 Time to GET strings: 200.8788 Time to GET strings: 267.0520 Time to GET strings: 118.9311 Time to GET strings: 113.6837 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 477.4047 Time to SET floats: 401.4525 Time to SET floats: 229.3125 Time to SET floats: 174.6070 Time to SET strings: 633.1885 Time to SET strings: 659.5374 Time to SET strings: 379.1723 Time to SET strings: 290.4244 Time to GET floats: 430.3122 Time to GET floats: 354.1500 Time to GET floats: 252.8540 Time to GET floats: 151.3619 Time to GET strings: 592.1220 Time to GET strings: 641.9996 Time to GET strings: 344.2435 Time to GET strings: 274.9410 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 2506.0299 Time to SET floats: 1831.0226 Time to SET floats: 1102.2460 Time to SET floats: 941.9556 Time to SET strings: 2996.5019 Time to SET strings: 2834.2122 Time to SET strings: 1696.1518 Time to SET strings: 1596.9816 Time to GET floats: 2436.7968 Time to GET floats: 2059.1103 Time to GET floats: 1467.0756 Time to GET floats: 1068.0994 Time to GET strings: 2885.8160 Time to GET strings: 2736.6734 Time to GET strings: 1601.2007 Time to GET strings: 1507.9682 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 9625.9954 Time to SET floats: 7067.7140 Time to SET floats: 3690.0478 Time to SET floats: 4083.9408 Time to SET strings: 11062.4177 Time to SET strings: 9705.4638 Time to SET strings: 5828.4754 Time to SET strings: 6309.6669 Time to GET floats: 9402.8360 Time to GET floats: 7386.4105 Time to GET floats: 5821.5921 Time to GET floats: 5125.1619 Time to GET strings: 10732.6361 Time to GET strings: 9606.9670 Time to GET strings: 5637.6283 Time to GET strings: 6165.0928 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 21641.4441 Time to SET floats: 16346.8101 Time to SET floats: 7810.8329 Time to SET floats: 10127.1801 Time to SET strings: 24213.2453 Time to SET strings: 20998.8080 Time to SET strings: 12017.4508 Time to SET strings: 14443.3815 Time to GET floats: 20793.1913 Time to GET floats: 16415.3945 Time to GET floats: 13318.7511 Time to GET floats: 12215.9591 Time to GET strings: 23631.4639 Time to GET strings: 20436.8046 Time to GET strings: 11865.3739 Time to GET strings: 14166.9541 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET floats: 38099.9143 Time to SET floats: 29468.5027 Time to SET floats: 13488.5462 Time to SET floats: 18590.9545 Time to SET strings: 42532.3169 Time to SET strings: 37539.1462 Time to SET strings: 20615.3748 Time to SET strings: 25993.1925 Time to GET floats: 37491.8000 Time to GET floats: 29424.1574 Time to GET floats: 22812.6073 Time to GET floats: 21492.3516 Time to GET strings: 41942.9129 Time to GET strings: 36578.6597 Time to GET strings: 20636.5487 Time to GET strings: 25661.0474 The Dictionary object is tested with float and string keys for large numbers of key/item pairs and no time limit. The header text to identify the PCs is added manually directly in the report. This is done after the test on the individual PC. The technique can also be used to repeat the same test multiple times. Eg. to verify that the time measurements are fairly stable from one test to the next. For very short time measurements up to around 100 ms, the numbers can fluctuate a lot. For time measurements of longer duration, the numbers become more stable. At least in terms of the percentage variation. There can still easily be several 100 ms between the numbers. Repeat test.txt: Map Data Type Map Data Type Map Data Type Map Data Type Integer Key Type Integer Key Type Integer Key Type Integer Key Type Code executed as 32-bit code Code executed as 32-bit code Code executed as 32-bit code Code executed as 32-bit code ================================== ================================== ================================== ================================== 100 key/item pairs 100 key/item pairs 100 key/item pairs 100 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.0562 Time to SET integers: 0.0634 Time to SET integers: 0.0925 Time to SET integers: 0.0942 Time to GET integers: 0.0269 Time to GET integers: 0.0277 Time to GET integers: 0.0496 Time to GET integers: 0.0477 500 key/item pairs 500 key/item pairs 500 key/item pairs 500 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.2455 Time to SET integers: 0.2399 Time to SET integers: 0.4228 Time to SET integers: 0.4061 Time to GET integers: 0.1247 Time to GET integers: 0.1252 Time to GET integers: 0.2000 Time to GET integers: 0.2081 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs 1,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.4710 Time to SET integers: 0.4881 Time to SET integers: 0.8655 Time to SET integers: 0.8671 Time to GET integers: 0.2477 Time to GET integers: 0.2571 Time to GET integers: 0.4374 Time to GET integers: 0.4330 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs 2,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 0.9444 Time to SET integers: 0.9696 Time to SET integers: 1.6484 Time to SET integers: 1.6766 Time to GET integers: 0.5020 Time to GET integers: 0.5139 Time to GET integers: 0.9007 Time to GET integers: 0.9223 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs 5,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 2.5191 Time to SET integers: 2.6676 Time to SET integers: 3.3990 Time to SET integers: 4.9568 Time to GET integers: 1.3661 Time to GET integers: 1.4093 Time to GET integers: 2.0144 Time to GET integers: 2.6770 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs 10,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 10.0263 Time to SET integers: 5.8289 Time to SET integers: 9.3263 Time to SET integers: 10.2020 Time to GET integers: 5.3923 Time to GET integers: 3.3081 Time to GET integers: 3.2209 Time to GET integers: 5.4117 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs 20,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 15.0419 Time to SET integers: 18.2819 Time to SET integers: 14.7576 Time to SET integers: 22.3435 Time to GET integers: 9.5388 Time to GET integers: 9.5052 Time to GET integers: 9.9704 Time to GET integers: 13.9207 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs 50,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 73.2189 Time to SET integers: 83.5524 Time to SET integers: 68.4244 Time to SET integers: 101.6177 Time to GET integers: 78.3893 Time to GET integers: 77.2465 Time to GET integers: 84.2608 Time to GET integers: 60.6623 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs 100,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 298.2182 Time to SET integers: 296.7654 Time to SET integers: 294.4335 Time to SET integers: 298.0808 Time to GET integers: 265.1449 Time to GET integers: 266.9922 Time to GET integers: 266.8074 Time to GET integers: 274.0365 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs 250,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 2281.5185 Time to SET integers: 2317.1292 Time to SET integers: 2268.9331 Time to SET integers: 2356.9431 Time to GET integers: 2214.9619 Time to GET integers: 2236.4405 Time to GET integers: 2239.2422 Time to GET integers: 2289.0354 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs 500,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: 10227.8703 Time to SET integers: 10255.9150 Time to SET integers: 10306.3266 Time to SET integers: 10393.5952 Time to GET integers: 9999.0337 Time to GET integers: 10217.8988 Time to GET integers: 10095.6638 Time to GET integers: 10271.2409 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs 750,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs 1,000,000 key/item pairs ---------------------------------- ---------------------------------- ---------------------------------- ---------------------------------- Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to SET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time to GET integers: >10000.0000 Time limit 1/2A limitation of the time consumption for a single time measurement has already been discussed regarding script 7) in the Map vs Dict Obj example above. Time limit 1.au3 with a 10 second limit on time measurements produces a report Time limit 1.txt: Map Data Type Integer Key Type Code executed as 32-bit code ================================== 100 key/item pairs ---------------------------------- Time to SET integers: 0.0562 Time to GET integers: 0.0269 500 key/item pairs ---------------------------------- Time to SET integers: 0.2455 Time to GET integers: 0.1247 1,000 key/item pairs ---------------------------------- Time to SET integers: 0.4710 Time to GET integers: 0.2477 2,000 key/item pairs ---------------------------------- Time to SET integers: 0.9444 Time to GET integers: 0.5020 5,000 key/item pairs ---------------------------------- Time to SET integers: 2.5191 Time to GET integers: 1.3661 10,000 key/item pairs ---------------------------------- Time to SET integers: 10.0263 Time to GET integers: 5.3923 20,000 key/item pairs ---------------------------------- Time to SET integers: 15.0419 Time to GET integers: 9.5388 50,000 key/item pairs ---------------------------------- Time to SET integers: 73.2189 Time to GET integers: 78.3893 100,000 key/item pairs ---------------------------------- Time to SET integers: 298.2182 Time to GET integers: 265.1449 250,000 key/item pairs ---------------------------------- Time to SET integers: 2281.5185 Time to GET integers: 2214.9619 500,000 key/item pairs ---------------------------------- Time to SET integers: 10227.8703 Time to GET integers: 9999.0337 750,000 key/item pairs ---------------------------------- Time to SET integers: >10000.0000 Time to GET integers: >10000.0000 1,000,000 key/item pairs ---------------------------------- Time to SET integers: >10000.0000 Time to GET integers: >10000.0000 But there is an issue at 500,000 key/item pairs. Here the SET-time has exceeded the 10 second limit, so the SET-code isn't executed for 750,000 key/item pairs. But the GET-time at 500,000 key/item pairs isn't exceeded, so the GET-code will be executed for 750,000 key/item pairs. The issue is that the GET-code is dependent on the SET-code. It makes no sense to time measure the GET-code if the SET-code isn't executed. Code has been added to the time measurement of the GET-time to handle this situation: ; Time test 1 $iTest = 0 If Not $aTimes[$iTest][2] Or ( $aTimes[$iTest][1] < $aTimes[$iTest][2] ) Then $hTimer = TimerInit() ; Time test 1 For $j = 0 To $iRows - 1 $mMap[$j] = $j Next $aTimes[$iTest][1] = TimerDiff( $hTimer ) Runtime_Info1( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][1], $aRuntime_Info, "Time to SET integers:" ) Else Runtime_Info2( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][2], $aRuntime_Info, "Time to SET integers:" ) EndIf ; Time test 2 ; Time test 2 is dependent on time test 1 being completed within the $iTest += 1 ; time limit. $aTimes[$iTest-1][0] indicates whether this is the case. If Not $aTimes[$iTest][2] Or ( $aTimes[$iTest-1][0] And $aTimes[$iTest][1] < $aTimes[$iTest][2] ) Then $hTimer = TimerInit() ; Time test 2 For $j = 0 To $iRows - 1 $v = $mMap[$j] Next ; $aTimes[$iTest-1][0] = 0 indicates that time test 1 wasn't completed within the time limit. $aTimes[$iTest][1] = TimerDiff( $hTimer ) ; Because $aTimes[$iTest-1][0] is set at this place in the code and not immediately after time If $aTimes[$iTest-1][1] > $aTimes[$iTest-1][2] Then $aTimes[$iTest-1][0] = 0 ; test 1, this test is still executed the FIRST time that time test 1 exceeds the time limit. Runtime_Info1( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][1], $aRuntime_Info, "Time to GET integers:" ) Else Runtime_Info2( 8+$iTest, $i, $iTests, $iLineLen, $aTimes[$iTest][2], $aRuntime_Info, "Time to GET integers:" ) EndIf In Time limit 2.au3 there are also time measurements on a Map data type of string keys. Here, the additional check in the GET-code that the SET-code has actually been executed must also be carried out for the string keys. 7z-fileThe 7z-file contains source code for include files and examples. You need AutoIt 3.3.16 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. Runtimes.7z1 point -
poker game to study, play, or whatever you want ! an old challenge of mine that I have given up #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=poker.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <Array.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration #Region === GUI === Local $Form1_1 = GUICreate("Poker", 769, 382, 374, 395) GUISetBkColor($COLOR_TEAL) GUISetIcon(@ScriptDir & "\spade.ico") Local $Pic1 = GUICtrlCreatePic("", 20, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic2 = GUICtrlCreatePic("", 170, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic3 = GUICtrlCreatePic("", 320, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic4 = GUICtrlCreatePic("", 470, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Pic5 = GUICtrlCreatePic("", 620, 60, 130, 190) GUICtrlSetState(-1, $GUI_DISABLE) Local $Hold1 = GUICtrlCreateLabel("", 20, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold2 = GUICtrlCreateLabel("", 170, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold3 = GUICtrlCreateLabel("", 320, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold4 = GUICtrlCreateLabel("", 470, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Hold5 = GUICtrlCreateLabel("", 620, 250, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Label1 = GUICtrlCreateLabel("", 20, 10, 587, 41, $SS_CENTER) GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFFFF) ;White Local $Label2 = GUICtrlCreateLabel("", 620, 10, 130, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFF00) ;Yellow Local $Button1 = GUICtrlCreateButton("START", 20, 320, 735, 35) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x000000) Local $Button2 = GUICtrlCreateButton("RED", 290, 280, 100, 35) GUICtrlSetState(-1, $GUI_HIDE) Local $Button3 = GUICtrlCreateButton("BLACK", 400, 280, 100, 35) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region === make the card === ;clubs diamonds hearts spades Local $aColor = ["clubs", "heart", "diamond", "spade"] Local $shColor = ["C", "H", "D", "S"] Local $k, $nMsg, $Str Local $at = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king", "ace"] Local $Oat = ["102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114"] Local $aCard[53][4] $aCard[0][0] = 52 $k = 1 For $C = 0 To UBound($aColor) - 1 For $j = 0 To UBound($at) - 1 $aCard[$k][0] = $aColor[$C] & "_" & $at[$j] ; card full name $aCard[$k][1] = $shColor[$C] ; suit $aCard[$k][2] = $at[$j] ; card $aCard[$k][3] = $Oat[$j] ; order $k += 1 Next Next ReplaceInArray($aCard, "jack", "J", 2) ReplaceInArray($aCard, "queen", "Q", 2) ReplaceInArray($aCard, "king", "K", 2) ReplaceInArray($aCard, "ace", "A", 2) $aColor = 0 $shColor = 0 $at = 0 $Oat = 0 ;_ArrayDisplay($aCard) _ArrayShuffle($aCard, 1) #EndRegion === make the card === Local $Rnt = 1, $Cnt = 1, $Score = 100, $GameMode = "Play", $WinAmount Local $HandCard[6][4] $HandCard[0][0] = 5 ;******************************************************************************* While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Pic1 If GUICtrlRead($Hold1) = "" Then GUICtrlSetData($Hold1, "Hold") Else GUICtrlSetData($Hold1, "") EndIf Case $Pic2 If GUICtrlRead($Hold2) = "" Then GUICtrlSetData($Hold2, "Hold") Else GUICtrlSetData($Hold2, "") EndIf Case $Pic3 If GUICtrlRead($Hold3) = "" Then GUICtrlSetData($Hold3, "Hold") Else GUICtrlSetData($Hold3, "") EndIf Case $Pic4 If GUICtrlRead($Hold4) = "" Then GUICtrlSetData($Hold4, "Hold") Else GUICtrlSetData($Hold4, "") EndIf Case $Pic5 If GUICtrlRead($Hold5) = "" Then GUICtrlSetData($Hold5, "Hold") Else GUICtrlSetData($Hold5, "") EndIf ;------------------- Case $Hold1 Case $Button1 ;deal Button1() Case $Button2 ;red Button2() Case $Button3 ;black Button3() EndSwitch WEnd ;******************************************************************************** ;------------------------------------------------------------------------------- Func Button1() ; deal , take Select Case $GameMode = "Play" ; then deal Deal() Case $GameMode = "Black-Red" ; then take $Score = $Score + $WinAmount GUICtrlSetState($Button2, $GUI_HIDE) GUICtrlSetState($Button3, $GUI_HIDE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetData($Label2, $Score) GUICtrlSetFont($Label2, 24, 800, 0, "MS Sans Serif") Sleep(500) GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif") ;GUICtrlSetFont($Label2, 17, 800, 0, "MS Sans Serif") ;GUICtrlSetColor($Label2, 0xFFFF00) ;Yellow $GameMode = "Play" GUICtrlSetData($Button1, "DEAL") GUISetBkColor($COLOR_TEAL) EndSelect EndFunc ;==>Button1 ;------------------------------------------------------------------------------- Func Button2() ;red CardColor("Red") EndFunc ;==>Button2 ;------------------------------------------------------------------------------- Func Button3() ;black CardColor("Black") EndFunc ;==>Button3 ;------------------------------------------------------------------------------- Func ReplaceInArray(ByRef $Array, $oStr, $nStr, $Col) For $i = 0 To UBound($Array) - 1 If $Array[$i][$Col] = $oStr Then $Array[$i][$Col] = $nStr ;ConsoleWrite ($oStr & " in " & $i & " to " & $nStr & @CRLF) EndIf Next ;ToConsole($Array, $Col) EndFunc ;==>ReplaceInArray ;------------------------------------------------------------------------------- Func ToConsole($Array, $Col) ;write array to console For $i = 0 To UBound($Array) - 1 ConsoleWrite($Array[$i][$Col] & " ") Next ConsoleWrite(@CRLF) EndFunc ;==>ToConsole ;------------------------------------------------------------------------------- Func TurnCards() ;TurnCards GUICtrlSetImage($Pic1, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic2, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic3, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic4, @ScriptDir & "\card\back04.jpg") GUICtrlSetImage($Pic5, @ScriptDir & "\card\back04.jpg") EndFunc ;==>TurnCards ;------------------------------------------------------------------------------- Func Deal() ;Deal the Cards Local $C, $R If $Rnt = 1 Then TurnCards() Sleep(300) _ArrayShuffle($aCard, 1) ckHolder() $Score = $Score - 1 GUICtrlSetData($Label2, $Score) GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[1][0] & ".jpg") GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[2][0] & ".jpg") GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[3][0] & ".jpg") GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[4][0] & ".jpg") GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[5][0] & ".jpg") For $C = 0 To 3 For $R = 1 To 5 $HandCard[$R][$C] = $aCard[$R][$C] Next Next ;_ArrayDisplay($HandCard, "Deal") ToConsole($HandCard, 2) $Rnt = 2 $Cnt = 6 Else If GUICtrlRead($Hold1) = "" Then GUICtrlSetImage($Pic1, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[1][0] = $aCard[$Cnt][0] $HandCard[1][1] = $aCard[$Cnt][1] $HandCard[1][2] = $aCard[$Cnt][2] $HandCard[1][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold2) = "" Then GUICtrlSetImage($Pic2, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[2][0] = $aCard[$Cnt][0] $HandCard[2][1] = $aCard[$Cnt][1] $HandCard[2][2] = $aCard[$Cnt][2] $HandCard[2][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold3) = "" Then GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[3][0] = $aCard[$Cnt][0] $HandCard[3][1] = $aCard[$Cnt][1] $HandCard[3][2] = $aCard[$Cnt][2] $HandCard[3][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold4) = "" Then GUICtrlSetImage($Pic4, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[4][0] = $aCard[$Cnt][0] $HandCard[4][1] = $aCard[$Cnt][1] $HandCard[4][2] = $aCard[$Cnt][2] $HandCard[4][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf If GUICtrlRead($Hold5) = "" Then GUICtrlSetImage($Pic5, @ScriptDir & "\card\" & $aCard[$Cnt][0] & ".jpg") $HandCard[5][0] = $aCard[$Cnt][0] $HandCard[5][1] = $aCard[$Cnt][1] $HandCard[5][2] = $aCard[$Cnt][2] $HandCard[5][3] = $aCard[$Cnt][3] $Cnt += 1 EndIf ckHolder() ToConsole($HandCard, 2) ChekForWin() $Rnt = 1 EndIf EndFunc ;==>Deal ;------------------------------------------------------------------------------- Func ckHolder() ;Check the Holders If GUICtrlRead($Label2) = "" Then GUICtrlSetData($Label2, $Score) If $Rnt = 1 Then ConsoleWrite("********************" & @CRLF) ConsoleWrite($Rnt & " Round ------------" & @CRLF) GUICtrlSetData($Button1, "OK") GUICtrlSetFont($Label1, 18, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "hold your cards") GUICtrlSetState($Pic1, $GUI_ENABLE) GUICtrlSetState($Pic2, $GUI_ENABLE) GUICtrlSetState($Pic3, $GUI_ENABLE) GUICtrlSetState($Pic4, $GUI_ENABLE) GUICtrlSetState($Pic5, $GUI_ENABLE) GUICtrlSetData($Hold1, "") GUICtrlSetData($Hold2, "") GUICtrlSetData($Hold3, "") GUICtrlSetData($Hold4, "") GUICtrlSetData($Hold5, "") ElseIf $Rnt = 2 Then ConsoleWrite($Rnt & " Round ------------" & @CRLF) GUICtrlSetData($Button1, "DEAL") ;GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetState($Pic1, $GUI_DISABLE) GUICtrlSetState($Pic2, $GUI_DISABLE) GUICtrlSetState($Pic3, $GUI_DISABLE) GUICtrlSetState($Pic4, $GUI_DISABLE) GUICtrlSetState($Pic5, $GUI_DISABLE) GUICtrlSetData($Hold1, "") GUICtrlSetData($Hold2, "") GUICtrlSetData($Hold3, "") GUICtrlSetData($Hold4, "") GUICtrlSetData($Hold5, "") ElseIf $Rnt = 3 Then EndIf EndFunc ;==>ckHolder ;------------------------------------------------------------------------------- Func ChekForWin() ;Check for Win Local $tmpHand, $CardStr = "" _ArraySort($HandCard, 0, 1, 0, 3) ; array sort by card order ;_ArrayDisplay($HandCard, "ChekForWin") ;------------------------------------------------------------------------------------ ; Flush For $i = 1 To $HandCard[0][0] $CardStr = $CardStr & $HandCard[$i][1] Next Select Case $CardStr = "CCCCC" $tmpHand = "Flush" Case $CardStr = "DDDDD" $tmpHand = "Flush" Case $CardStr = "HHHHH" $tmpHand = "Flush" Case $CardStr = "SSSSS" $tmpHand = "Flush" EndSelect ;------------------------------------------------------------------------------------ $CardStr = "" For $i = 1 To $HandCard[0][0] $CardStr = $CardStr & $HandCard[$i][2] Next ConsoleWrite("ChekForWin ---------" & @CRLF) ConsoleWrite("$CardStr = " & $CardStr & @CRLF) ConsoleWrite("$tmpHand1 = " & $tmpHand & @CRLF) ;------------------------------------------------------------------------------------ If $tmpHand = "Flush" Then Select Case StringInStr($CardStr, "10JQKA") > 0 And $tmpHand = "Flush" $tmpHand = "Royal Flush" Case StringInStr($CardStr, "910JQK") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "8910JQ") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "78910J") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "678910") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "56789") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "45678") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "34567") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case StringInStr($CardStr, "23456") > 0 And $tmpHand = "Flush" $tmpHand = "Straight Flush" Case Else $tmpHand = "Flush" EndSelect Else Select Case StringInStr($CardStr, "2222") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "3333") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "4444") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "5555") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "6666") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "7777") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "8888") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "9999") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "10101010") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "JJJJ") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "QQQQ") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "KKKK") > 0 $tmpHand = "Four of kind" Case StringInStr($CardStr, "AAAA") > 0 $tmpHand = "Four of kind" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22333") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22444") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22233") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22244") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22255") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22266") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22277") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22288") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "22299") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "2221010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "222AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "33444") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33344") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33355") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33366") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33377") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33388") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "33399") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "3331010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "333AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------" Case StringInStr($CardStr, "44555") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44455") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44466") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44477") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44488") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "44499") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "4441010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "444AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "55666") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55566") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55577") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55588") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "55599") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "5551010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "555AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "66777") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66677") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66688") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "66699") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "6661010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "666AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "77888") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77788") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "77799") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "7771010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "777AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "88999") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "88899") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "8881010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "888AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "99101010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "99AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "9991010") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "999AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "1010JJJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010QQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010KKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "1010AAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010JJ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010QQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010KK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "101010AA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "JJQQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJKKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJQQ") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "JJJAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "QQKKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQQKK") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "QQQAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "KKAAA") > 0 $tmpHand = "Full house" Case StringInStr($CardStr, "KKKAA") > 0 $tmpHand = "Full house" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "10JQKA") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "910JQK") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "8910JQ") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "78910J") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "678910") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "56789") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "45678") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "34567") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "23456") > 0 $tmpHand = "Straight" Case StringInStr($CardStr, "A2345") > 0 $tmpHand = "Straight" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "222") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "333") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "444") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "555") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "666") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "777") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "888") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "999") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "101010") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "JJJ") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "QQQ") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "KKK") > 0 $tmpHand = "Three of kind" Case StringInStr($CardStr, "AAA") > 0 $tmpHand = "Three of kind" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "33") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "44") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "22") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "44") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "33") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "55") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "44") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "66") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "55") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "77") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "66") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "88") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "77") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "99") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "88") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "1010") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "99") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "JJ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "1010") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "QQ") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "JJ") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "KK") > 0 $tmpHand = "Two pair" Case StringInStr($CardStr, "QQ") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "KK") > 0 And StringInStr($CardStr, "AA") > 0 $tmpHand = "Two pair" ;------------------------------------------------------------------------------------ Case StringInStr($CardStr, "22") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "33") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "44") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "55") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "66") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "77") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "88") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "99") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "1010") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "JJ") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "QQ") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "KK") > 0 $tmpHand = "Pair" Case StringInStr($CardStr, "AA") > 0 $tmpHand = "Pair" ;------------------------------------------------------------------------------------ EndSelect EndIf ConsoleWrite("$tmpHand2 = " & $tmpHand & @CRLF) If $tmpHand = "" Then ;nothing to win Else TakeWin($tmpHand) EndIf EndFunc ;==>ChekForWin ;------------------------------------------------------------------------------- Func TakeWin($Hand) ;amount to take Local $Msg Select ;win $Hand Case $Hand = "Royal Flush" $WinAmount = 89 Case $Hand = "Straight Flush" $WinAmount = 55 Case $Hand = "Flush" $WinAmount = 34 Case $Hand = "Four of kind" $WinAmount = 21 Case $Hand = "Full house" $WinAmount = 13 Case $Hand = "Straight" $WinAmount = 8 Case $Hand = "Three of kind" $WinAmount = 5 Case $Hand = "Two pair" $WinAmount = 3 Case $Hand = "Pair" $WinAmount = 2 EndSelect GUICtrlSetState($Button1, $GUI_DISABLE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, $Hand) ; blink GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White Sleep(300) GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White Sleep(300) GUICtrlSetColor($Label1, 0xFF0000) ;red Sleep(300) GUICtrlSetColor($Label1, 0xFFFFFF) ;White ConsoleWrite("TakeWin ------------" & @CRLF) BlackRed() EndFunc ;==>TakeWin ;------------------------------------------------------------------------------- Func BlackRed() ;Black Red bet Local $Msg TurnCards() $Msg = "Win amount " & $WinAmount & ", choose black - red to double it or press take to take it" ;GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetFont($Label1, 12, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, $Msg) $GameMode = "Black-Red" GUICtrlSetData($Button1, "TAKE") GUISetBkColor($COLOR_PURPLE) ; will change background color GUICtrlSetState($Button1, $GUI_ENABLE) GUICtrlSetState($Button2, $GUI_SHOW) GUICtrlSetState($Button3, $GUI_SHOW) ;GUICtrlSetState($Button1, $GUI_ENABLE) ConsoleWrite("Win amount = " & $WinAmount & @CRLF) EndFunc ;==>BlackRed ;------------------------------------------------------------------------------- Func CardColor($crdColor) ; check Black Red bet Local $Par1, $Par2 If $crdColor = "Red" Then $Par1 = "D" $Par2 = "H" Else $Par1 = "C" $Par2 = "S" EndIf Local $X = $Cnt, $CardColor $Cnt += 1 GUICtrlSetImage($Pic3, @ScriptDir & "\card\" & $aCard[$X][0] & ".jpg") Sleep(1000) $CardColor = $aCard[$X][1] If $CardColor = $Par1 Or $CardColor = $Par2 Then ;win $WinAmount = $WinAmount + $WinAmount BlackRed() Else $WinAmount = 0 ConsoleWrite("Win amount = " & 0 & @CRLF) TurnCards() GUICtrlSetState($Button2, $GUI_HIDE) GUICtrlSetState($Button3, $GUI_HIDE) GUICtrlSetFont($Label1, 24, 800, 0, "MS Sans Serif") GUICtrlSetData($Label1, "") GUICtrlSetData($Label2, $Score) $GameMode = "Play" GUICtrlSetData($Button1, "DEAL") GUISetBkColor($COLOR_TEAL) EndIf EndFunc ;==>CardColor ;------------------------------------------------------------------------------- Please, leave your comments and experiences here Thank you ! card_deck.zip RegExp shorter version 🏆 thanks to @jugador1 point
-
Moved to the appropriate forum. Moderation Team1 point
-
WebDriver UDF - Help & Support (IV)
SOLVE-SMART reacted to Danp2 for a topic
@DoVinhTrungI imagine that you would get the same result if you ran the same Javascript code from the Dev Tools console. This would indicate that something is incorrect with your JS code. On second glance, you aren't returning a value, so that would explain the null. Try prepending "return " to your JS code. Also, you should explain why you are attempting to retrieve the text this way instead of using _WD_ElementAction.1 point -
No idea... but these are the proper options available in the latest version and when I set it to: ## ================================================ ## Separate settings for debugging these Lua files ## ================================================ #> Enable debugging for these lua scripts: #~ debug.autoittools=n debug.autoitdynamicincludes=y #~ debug.autoitautocomplete=n #~ debug.autoitgotodefinition=n #~ debug.autoitindentfix=n #> when debug.tofile is defined, log records will be send to the log in stead of OutputPane: #~ debug.tofile=$(SciteUserHome)\SciTE_LUA_Scripts_Debug.err The SciTE Console log will shown when debug is active: >>> AutoItDynamicIncludes debugging on to file: "C:\Users\xxxx\AppData\Local\AutoIt v3\SciTE\SciTE_LUA_Scripts_Debug.err" (1,1) --> Double Click to open. Jos1 point
-
Use BitAnd to determine if the window is visible -- If BitAnd($State, $WIN_STATE_VISIBLE) Then WinSetState ("authserver.exe", "", @SW_HIDE) Else WinSetState ("authserver.exe", "", @SW_SHOW) EndIf1 point
-
SAX-XML-Parser in pure AutoIt
ioa747 reacted to AspirinJunkie for a topic
Introduction: To parse XML data, a so-called DOM parser is usually used - e.g. the Microsoft.XMLDOM object. This parser goes through the entire structure and rebuilds it hierarchically in its own data structure. Afterwards you can continue working on this basis. In other programming languages, however, one occasionally encounters a different approach: the SAX parser. Here the idea is as follows: The parser traverses the XML string and calls user-defined functions at certain breakpoints. Usually this would be at the beginning of an element, for example. The parser then passes the element type, the position in the string and the attributes of the element to the user-defined function. The parser doesn't care what the user does with it - it just calls functions at the breakpoints. Further breakpoints would be when closing an element or as soon as the content of an element has been reached. This approach has advantages as well as disadvantages. The advantage is that the user can decide what is really needed and what is not. This can result in faster parsing. Also it is possible to process the data before it is completely loaded or processed. The disadvantage however is that the work with this can not only take some getting used to but also quickly become very complex. In particular, since it is important for a reasonable processing to exchange information between the individual user functions one will have to use global variables. Example of use: The following example reads the Autoitscript.com forum page and extracts a list of recent topics using the SAX parser: To use or not? So what's the point of all this? For most use cases I think it is better to use the known DOM-based approaches, because working with a SAX parser can quickly degenerate into enormous complexity. However, a certain acceleration can(!) be achieved with this approach. I have tested this in the example above: If I process the page with the HTMLFile object, it needs ~150ms for parsing alone. The topics were already processed with the SAX parser after 60ms (the parsing continues - but can be stopped). The question is whether the higher complexity for the user is worth it for these cases. The Sax parser also reacts more kindly to errors in the XML file in many cases and could be used as a more robust alternative. With the SAX parser as a fundament, it should also be fairly easy to write your own purely AutoIt-based DOM parser. And last but not least, we can now say for AutoIt: Now we have our own Sax parser too! >>sourcecode and download on github<<1 point -
It would probably be helpful if you provided the output that you get from your xslx range read (what does $ListOfPrograms look like? Can you send a screenshot of the _ArrayDisplay?) Another option would be to just use a simple text file, and read that to an array instead of involving the whole excel stack of things. I also can't help you test your provided code as I don't have Excel and the functions don't work without it. Here's my suggestion, using just a text file: #include <Array.au3> Local $hRunTimer = -1 Local $aListOfPrograms = FileReadToArray(@ScriptDir & '\test.txt') _ArrayDisplay($aListOfPrograms) For $i = 0 To UBound($aListOfPrograms) - 1 If FileExists($aListOfPrograms[$i]) = 0 Then __cLog('File does not exist: ' & $aListOfPrograms[$i]) ContinueLoop EndIf $hRunTimer = TimerInit() __cLog('Program to run: ' & $aListOfPrograms[$i]) RunWait($aListOfPrograms[$i]) __cLog(' Finished in ' & Round(TimerDiff($hRunTimer), 2) & 'ms') Next Func __cLog($sMsg = '') ConsoleWrite($sMsg & @CRLF) EndFunc ;==>__cLog and the test.txt file: script1.exe "c:\script2.exe" meow.asdf Unless you provide an example .xslx for people to use I don't think there's a lot of help you can get with the Excel functions since we don't know what format you're using. I would still recommend using just a simple text file however. If you need more 'columns' of data, such as parameters for the scripts, I would use a CSV format or something similar and use StringSplit to break it up and get your parameters or other information.1 point