HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Quick question on loop checks...

10-08-2007, 03:56 AM#1
MrApples
Which is faster? Thought came to me as I was looking at a script and noticing how it's similar to a sort function I was working on last week.

A
Collapse JASS:
loop
    exitwhen a > amax
    loop
        exitwhen b > bmax
        if (Array1[a] == Array2[b])
            do stuff
            exitwhen true
        endif
        set b = b + 1
    endloop
    set a = a + 1
    set b = 1
endloop

OR

B
Collapse JASS:
loop
    exitwhen a > amax
    loop
        exitwhen b > bmax
        if (Array1[a] == Array2[b])
            do stuff
            set Array2[b] = Array2[bmax]
            set bmax = b - 1
            exitwhen true
        endif
        set b = b + 1
    endloop
    set a = a + 1
    set b = 1
endloop

I'm almost certain it is B. Part of the reason for me posting this is that if it is faster, this would be a good habit to adapt for anyone.
10-08-2007, 04:10 AM#2
PipeDream
In general contexts, they do different things. If you're concerned about speed, and you also have a ">" or hashing operation, then for amax,bmax > 15 or so you can implement set/setlike intersection faster.
10-08-2007, 04:51 AM#3
MrApples
Your saying a set/setlike intersection(which is?) is something I should be using instead of '>' and hashing operations(which is?)?

They really do the same thing, its just that the 'do stuff' part is not full. The second in return for 2 extra var sets and a subtraction makes half as many checks on average.
10-09-2007, 11:54 PM#4
MrApples
Eh? I would actually like to know, please
10-10-2007, 08:47 PM#5
botanic
The fastest would be dependent on application to be quire honist
10-11-2007, 12:47 AM#6
MrApples
Yes, but I want to know what Pipe was talking about exactly. I can't tell if he's telling me I'm doing something wrong, or there something else I also could be doing for larger sets.