Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
Lookups.SpecialClassAttribute Class Reference
Inheritance diagram for Lookups.SpecialClassAttribute:
Inheritance graph
[legend]
Collaboration diagram for Lookups.SpecialClassAttribute:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test
def calibrate
def get_timer
def compatible
def calibrate_test
def run
def stat

Public Attributes

 last_timing
 warp
 times

Static Public Attributes

float version = 2.0
 Instance variables that each test should override.
int operations = 5
int rounds = 100000
int is_a_test = 1
 Internal variables.
tuple last_timing = (0.0, 0.0, 0.0)
int warp = 1
 calibration_runs = CALIBRATION_RUNS
 overhead_times = None
list times = []
 timer = TIMER_PLATFORM_DEFAULT

Detailed Description

Definition at line 3 of file Lookups.py.


Member Function Documentation

Calibrate the test.

    This method should execute everything that is needed to
    setup and run the test - except for the actual operations
    that you intend to measure. pybench uses this method to
    measure the test implementation overhead.

Reimplemented from pybench.Test.

Definition at line 176 of file Lookups.py.

00176 
00177     def calibrate(self):
00178 
00179         class c:
00180             pass
00181 
00182         for i in range(self.rounds):
00183             pass

Here is the caller graph for this function:

def pybench.Test.calibrate_test (   self) [inherited]

Definition at line 262 of file pybench.py.

00262 
00263     def calibrate_test(self):
00264 
00265         if self.calibration_runs == 0:
00266             self.overhead_times = [0.0]
00267             return
00268 
00269         calibrate = self.calibrate
00270         timer = self.get_timer()
00271         calibration_loops = range(CALIBRATION_LOOPS)
00272 
00273         # Time the calibration loop overhead
00274         prep_times = []
00275         for i in range(self.calibration_runs):
00276             t = timer()
00277             for i in calibration_loops:
00278                 pass
00279             t = timer() - t
00280             prep_times.append(t / CALIBRATION_LOOPS)
00281         min_prep_time = min(prep_times)
00282         if _debug:
00283             print()
00284             print('Calib. prep time     = %.6fms' % (
00285                 min_prep_time * MILLI_SECONDS))
00286 
00287         # Time the calibration runs (doing CALIBRATION_LOOPS loops of
00288         # .calibrate() method calls each)
00289         for i in range(self.calibration_runs):
00290             t = timer()
00291             for i in calibration_loops:
00292                 calibrate()
00293             t = timer() - t
00294             self.overhead_times.append(t / CALIBRATION_LOOPS
00295                                        - min_prep_time)
00296 
00297         # Check the measured times
00298         min_overhead = min(self.overhead_times)
00299         max_overhead = max(self.overhead_times)
00300         if _debug:
00301             print('Calib. overhead time = %.6fms' % (
00302                 min_overhead * MILLI_SECONDS))
00303         if min_overhead < 0.0:
00304             raise ValueError('calibration setup did not work')
00305         if max_overhead - min_overhead > 0.1:
00306             raise ValueError(
00307                 'overhead calibration timing range too inaccurate: '
00308                 '%r - %r' % (min_overhead, max_overhead))

def pybench.Test.compatible (   self,
  other 
) [inherited]
Return 1/0 depending on whether the test is compatible
    with the other Test instance or not.

Definition at line 250 of file pybench.py.

00250 
00251     def compatible(self, other):
00252 
00253         """ Return 1/0 depending on whether the test is compatible
00254             with the other Test instance or not.
00255 
00256         """
00257         if self.version != other.version:
00258             return 0
00259         if self.rounds != other.rounds:
00260             return 0
00261         return 1

Here is the caller graph for this function:

def pybench.Test.get_timer (   self) [inherited]
Return the timer function to use for the test.

Definition at line 243 of file pybench.py.

00243 
00244     def get_timer(self):
00245 
00246         """ Return the timer function to use for the test.
00247 
00248         """
00249         return get_timer(self.timer)

Here is the caller graph for this function:

def pybench.Test.run (   self) [inherited]
Run the test in two phases: first calibrate, then
    do the actual test. Be careful to keep the calibration
    timing low w/r to the test timing.

Definition at line 309 of file pybench.py.

00309 
00310     def run(self):
00311 
00312         """ Run the test in two phases: first calibrate, then
00313             do the actual test. Be careful to keep the calibration
00314             timing low w/r to the test timing.
00315 
00316         """
00317         test = self.test
00318         timer = self.get_timer()
00319 
00320         # Get calibration
00321         min_overhead = min(self.overhead_times)
00322 
00323         # Test run
00324         t = timer()
00325         test()
00326         t = timer() - t
00327         if t < MIN_TEST_RUNTIME:
00328             raise ValueError('warp factor too high: '
00329                              'test times are < 10ms')
00330         eff_time = t - min_overhead
00331         if eff_time < 0:
00332             raise ValueError('wrong calibration')
00333         self.last_timing = (eff_time, t, min_overhead)
00334         self.times.append(eff_time)

def pybench.Test.stat (   self) [inherited]
Return test run statistics as tuple:

    (minimum run time,
     average run time,
     total run time,
     average time per operation,
     minimum overhead time)

Definition at line 357 of file pybench.py.

00357 
00358     def stat(self):
00359 
00360         """ Return test run statistics as tuple:
00361 
00362             (minimum run time,
00363              average run time,
00364              total run time,
00365              average time per operation,
00366              minimum overhead time)
00367 
00368         """
00369         runs = len(self.times)
00370         if runs == 0:
00371             return 0.0, 0.0, 0.0, 0.0
00372         min_time = min(self.times)
00373         total_time = sum(self.times)
00374         avg_time = total_time / float(runs)
00375         operation_avg = total_time / float(runs
00376                                            * self.rounds
00377                                            * self.operations)
00378         if self.overhead_times:
00379             min_overhead = min(self.overhead_times)
00380         else:
00381             min_overhead = self.last_timing[2]
00382         return min_time, avg_time, total_time, operation_avg, min_overhead

