0

I am interested in measuring the time elapsed during a (synchronous) HTTP request and/or a (synchronous) request to a database on a remote server. After reading this page, my understanding is that time.clock() is an accurate measure of the processor time. But I don't know if "processor time" is relevant in my case, since the CPU would be idling while waiting for the response. In other words:

s0 = time.time()
# send a HTTP request
s1 = time.time()

t0 = time.clock()
# send a HTTP request
t1 = time.clock()

Which one actually measures what I want?

Community
  • 1
  • 1
usual me
  • 8,338
  • 10
  • 52
  • 95

2 Answers2

1

For measuring HTTP response time, I think time.time() is enough.

As others suggested, use timeit if you want to do benchmarking.

I personally haven't used time.clock() before, but after reading the example :

#!/usr/bin/python
import time

def procedure():
    time.sleep(2.5)

# measure process time
t0 = time.clock()
procedure()
print time.clock() - t0, "seconds process time"

# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"

I don't think time.clock() is appropriate measuring HTTP response time.

laike9m
  • 18,344
  • 20
  • 107
  • 140
0

One approach is to use New Relic for python. You just install it and enable in application. After that, you will be able to see such charts in your New Relic account. It has a free plan.

new relic charts

stalk
  • 11,934
  • 4
  • 36
  • 58