Jump to content
Sign in to follow this  
Hooch

Question regarding WinActivate

Recommended Posts

When you call WinActivate() what is the behaivor if the window that is called to be activated is already active? Do I save processing if I do a ....

If WinActive("window1") Then
    WinActivate("window2")
endIf

... or does the function check that and not bother if the window is already active?

I just want to be as efficient as possible....

Share this post


Link to post
Share on other sites

When you call WinActivate() what is the behaivor if the window that is called to be activated is already active? Do I save processing if I do a ....

If WinActive("window1") Then
    WinActivate("window2")
endIf

... or does the function check that and not bother if the window is already active?

I just want to be as efficient as possible....

<{POST_SNAPBACK}>

WinActivate() will give the focus to the specified window. Nothing happends when the Window already has the focus....

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

ah ok, so with the extra if clause Im costing myself cpu cycles..... thanks.

I knew it worked fine either way, I just wasn't sure which was more efficient.

Edited by Hooch

Share this post


Link to post
Share on other sites

WinActivate("E:\AutoIt")

Sleep(100)

$t = TimerInit()
If NOT WinActive("E:\AutoIt") Then WinActivate("E:\AutoIt")
ConsoleWrite(Timerdiff($t) & @CR); gives +/- 0.6

$t = TimerInit()
WinActivate("E:\AutoIt")
ConsoleWrite(Timerdiff($t) & @CR); gives +/- 250.0

so the 1st method is way better


My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Share this post


Link to post
Share on other sites

WinActivate("E:\AutoIt")

Sleep(100)

$t = TimerInit()
If NOT WinActive("E:\AutoIt") Then WinActivate("E:\AutoIt")
ConsoleWrite(Timerdiff($t) & @CR); gives +/- 0.6

$t = TimerInit()
WinActivate("E:\AutoIt")
ConsoleWrite(Timerdiff($t) & @CR); gives +/- 250.0

so the 1st method is way better

<{POST_SNAPBACK}>

wOuter,

This test is misleading because the AutoIt WinWaitDelay option defaults to 250ms. If set to 0ms, the time to activate a window is reduced from 251ms to about 0.19ms on my PC. While I don't recommend a delay of zero milliseconds, I often set WinWaitDelay to 5ms.

My results from 10 runs using Opt("WinWaitDelay", 0):

1. Not activating the window if already active: 0.17ms to .22 ms

2. Always activating the window: 0.16ms to 0.23ms


Phillip

Share this post


Link to post
Share on other sites

stupid me lol.

w/ the opt()

1st try

0.594628697874134
0.93590351501102

2nd try

0.846656363694903
0.655575459023735

3th try

0.653381101656964
0.430464892331018

4th try

2.20084589739762
3.30013434841021

i think that it doesnt really make a diffenence ...

and i also tried this

$bx = 0
$ax = 0

WinActivate("E:\AutoIt")

Opt("WinWaitDelay", 0)

Sleep(100)

For $i = 1 to 100

$a1 = 0
For $a = 1 To 100
    $t = TimerInit()
    If NOT WinActive("E:\AutoIt") Then WinActivate("E:\AutoIt")
    $a1 += Timerdiff($t)
Next

$b1 = 0
For $b = 1 To 100
    $t = TimerInit()
    WinActivate("E:\AutoIt")
    $b1 += Timerdiff($t)
Next

If $a1 < $b1 Then 
    $bx += 1
;MsgBox(0, '', "If: (" &  $b1 - $a1 & ")")
Else
    $ax += 1
;MsgBox(0, '', "Normal: (" &  $a1 - $b1 & ")")
EndIf

Next

MsgBox(0, '', $ax & @CRLF & $bx)

IT ENDED EXACTLY IN 50-50

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

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