Jump to content
Sign in to follow this  

For loop vs Select case

Recommended Posts

So i was wondering which one is faster if i want to do something like this:

Check a bunch of string with StringRegExp, would it be faster to

1) Use for loop and loop till i get the correct string then exitloop


2) using Select Case to filter through to find the correct string

For sure using the for loop will produce a much cleaner code, however i am interested in which one provides better speed

thanks for help

Share this post

Link to post
Share on other sites

You can find that by yourself - just time the execution for both and see which is faster.

Faster or slower depends on what code you have inside these loops.

You can see what difference it makes when you comment/uncomment $ttt=1 in the For/Next loop.

$str = ""
For $i = 1 to 100000
    $str &= Chr(Random(97, 121, 1))
$str &= "z"
$CharARR = StringSplit($str, "")

$forTIME = TimerInit()
For $i = 1 to $CharARR[0]
    ;$ttt = 1
    If $CharARR[$i] = "z" Then ExitLoop
ConsoleWrite("For: "&TimerDiff($forTIME)&@CRLF)

$i = 1
$SelectTIME = TimerInit()
    $i += 1
Until $CharARR[$i] = "z"
ConsoleWrite("Do: "&TimerDiff($SelectTIME)&@CRLF)

So - to answer your question: it depends on the code you want to use - test and see.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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...