12

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

baisang
  • 414
  • 6
  • 13
  • What don't you understand from https://docs.python.org/3/library/time.html#time.perf_counter ? – Tom Dalton Aug 05 '15 at 15:25
  • 1
    When a number is returned, like 1.23 for example, is that 1 second and .23 fractions of a second? – baisang Aug 05 '15 at 15:27
  • Makes sense, thanks. I saw another post that had a weird answer, so I was confused http://stackoverflow.com/questions/8937708/what-is-a-fractional-second – baisang Aug 05 '15 at 15:29
  • 2
    Yeah I guess the term "fractional seconds" is a bit unusual, but they just mean seconds. – Tom Dalton Aug 05 '15 at 15:30
  • I agree that calling them "fractional seconds" is confusing. They are whole seconds, with fractions of a second resolution past the decimal point. – JHS Jan 28 '21 at 00:10

2 Answers2

12

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.

ezig
  • 1,219
  • 1
  • 10
  • 15
2

Additional info, for very small elapsed time it will return scientific notation like 3.6564000765793025e-05 then to format it to second and Milisecond/Microsecond

print(f'{elapsed:.3f} - Second & MiliSecond')
print(f'{elapsed:.6f} - Second & Microsecond')

# 0.000 - Second & MiliSecond
# 0.000037 - Second & Microsecond
uingtea
  • 6,002
  • 2
  • 26
  • 40