Contoh program : Program Python untuk Mengukur Waktu yang Berlalu dengan Python

0
(0)

Contoh 1: Menggunakan modul waktu

import time

start = time.time()

print(23*2.3)

end = time.time()
print(end - start)

Keluaran

52.9
3.600120544433594e-05

Waktu eksekusi tergantung pada sistem.


Contoh 2: Menggunakan modul timeit

from timeit import default_timer as timer

start = timer()

print(23*2.3)

end = timer()
print(end - start)

Keluaran

52.9
6.355400000000039e-05

timeit memberikan hasil yang paling akurat.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.