diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-24 16:56:59 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2006-02-24 16:56:59 +0000 |
commit | 00f2295ec55239ce35687a20a7c58d1583b068f1 (patch) | |
tree | 0b9be469665fc81943ccac5667467627723dc95e /numpy/testing/utils.py | |
parent | ec53dd5cac4175116048d847f74076e05b6b1a6a (diff) | |
download | numpy-00f2295ec55239ce35687a20a7c58d1583b068f1.tar.gz |
Added more debugging hooks to PackageLoader: NUMPY_IMPORT_DEBUG. Avoid initiating Scipy/NumpyTest during imports.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 4ea19c270..fe3a3c093 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -4,8 +4,6 @@ Utility function to facilitate testing. import os import sys -import time -import math __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', @@ -27,16 +25,19 @@ def rand(*args): if sys.platform[:5]=='linux': def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()), - _load_time=time.time()): + _load_time=[]): """ Return number of jiffies (1/100ths of a second) that this process has been scheduled in user mode. See man 5 proc. """ + import time + if not _load_time: + _load_time.append(time.time()) try: f=open(_proc_pid_stat,'r') l = f.readline().split(' ') f.close() return int(l[13]) except: - return int(100*(time.time()-_load_time)) + return int(100*(time.time()-_load_time[0])) def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())): """ Return virtual memory size in bytes of the running python. @@ -52,10 +53,13 @@ else: # os.getpid is not in all platforms available. # Using time is safe but inaccurate, especially when process # was suspended or sleeping. - def jiffies(_load_time=time.time()): + def jiffies(_load_time=[]): """ Return number of jiffies (1/100ths of a second) that this process has been scheduled in user mode. [Emulation with time.time]. """ - return int(100*(time.time()-_load_time)) + import time + if not _load_time: + _load_time.append(time.time()) + return int(100*(time.time()-_load_time[0])) def memusage(): """ Return memory usage of running python. [Not implemented]""" return @@ -150,6 +154,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1): Approximately equal is defined as the number of significant digits correct """ + import math msg = '\nItems are not equal to %d significant digits:\n' % significant msg += err_msg actual, desired = map(float, (actual, desired)) |