Sunaj Posted December 11, 2006 Share Posted December 11, 2006 (edited) Hi, I created the following little program that among other things can be used to demonstrate the speed difference between the Official AU3 release and the beta (yes, there IS a 100% speed increase, run this program and check it for yourself!). Please note that J.Prime contains a quite nice (though basic) prime number checker that could find use in many other contexts (or simply for learning purposes). Please post improvements.., speed results, etc. Enjoy Sunaj Edit: focus on primes expandcollapse popup#include <Math.au3> #include <GUIConstants.au3> #include <Array.au3> #NoTrayIcon ; hide icon from icontray Opt("GUIOnEventMode", 1) Opt("SendKeyDelay", 1) GUICreate("J.Prime",330,140,-1,-1,$WS_SYSMENU,$WS_EX_TOOLWINDOW + $WS_EX_APPWINDOW) GUICtrlCreateLabel ( _ "This is a prime benchmark for AU3, it computes all primes from" & @CRLF & _ "0 - 10.000 && puts the primes in a file and then returns the time" & @CRLF & _ "used in seconds - save includes time stats for future reference.",10,10) $h_StartButton= GUICtrlCreateButton("Start Computing",10,56,100,19) GUICtrlSetOnEvent (-1, "func_StartButton" ) $h_ShowFileButton= GUICtrlCreateButton("Show Primes",214,56,100,19) GUICtrlSetOnEvent (-1, "func_ShowFileButton" ) GUICtrlSetState(-1, $GUI_DISABLE) $h_ProgressBar = GuiCtrlCreateProgress(10,85,304,19,$PBS_SMOOTH) $h_hidden = GUICtrlCreateButton("hidden",1,1) ; fix for button focus issue, see func_ButtonfocusFix() GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetState(-1, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "func_Close") GUISetState() $i_CounterForProgressBar = 0 Func func_StartButton() func_ButtonfocusFix() $i_TimerStart = TimerInit() GUICtrlSetData ($h_StartButton,"Please Wait") GUICtrlSetState($h_StartButton, $GUI_DISABLE) Dim $a_PrimeList[1] $i_PrimeCeiling = 10000 $i_PrimeCandidate = 2 While $i_PrimeCandidate <= $i_PrimeCeiling $i_Divisor = 2 $i_PrimeTest = 1 ; assume current $i_PrimeCandidate IS a prime While ($i_Divisor * $i_Divisor <= $i_PrimeCandidate) If Mod($i_PrimeCandidate,$i_Divisor) = 0 Then $i_PrimeTest = 0 ; current $i_PrimeCandidate IS NOT a prime ExitLoop EndIf $i_Divisor += 1 Wend If $i_PrimeTest <> 0 Then _ArrayAdd($a_PrimeList,$i_PrimeCandidate) EndIf $i_PrimeCandidate += 1 $i_CounterForProgressBar += 0.01 ; allow correct countup to 100 (which is max of $h_ProgressBar) GUICtrlSetData ($h_ProgressBar,$i_CounterForProgressBar) Wend $i_TimeUsed = TimerDiff($i_TimerStart) $i_TimeUsed = "Seconds used: " & $i_TimeUsed/1000 MsgBox(4096, "Time benchmark", $i_TimeUsed) GUICtrlSetData ($h_ProgressBar,0) ; clear $h_ProgressBar for next run GUICtrlSetData ($h_StartButton,"Start Computing") GUICtrlSetState($h_StartButton, $GUI_ENABLE) _ArrayDelete ($a_PrimeList,0) ; remove empty index key in array before converting to string $s_PrimesString = _ArrayToString($a_PrimeList,@CRLF) $f_PrimesTxt = FileOpen ("primes.txt",2) FileWrite($f_PrimesTxt,$i_TimeUsed & @CRLF & @CRLF) FileClose($f_PrimesTxt) ;close $f_PrimesTxt to allow for next line $f_PrimesTxt = FileOpen ("primes.txt",1) ; change write mode to append to end of $f_PrimesTxt FileWrite($f_PrimesTxt,$s_PrimesString) FileClose($f_PrimesTxt) GUICtrlSetState($h_ShowFileButton, $GUI_ENABLE) EndFunc Func func_ButtonfocusFix() ; lets focus behave as in standard windows application (does NOT leave black selection around clicked button) GUICtrlSetState(@GUI_CtrlId, $GUI_HIDE) GUICtrlSetState($h_hidden, $GUI_FOCUS) GUICtrlSetState(@GUI_CtrlId, $GUI_SHOW) Endfunc Func func_ShowFileButton() ; opens primes.txt in notepad func_ButtonfocusFix() Run("Notepad.exe " & @ScriptDir & "\primes.txt", "") Endfunc Func func_Close() Exit EndFunc While 1 Sleep(500) Wend Edited December 12, 2006 by Sunaj [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
RazerM Posted December 11, 2006 Share Posted December 11, 2006 Very big time difference! 4.95654922622847 seconds for beta and 9.01754915778402 seconds for release. My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Sunaj Posted December 12, 2006 Author Share Posted December 12, 2006 Yea.. exactly.. rather extreme time difference! Btw, for people interested in prime numbers there is an excellent tutorial available at Fun With Prime Numbers that teaches all the basics for programming both basic (J.Prime) and advanced prime number crunchers. The tutorial is in C++ but is relatively easily translatable into AU3 context! My Intel Core Duo 1.83 (T2400) can do 3.02742527332384 for the beta and 5.91007153143766 for release.Very big time difference! 4.95654922622847 seconds for beta and 9.01754915778402 seconds for release. [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
the DtTvB Posted December 12, 2006 Share Posted December 12, 2006 Oh, my computer, maybe, is slow. Seconds used: 27.486799299911. [right]Please visit: My biggest project, the DtTvB's AutoIt Web ServerOlder Stuff: A Smoother MouseMove :: AutoIt Syntax Highlighter[/right] Link to comment Share on other sites More sharing options...
RazerM Posted December 12, 2006 Share Posted December 12, 2006 My PC has a Pentium 4 2.8GHz CPU. My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
FuryCell Posted December 12, 2006 Share Posted December 12, 2006 (edited) Nice script. Here are the results from my PC.Seconds used: 15.40275900987422.0 ghz P4 Edited December 12, 2006 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
gamepin126 Posted December 12, 2006 Share Posted December 12, 2006 Seconds used: 4.75806170896022What good is a dual core if you can't brag about 2 second benchmarks xD Link to comment Share on other sites More sharing options...
Sunaj Posted December 12, 2006 Author Share Posted December 12, 2006 (edited) Thanks - were you using the beta or release version of AU3? (this question goes for gamepin126 too!)Edit: question for gamepin126 too (since this is rather important when it comes to bragging )Nice script. Here are the results from my PC.2.0 ghz P4 Edited December 12, 2006 by Sunaj [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list] Link to comment Share on other sites More sharing options...
Zedna Posted December 12, 2006 Share Posted December 12, 2006 Nice new benchamark Here is my result: 5.6s / 10.5s with AthlonXP 1700+ on WIN98 I'm looking forward to new AutoIt with compiling to bytecode. So my question is: Will be even more quick this precompiled bytecode? Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
gamepin126 Posted December 19, 2006 Share Posted December 19, 2006 I was using the beta. Link to comment Share on other sites More sharing options...
Jabberwock Posted December 20, 2006 Share Posted December 20, 2006 3.51455981435097 for the beta and 6.55561284051263 for the release pretty big difference, I never use the release anyway Link to comment Share on other sites More sharing options...
JoshDB Posted December 20, 2006 Share Posted December 20, 2006 1.9 for the beta and 3.2 for the release. Nice checker, and good to know Beta is really an improvement aside from functions. Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite Link to comment Share on other sites More sharing options...
jaenster Posted February 13, 2007 Share Posted February 13, 2007 3,887 -jaenster Link to comment Share on other sites More sharing options...
bonebreaker Posted February 17, 2007 Share Posted February 17, 2007 Nice, I made a faster way for you to check for primes (it makes it in less than half time) , implement it if you want to: $searchlimit=10000 ;your method $timer=TimerInit() $primes=$searchlimit for $check=2 to $searchlimit $divisor=2 while $check >= $divisor*$divisor if mod($check,$divisor)=0 Then $primes -=1 exitloop endif $divisor +=1 wend next msgbox(0,"your method","Speed: "&TimerDiff($timer)/1000&" Primes: "&$primes) ;my method $timer=TimerInit() $primes=$searchlimit/2 for $check=3 to $searchlimit step 2 $divisor=3 while $check >= $divisor*$divisor if mod($check,$divisor)=0 Then $primes -=1 exitloop endif $divisor +=2 wend next msgbox(0,"my method","Speed: "&TimerDiff($timer)/1000&" Primes: "&$primes) My programs:[topic="40019"]Sudoku[/topic], [topic="41258"]Suitcase game & Random jokes[/topic], [topic="41641"]8 Queens[/topic], [topic="41679"]Puzzle Generator[/topic], [topic="42045"]Snake[/topic]My UDFs:[topic="41309"]Prime functions & Prime game[/topic]Other:Fake emailer Link to comment Share on other sites More sharing options...
KJohn Posted February 17, 2007 Share Posted February 17, 2007 Your Method: 6.81 secondsMy method (modification of the prime number generation part only): 2.76 secondsI used the same method in C++, just ported the algorithm over to AutoIt. Makes a huge difference when you go for higher primes than the limit you've specified. Tell me what you think?There are many neat little programming tricks like this. If you like challenges, try making a program similar to this:http://www.autoitscript.com/forum/index.php?showtopic=40627expandcollapse popup#NoTrayIcon AutoItSetOption("MustDeclareVars", 0) AutoItSetOption("RunErrorsFatal", 0) AutoItSetOption("TrayIconDebug", 0) Opt("GUIOnEventMode", 1) Opt("SendKeyDelay", 1) Break(0) #include <GUIConstants.au3> #include <Array.au3> GUICreate("J.Prime (Optimized by K.John)",330,140,-1,-1,$WS_SYSMENU,$WS_EX_TOOLWINDOW + $WS_EX_APPWINDOW) GUICtrlCreateLabel ( _ "This is a prime benchmark for AU3, it computes all primes from" & @CRLF & _ "0 - 10.000 && puts the primes in a file and then returns the time" & @CRLF & _ "used in seconds - save includes time stats for future reference.",10,10) $h_StartButton= GUICtrlCreateButton("Start Computing",10,56,100,19) GUICtrlSetOnEvent (-1, "func_StartButton" ) $h_ShowFileButton= GUICtrlCreateButton("Show Primes",214,56,100,19) GUICtrlSetOnEvent (-1, "func_ShowFileButton" ) GUICtrlSetState(-1, $GUI_DISABLE) $h_ProgressBar = GuiCtrlCreateProgress(10,85,304,19,$PBS_SMOOTH) $h_hidden = GUICtrlCreateButton("hidden",1,1) ; fix for button focus issue, see func_ButtonfocusFix() GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetState(-1, $GUI_FOCUS) GUISetOnEvent($GUI_EVENT_CLOSE, "func_Close") GUISetState() $i_CounterForProgressBar = 0 Func func_StartButton() func_ButtonfocusFix() $i_TimerStart = TimerInit() GUICtrlSetData ($h_StartButton,"Please Wait") GUICtrlSetState($h_StartButton, $GUI_DISABLE) Dim $primes[1] $primes[0] = 2 $i = 1 $max = 10000 $size = 0 For $i = 3 To $max Step 2 $i_CounterForProgressBar += 0.02 ; allow correct countup to 100 (which is max of $h_ProgressBar) GUICtrlSetData ($h_ProgressBar,$i_CounterForProgressBar) $j = 0 While $primes[$j] * $primes[$j] <= $i If Mod($i, $primes[$j]) = 0 Then ContinueLoop 2 $j = $j + 1 WEnd $size = $size + 1 ReDim $primes[$size + 1] $primes[$size] = $i Next $i_TimeUsed = TimerDiff($i_TimerStart) $i_TimeUsed = "Seconds used: " & $i_TimeUsed/1000 MsgBox(4096, "Time benchmark", $i_TimeUsed) GUICtrlSetData ($h_ProgressBar,0) ; clear $h_ProgressBar for next run GUICtrlSetData ($h_StartButton,"Start Computing") GUICtrlSetState($h_StartButton, $GUI_ENABLE) $s_PrimesString = _ArrayToString($primes,@CRLF) $f_PrimesTxt = FileOpen ("primes.txt",2) FileWrite($f_PrimesTxt,$i_TimeUsed & @CRLF & @CRLF) FileClose($f_PrimesTxt) ;close $f_PrimesTxt to allow for next line $f_PrimesTxt = FileOpen ("primes.txt",1) ; change write mode to append to end of $f_PrimesTxt FileWrite($f_PrimesTxt,$s_PrimesString) FileClose($f_PrimesTxt) GUICtrlSetState($h_ShowFileButton, $GUI_ENABLE) EndFunc Func func_ButtonfocusFix() ; lets focus behave as in standard windows application (does NOT leave black selection around clicked button) GUICtrlSetState(@GUI_CtrlId, $GUI_HIDE) GUICtrlSetState($h_hidden, $GUI_FOCUS) GUICtrlSetState(@GUI_CtrlId, $GUI_SHOW) Endfunc Func func_ShowFileButton() ; opens primes.txt in notepad func_ButtonfocusFix() Run("Notepad.exe " & @ScriptDir & "\primes.txt", "") Endfunc Func func_Close() Exit EndFunc While 1 Sleep(500) Wend Link to comment Share on other sites More sharing options...
bonebreaker Posted February 17, 2007 Share Posted February 17, 2007 wow, I installed beta version and its much much faster 2.7 in the original way 1.2 with mine My programs:[topic="40019"]Sudoku[/topic], [topic="41258"]Suitcase game & Random jokes[/topic], [topic="41641"]8 Queens[/topic], [topic="41679"]Puzzle Generator[/topic], [topic="42045"]Snake[/topic]My UDFs:[topic="41309"]Prime functions & Prime game[/topic]Other:Fake emailer Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now