diff testcases.py @ 85:741ae3391b61

Moved clock/time detection into platform-specific modules and testcases
author Oleg Oshmyan <chortos@inbox.lv>
date Thu, 24 Feb 2011 23:59:48 +0000
parents 37c4ad87583c
children cd347cfca272
line wrap: on
line diff
--- a/testcases.py	Thu Feb 24 00:29:32 2011 +0000
+++ b/testcases.py	Thu Feb 24 23:59:48 2011 +0000
@@ -12,7 +12,7 @@
 	import __main__
 	__main__.import_error(sys.exc_info()[1])
 else:
-	from __main__ import clock, options
+	from __main__ import options
 
 import glob, re, sys, tempfile, time
 from subprocess import Popen, PIPE, STDOUT
@@ -20,6 +20,21 @@
 import os
 devnull = open(os.path.devnull, 'w+')
 
+if options.autotime:
+	# This is really a dirty hack that assumes that sleep() does not spend
+	# the CPU time of the current process and that if clock() measures
+	# wall-clock time, then it is more precise than time() is. Both these
+	# assumptions are true on all platforms I have tested this on so far,
+	# but I am not aware of any guarantee that they will both be true
+	# on every other platform.
+	c = time.clock()
+	time.sleep(1)
+	c = time.clock() - c
+	if int(c + .5) == 1:
+		clock = time.clock
+	else:
+		clock = time.time
+
 try:
 	from win32 import *
 except Exception: