Search code examples
pythonpython-3.xtimetiming

What exactly are fractional seconds returned by Python time.perf_counter()?


This is probably a dumb/obvious question, but just want to make sure my hunches are correct.

I'm doing some basic performance timing in a Python3 script using time.perf_counter() like so:

start = time.perf_counter()
# some time consuming operation here
end = time.perf_counter()
elapsed = end - start

And I'll get back values like 9.774 or 36.903 (to many more decimal places, of course). I'm assuming that larger numbers = more time elapsed, but what exactly do these numbers mean? E.g. is 1.23 fractional seconds just 1 second and .23 fractions of a second


Solution

  • As far as I know, "fractional second" just means a second with a fractional part (as opposed to a strictly integer number of seconds). So 9.774 means 9 seconds plus 774/1000 seconds.