Task

Write a program which uses a timer (with the least granularity available
on your system) to time how long a function takes to execute.

Whenever possible, use methods which measure only the processing time used
by the current process; instead of the difference in system time
between start and finish, which could include time used by
other processes on the computer.

This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.




with javascript_semantics
function identity(integer x)
    return x
end function
 
function total(integer num)
    for i=1 to 100_000_000 do
        num += odd(i)
    end for
    return num
end function

procedure time_it(integer fn)
    atom t0 = time()
    integer res = fn(4)
    string funcname = get_routine_info(fn)[4]
    printf(1,"%s(4) = %d, taking %s\n",{funcname,res,elapsed(time()-t0)})
end procedure

time_it(identity)
time_it(total)
