Jump to content
Sign in to follow this  
WolfWorld

will using Const make the script goes faster

Recommended Posts

- -* so which one

what about

Global Const $a = 5

while 1

If stringregexp($a,'5') then ...

wend

and

Global $a = 5

while 1

If stringregexp($a,'5') then ...

wend

is anyone of it gona be faster ??

Edited by athiwatc

Share this post


Link to post
Share on other sites

try something like this to test:

Global $a = 5
$t = TimerInit()
For $x = 1 to 1000000
    If StringRegExp($a, '5') Then 
    EndIf
Next
ConsoleWrite('@@ (6) :(' & @min & ':' & @sec & ') TimerDiff($t) = ' & TimerDiff($t) & @CRLF);### Debug Console

and then

Global const $a = 5
$t = TimerInit()
For $x = 1 to 1000000
    If StringRegExp($a, '5') Then 
    EndIf
Next
ConsoleWrite('@@ (6) :(' & @min & ':' & @sec & ') TimerDiff($t) = ' & TimerDiff($t) & @CRLF);### Debug Console

Run both a couple of times and see if there is a difference.


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I know it was posted in 2007, but if somebody still want to know if script works faster with Const, it may not work faster.
Tested on my computer, it may be different in your computer, sorry for this messy script:
 

Global $nct = 0, $yct = 0
Global $number = 63064;Recommended to use 100000
Global Const $numberConst = $number
Global $a = $number
Global Const $b = $number
MsgBox(0,Null,"Please close programs to avoid high CPU/RAM usage."&@CRLF&"Press OK to continue.")
sleep(1000)
For $i = 0 to 10
    $t = Null
    sleep(100)

    $t = TimerInit()
    For $x = 1 to $a
        If StringRegExp($a, $number) Then
        EndIf
    Next
    $nct += TimerDiff($t)

    $t = Null
    sleep(100)

    $t = TimerInit()
    For $x = 1 to $b
        If StringRegExp($b, $numberConst) Then
        EndIf
    Next
    $yct += TimerDiff($t)

Next
MsgBox(0,Null,"Global Const took "&$yct&"ms"&@CRLF&"Global took "&$nct&"ms" & @CRLF)
MsgBox(0,Null,"Differience "&Round($yct/$nct*100,5)&"%" & @CRLF)
sleep(2000)

 

Edited by algiuxas

42783.png

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...