Here is the call graph for this function:

Run the test.

    The test needs to run self.rounds executing
    self.operations number of operations each.

Reimplemented from pybench.Test.

Definition at line 9 of file Lookups.py.

00009 
00010     def test(self):
00011 
00012         class c:
00013             pass
00014 
00015         for i in range(self.rounds):
00016 
00017             c.__a = 2
00018             c.__b = 3
00019             c.__c = 4
00020 
00021             c.__a = 2
00022             c.__b = 3
00023             c.__c = 4
00024 
00025             c.__a = 2
00026             c.__b = 3
00027             c.__c = 4
00028 
00029             c.__a = 2
00030             c.__b = 3
00031             c.__c = 4
00032 
00033             x = c.__a
00034             x = c.__b
00035             x = c.__c
00036 
00037             x = c.__a
00038             x = c.__b
00039             x = c.__c
00040 
00041             x = c.__a
00042             x = c.__b
00043             x = c.__c
00044 
00045             x = c.__a
00046             x = c.__b
00047             x = c.__c
00048 
00049             c.__a = 2
00050             c.__b = 3
00051             c.__c = 4
00052 
00053             c.__a = 2
00054             c.__b = 3
00055             c.__c = 4
00056 
00057             c.__a = 2
00058             c.__b = 3
00059             c.__c = 4
00060 
00061             c.__a = 2
00062             c.__b = 3
00063             c.__c = 4
00064 
00065             x = c.__a
00066             x = c.__b
00067             x = c.__c
00068 
00069             x = c.__a
00070             x = c.__b
00071             x = c.__c
00072 
00073             x = c.__a
00074             x = c.__b
00075             x = c.__c
00076 
00077             x = c.__a
00078             x = c.__b
00079             x = c.__c
00080 
00081             c.__a = 2
00082             c.__b = 3
00083             c.__c = 4
00084 
00085             c.__a = 2
00086             c.__b = 3
00087             c.__c = 4
00088 
00089             c.__a = 2
00090             c.__b = 3
00091             c.__c = 4
00092 
00093             c.__a = 2
00094             c.__b = 3
00095             c.__c = 4
00096 
00097             x = c.__a
00098             x = c.__b
00099             x = c.__c
00100 
00101             x = c.__a
00102             x = c.__b
00103             x = c.__c
00104 
00105             x = c.__a
00106             x = c.__b
00107             x = c.__c
00108 
00109             x = c.__a
00110             x = c.__b
00111             x = c.__c
00112 
00113             c.__a = 2
00114             c.__b = 3
00115             c.__c = 4
00116 
00117             c.__a = 2
00118             c.__b = 3
00119             c.__c = 4
00120 
00121             c.__a = 2
00122             c.__b = 3
00123             c.__c = 4
00124 
00125             c.__a = 2
00126             c.__b = 3
00127             c.__c = 4
00128 
00129             x = c.__a
00130             x = c.__b
00131             x = c.__c
00132 
00133             x = c.__a
00134             x = c.__b
00135             x = c.__c
00136 
00137             x = c.__a
00138             x = c.__b
00139             x = c.__c
00140 
00141             x = c.__a
00142             x = c.__b
00143             x = c.__c
00144 
00145             c.__a = 2
00146             c.__b = 3
00147             c.__c = 4
00148 
00149             c.__a = 2
00150             c.__b = 3
00151             c.__c = 4
00152 
00153             c.__a = 2
00154             c.__b = 3
00155             c.__c = 4
00156 
00157             c.__a = 2
00158             c.__b = 3
00159             c.__c = 4
00160 
00161             x = c.__a
00162             x = c.__b
00163             x = c.__c
00164 
00165             x = c.__a
00166             x = c.__b
00167             x = c.__c
00168 
00169             x = c.__a
00170             x = c.__b
00171             x = c.__c
00172 
00173             x = c.__a
00174             x = c.__b
00175             x = c.__c

Here is the caller graph for this function:


Member Data Documentation

pybench.Test.calibration_runs = CALIBRATION_RUNS [static, inherited]

Definition at line 206 of file pybench.py.

int pybench.Test.is_a_test = 1 [static, inherited]

Internal variables.

Definition at line 197 of file pybench.py.

tuple pybench.Test.last_timing = (0.0, 0.0, 0.0) [static, inherited]

Definition at line 200 of file pybench.py.

Definition at line 332 of file pybench.py.

Reimplemented from pybench.Test.

Definition at line 6 of file Lookups.py.

pybench.Test.overhead_times = None [static, inherited]

Definition at line 209 of file pybench.py.

Reimplemented from pybench.Test.

Definition at line 7 of file Lookups.py.

pybench.Test.timer = TIMER_PLATFORM_DEFAULT [static, inherited]

Definition at line 215 of file pybench.py.

list pybench.Test.times = [] [static, inherited]

Definition at line 212 of file pybench.py.

pybench.Test.times [inherited]

Definition at line 234 of file pybench.py.

Instance variables that each test should override.

Reimplemented from pybench.Test.

Definition at line 5 of file Lookups.py.

int pybench.Test.warp = 1 [static, inherited]

Definition at line 203 of file pybench.py.

pybench.Test.warp [inherited]

Definition at line 224 of file pybench.py.


The documentation for this class was generated from the following file: