annotate Tools/pybench/clockres.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 63741c7521aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
1 #!/usr/bin/env python
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
2
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
3 """ clockres - calculates the resolution in seconds of a given timer.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
4
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
5 Copyright (c) 2006, Marc-Andre Lemburg (mal@egenix.com). See the
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
6 documentation for further information on copyrights, or contact
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
7 the author. All Rights Reserved.
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
8
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
9 """
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
10 import time
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
11
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
12 TEST_TIME = 1.0
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
13
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
14 def clockres(timer):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
15 d = {}
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
16 wallclock = time.time
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
17 start = wallclock()
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
18 stop = wallclock() + TEST_TIME
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
19 spin_loops = range(1000)
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
20 while 1:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
21 now = wallclock()
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
22 if now >= stop:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
23 break
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
24 for i in spin_loops:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
25 d[timer()] = 1
47103
63741c7521aa More 2to3 fixes in the Tools directory. Fixes #2893.
Georg Brandl <georg@python.org>
parents: 42132
diff changeset
26 values = sorted(d.keys())
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
27 min_diff = TEST_TIME
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
28 for i in range(len(values) - 1):
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
29 diff = values[i+1] - values[i]
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
30 if diff < min_diff:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
31 min_diff = diff
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
32 return min_diff
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
33
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
34 if __name__ == '__main__':
42132
863ed7cd45dc Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
35 print('Clock resolution of various timer implementations:')
863ed7cd45dc Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
36 print('time.clock: %10.3fus' % (clockres(time.clock) * 1e6))
863ed7cd45dc Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
37 print('time.time: %10.3fus' % (clockres(time.time) * 1e6))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
38 try:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
39 import systimes
42132
863ed7cd45dc Merged revisions 56020-56124 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 39442
diff changeset
40 print('systimes.processtime: %10.3fus' % (clockres(systimes.processtime) * 1e6))
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
41 except ImportError:
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
diff changeset
42 pass