Micro‑Benchmarking ‑ Measure as You Go

While designing or coding, you may be aware of different ways of accomplishing the same functionality in Jade. It can be beneficial to do a performance test to decide between them at the time, particularly if the same functionality will be used many times. Simple construct choices, in particular, benefit from measuring as you go, as they are easier to test.

Micro‑benchmarking refers to a simple test comparing two constructs, to see which is faster. These tests are frequently run in Workspace or JadeScript methods. The following is an example JadeScript method that is useful for comparing constructs.

jblPfm() updating;
vars
    oldWay : Boolean;
    dts,dte : Decimal[19];
    s,t,u,v : String;
    i,j,reps : Integer;
begin
    write CrLf & "Starting...";
    reps := 10000;  // adjust this to get a run length of 1 to 10 seconds
    oldWay := true;
    dts := app.relativeMachineTime;
    foreach i in 1 to reps do
        if oldWay then
            s := app.actualTimeServer.String;
        else
            s := app.actualTimeAppServer.String;
        endif;
    endforeach;
    dte := app.relativeMachineTime;
    write "<" & s & ">" & "<" & t & ">";  // to verify the functional results
    write ((dte‑dts)/reps).roundedTo(6).String & " ms/rep";
epilog
    write "Finished";
end;

When performing micro‑benchmarks, there are a few things to watch out for.