Logo

Programming-Idioms

  • C#
  • Elixir

Idiom #125 Measure function call duration

measure the duration t, in nanoseconds, of a call to the function foo. Print this duration.

def main(function) do
  function
  |> :timer.tc()
  |> elem(0)
  |> Kernel.*(1_000)
end
using System.Diagnostics;
var stopwatch = new Stopwatch();
stopwatch.Start();
foo();
stopwatch.Stop();
var t = stopwatch.ElapsedMilliseconds;
(time (foo))

time prints time elapsed, but in ms

New implementation...
< >
JPSII