2
假設我有一個通過產生多個進程來完成一些工作的函數。我想比較CPU時間與此功能實時性的比較。如何計算多個參與者/進程涉及的elixir中的CPU時間?
def test do
prev_real = System.monotonic_time(:millisecond)
# Code to complete some task
# Spawn different processes & give each process some task
# Receive result
# Finish task
current_real = System.monotonic_time(:millisecond)
diff_real = current_real - prev_real
IO.puts "Real time " <> to_string(diff_real)
IO.puts "CPU time ?????"
end
如何計算給定函數所需的CPU時間?我有興趣計算CPU時間/實時比率。