blob: abf3a06d056a23c7eaf4039fb58fe962395162f1 [file] [log] [blame]
Guido van Rossum58dd0351992-12-17 17:32:35 +00001# Simple interface to report execution times of program fragments.
2# Call TSTART() to reset the timer, TSTOP(...) to report times.
3
Guido van Rossume3cafbe1992-12-14 23:25:04 +00004import sys, os, time
5
6def TSTART():
7 global t0, t1
8 u, s, cu, cs = os.times()
Guido van Rossume69d3fe1994-02-17 12:36:58 +00009 t0 = u+cu, s+cs, time.time()
Guido van Rossume3cafbe1992-12-14 23:25:04 +000010
11def TSTOP(*label):
12 global t0, t1
13 u, s, cu, cs = os.times()
Guido van Rossume69d3fe1994-02-17 12:36:58 +000014 t1 = u+cu, s+cs, time.time()
Guido van Rossume3cafbe1992-12-14 23:25:04 +000015 tt = []
16 for i in range(3):
17 tt.append(t1[i] - t0[i])
18 [u, s, r] = tt
19 msg = ''
20 for x in label: msg = msg + (x + ' ')
Guido van Rossume69d3fe1994-02-17 12:36:58 +000021 msg = msg + `u` + ' user, ' + `s` + ' sys, ' + `r` + ' real\n'
Guido van Rossume3cafbe1992-12-14 23:25:04 +000022 sys.stderr.write(msg)