• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

StopWatch API - Benchmarking for Everyone

Status
Not open for further replies.
Now that SharpCraft is released I decided to create new StopWatch natives since the old ones only work with RtC on patch 1.24 (which nobody had).

These are very useful for testing the speed of things in JASS.

JASS:
native StopWatchCreate  takes nothing returns integer
native StopWatchTicks   takes integer id returns integer
native StopWatchMark    takes integer id returns integer
native StopWatchDestroy takes integer id returns nothing


JASS:
native UnitAlive takes unit id returns boolean

function Trig_esc_Actions takes nothing returns nothing
    local integer sw
    local integer i  = 0
    local integer array ticks
    local unit u =  CreateUnit(Player(0), 'hfoo', 0, 0, 0)
    
    set sw = StopWatchCreate()
    loop
        exitwhen i == 1000
        // TEST 1
        if (GetWidgetLife(u) > 0.405) then
        endif
        set i = i + 1
    endloop
    set ticks[0] = StopWatchTicks(sw)
    
    call BJDebugMsg("GetWidgetLife took " + I2S(StopWatchMark(sw)) + " milliseconds to finish.")
    call StopWatchDestroy(sw)
    
    set sw = StopWatchCreate()
    set i  = 0
    
    loop
        exitwhen i == 1000
        // TEST 2
        if (UnitAlive(u)) then
        endif
        set i = i + 1
    endloop
    set ticks[1] = StopWatchTicks(sw)
    
    call BJDebugMsg("UnitAlive took " + I2S(StopWatchMark(sw)) + " milliseconds to finish.")
    call StopWatchDestroy(sw)
    
    if (ticks[0] > ticks[1]) then
        call BJDebugMsg("UnitAlive is faster than GetWidgetLife")
    else
        call BJDebugMsg("GetWidgetLife is faster than UnitAlive")
    endif
endfunction

//===========================================================================
function InitTrig_esc takes nothing returns nothing
    set gg_trg_esc = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_esc, Player(0) )
    call TriggerAddAction( gg_trg_esc, function Trig_esc_Actions )
endfunction

Copy StopWatch.dll to the plugins folder of SharpCraft.
 

Attachments

  • StopWatch.zip
    2 KB · Views: 101
  • stopwatch.w3x
    16.5 KB · Views: 101
  • stopwatch.png
    stopwatch.png
    25.6 KB · Views: 136
Last edited:
Does SharpCraft support JassHelper at its current state? Without I can't run a benchmark, right?

Anyways thank you, thats very useful. :)

This is vJass or JNGP independent. You can use these natives in the Vanilla Editor if you'd like.

Althought in the vanillla editor you need to edit the common.j, add these native declarations like above and import it to your map as "scripts/common.j".
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Where do I find the common.j?
From the wc3x.mpq, which means I rip it out via MPQ editor edit it and put it in my map as skripts/common.j?

Actually I found two common.j, but those were from Cohadar's and Vexorian's jasshelper.

Can I use the JNPG I'm using instead of the vanilla editor? ( because it has no Styles.ini and therefore looks stupid)

I've tried some stuff but nothing worked, either I got tons of syntax errors ( Vanilla editor) or the map didn't load and instead I was stuck in the Warcraft3 startmenu. (JNPG 2.0)

Those questions may sound stupid, but stuff like this total new ground for me.
 
You're loading your map with SharpCraft, right?

BPower said:
Can I use the JNPG I'm using instead of the vanilla editor? ( because it has no Styles.ini and therefore looks stupid)

Yes you can use JNGP.

BPower said:
I've tried some stuff but nothing worked, either I got tons of syntax errors ( Vanilla editor) or the map didn't load and instead I was stuck in the Warcraft3 startmenu. (JNPG 2.0)

If you're using JNGP make sure to declare the natives somewhere like the script above or like in the demo map.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
You're loading your map with SharpCraft, right?
Now I do... :/ I can load the demo map from sharpcraft with the cursor position detection.

I've copied the StopWatch.dll into the sharkcraft plugon folder.
But I can't load your demo map of stopwatch. (It gets back into the game lobby instead). Additionally I can't even see the common lobby options Name Race Team Color handicap.
 

Attachments

  • s.jpg
    s.jpg
    428.1 KB · Views: 147
  • t.jpg
    t.jpg
    449.6 KB · Views: 124
Status
Not open for further replies.
Top