Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- JS
- Java
- Java
- Lisp
- PHP
- Pascal
- Perl
- Python
- Ruby
- Rust
(time (foo))
time prints time elapsed, but in ms
auto start = std::chrono::steady_clock::now();
foo();
auto end = std::chrono::steady_clock::now();
auto t = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();
c++ 11
var t = Stopwatch();
t.start();
foo();
t.stop();
print(t.elapsedMicroseconds * 1000);
def main(function) do
function
|> :timer.tc()
|> elem(0)
|> Kernel.*(1_000)
end
timer:tc(Fun).
integer, parameter :: i8 = selected_int_kind(15)
integer (kind=i8) :: count, count_rate, count_2
x = 1.2
call system_clock (count, count_rate)
call foo
call system_clock (count_2)
if (count_rate == 10**9) then
print *,"The call to foo used ", (count_2-count), "Nanoseconds"
else
print *,"The call to foo used ", (count_2-count)/real(count_rate)*1e9, "Nanoseconds"
end if
long t = System.nanoTime();
foo();
t = System.nanoTime() - t;
System.out.println(t + "ns");
long t = nanoTime();
foo();
out.println(nanoTime() - t);
(time (foo))
sub foo {};
my $start = Benchmark->new;
foo;
my $t = timediff(Benchmark->new, $start)->[0] * 10**9;
t1 = Time.now
foo
p (Time.now - t1)*1000000