Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
Constructs.IfThenElse Class Reference
Inheritance diagram for Constructs.IfThenElse:
Inheritance graph
[legend]
Collaboration diagram for Constructs.IfThenElse:
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 = 30
int rounds = 150000
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 Constructs.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 464 of file Constructs.py.

00464 
00465     def calibrate(self):
00466 
00467         a,b,c = 1,2,3
00468         for i in range(self.rounds):
00469             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 Constructs.py.

00009 
00010     def test(self):
00011 
00012         a,b,c = 1,2,3
00013         for i in range(self.rounds):
00014 
00015             if a == 1:
00016                 if b == 2:
00017                     if c != 3:
00018                         c = 3
00019                         b = 3
00020                     else:
00021                         c = 2
00022                 elif b == 3:
00023                     b = 2
00024                     a = 2
00025             elif a == 2:
00026                 a = 3
00027             else:
00028                 a = 1
00029 
00030             if a == 1:
00031                 if b == 2:
00032                     if c != 3:
00033                         c = 3
00034                         b = 3
00035                     else:
00036                         c = 2
00037                 elif b == 3:
00038                     b = 2
00039                     a = 2
00040             elif a == 2:
00041                 a = 3
00042             else:
00043                 a = 1
00044 
00045             if a == 1:
00046                 if b == 2:
00047                     if c != 3:
00048                         c = 3
00049                         b = 3
00050                     else:
00051                         c = 2
00052                 elif b == 3:
00053                     b = 2
00054                     a = 2
00055             elif a == 2:
00056                 a = 3
00057             else:
00058                 a = 1
00059 
00060             if a == 1:
00061                 if b == 2:
00062                     if c != 3:
00063                         c = 3
00064                         b = 3
00065                     else:
00066                         c = 2
00067                 elif b == 3:
00068                     b = 2
00069                     a = 2
00070             elif a == 2:
00071                 a = 3
00072             else:
00073                 a = 1
00074 
00075             if a == 1:
00076                 if b == 2:
00077                     if c != 3:
00078                         c = 3
00079                         b = 3
00080                     else:
00081                         c = 2
00082                 elif b == 3:
00083                     b = 2
00084                     a = 2
00085             elif a == 2:
00086                 a = 3
00087             else:
00088                 a = 1
00089 
00090             if a == 1:
00091                 if b == 2:
00092                     if c != 3:
00093                         c = 3
00094                         b = 3
00095                     else:
00096                         c = 2
00097                 elif b == 3:
00098                     b = 2
00099                     a = 2
00100             elif a == 2:
00101                 a = 3
00102             else:
00103                 a = 1
00104 
00105             if a == 1:
00106                 if b == 2:
00107                     if c != 3:
00108                         c = 3
00109                         b = 3
00110                     else:
00111                         c = 2
00112                 elif b == 3:
00113                     b = 2
00114                     a = 2
00115             elif a == 2:
00116                 a = 3
00117             else:
00118                 a = 1
00119 
00120             if a == 1:
00121                 if b == 2:
00122                     if c != 3:
00123                         c = 3
00124                         b = 3
00125                     else:
00126                         c = 2
00127                 elif b == 3:
00128                     b = 2
00129                     a = 2
00130             elif a == 2:
00131                 a = 3
00132             else:
00133                 a = 1
00134 
00135             if a == 1:
00136                 if b == 2:
00137                     if c != 3:
00138                         c = 3
00139                         b = 3
00140                     else:
00141                         c = 2
00142                 elif b == 3:
00143                     b = 2
00144                     a = 2
00145             elif a == 2:
00146                 a = 3
00147             else:
00148                 a = 1
00149 
00150             if a == 1:
00151                 if b == 2:
00152                     if c != 3:
00153                         c = 3
00154                         b = 3
00155                     else:
00156                         c = 2
00157                 elif b == 3:
00158                     b = 2
00159                     a = 2
00160             elif a == 2:
00161                 a = 3
00162             else:
00163                 a = 1
00164 
00165             if a == 1:
00166                 if b == 2:
00167                     if c != 3:
00168                         c = 3
00169                         b = 3
00170                     else:
00171                         c = 2
00172                 elif b == 3:
00173                     b = 2
00174                     a = 2
00175             elif a == 2:
00176                 a = 3
00177             else:
00178                 a = 1
00179 
00180             if a == 1:
00181                 if b == 2:
00182                     if c != 3:
00183                         c = 3
00184                         b = 3
00185                     else:
00186                         c = 2
00187                 elif b == 3:
00188                     b = 2
00189                     a = 2
00190             elif a == 2:
00191                 a = 3
00192             else:
00193                 a = 1
00194 
00195             if a == 1:
00196                 if b == 2:
00197                     if c != 3:
00198                         c = 3
00199                         b = 3
00200                     else:
00201                         c = 2
00202                 elif b == 3:
00203                     b = 2
00204                     a = 2
00205             elif a == 2:
00206                 a = 3
00207             else:
00208                 a = 1
00209 
00210             if a == 1:
00211                 if b == 2:
00212                     if c != 3:
00213                         c = 3
00214                         b = 3
00215                     else:
00216                         c = 2
00217                 elif b == 3:
00218                     b = 2
00219                     a = 2
00220             elif a == 2:
00221                 a = 3
00222             else:
00223                 a = 1
00224 
00225             if a == 1:
00226                 if b == 2:
00227                     if c != 3:
00228                         c = 3
00229                         b = 3
00230                     else:
00231                         c = 2
00232                 elif b == 3:
00233                     b = 2
00234                     a = 2
00235             elif a == 2:
00236                 a = 3
00237             else:
00238                 a = 1
00239 
00240             if a == 1:
00241                 if b == 2:
00242                     if c != 3:
00243                         c = 3
00244                         b = 3
00245                     else:
00246                         c = 2
00247                 elif b == 3:
00248                     b = 2
00249                     a = 2
00250             elif a == 2:
00251                 a = 3
00252             else:
00253                 a = 1
00254 
00255             if a == 1:
00256                 if b == 2:
00257                     if c != 3:
00258                         c = 3
00259                         b = 3
00260                     else:
00261                         c = 2
00262                 elif b == 3:
00263                     b = 2
00264                     a = 2
00265             elif a == 2:
00266                 a = 3
00267             else:
00268                 a = 1
00269 
00270             if a == 1:
00271                 if b == 2:
00272                     if c != 3:
00273                         c = 3
00274                         b = 3
00275                     else:
00276                         c = 2
00277                 elif b == 3:
00278                     b = 2
00279                     a = 2
00280             elif a == 2:
00281                 a = 3
00282             else:
00283                 a = 1
00284 
00285             if a == 1:
00286                 if b == 2:
00287                     if c != 3:
00288                         c = 3
00289                         b = 3
00290                     else:
00291                         c = 2
00292                 elif b == 3:
00293                     b = 2
00294                     a = 2
00295             elif a == 2:
00296                 a = 3
00297             else:
00298                 a = 1
00299 
00300             if a == 1:
00301                 if b == 2:
00302                     if c != 3:
00303                         c = 3
00304                         b = 3
00305                     else:
00306                         c = 2
00307                 elif b == 3:
00308                     b = 2
00309                     a = 2
00310             elif a == 2:
00311                 a = 3
00312             else:
00313                 a = 1
00314 
00315             if a == 1:
00316                 if b == 2:
00317                     if c != 3:
00318                         c = 3
00319                         b = 3
00320                     else:
00321                         c = 2
00322                 elif b == 3:
00323                     b = 2
00324                     a = 2
00325             elif a == 2:
00326                 a = 3
00327             else:
00328                 a = 1
00329 
00330             if a == 1:
00331                 if b == 2:
00332                     if c != 3:
00333                         c = 3
00334                         b = 3
00335                     else:
00336                         c = 2
00337                 elif b == 3:
00338                     b = 2
00339                     a = 2
00340             elif a == 2:
00341                 a = 3
00342             else:
00343                 a = 1
00344 
00345             if a == 1:
00346                 if b == 2:
00347                     if c != 3:
00348                         c = 3
00349                         b = 3
00350                     else:
00351                         c = 2
00352                 elif b == 3:
00353                     b = 2
00354                     a = 2
00355             elif a == 2:
00356                 a = 3
00357             else:
00358                 a = 1
00359 
00360             if a == 1:
00361                 if b == 2:
00362                     if c != 3:
00363                         c = 3
00364                         b = 3
00365                     else:
00366                         c = 2
00367                 elif b == 3:
00368                     b = 2
00369                     a = 2
00370             elif a == 2:
00371                 a = 3
00372             else:
00373                 a = 1
00374 
00375             if a == 1:
00376                 if b == 2:
00377                     if c != 3:
00378                         c = 3
00379                         b = 3
00380                     else:
00381                         c = 2
00382                 elif b == 3:
00383                     b = 2
00384                     a = 2
00385             elif a == 2:
00386                 a = 3
00387             else:
00388                 a = 1
00389 
00390             if a == 1:
00391                 if b == 2:
00392                     if c != 3:
00393                         c = 3
00394                         b = 3
00395                     else:
00396                         c = 2
00397                 elif b == 3:
00398                     b = 2
00399                     a = 2
00400             elif a == 2:
00401                 a = 3
00402             else:
00403                 a = 1
00404 
00405             if a == 1:
00406                 if b == 2:
00407                     if c != 3:
00408                         c = 3
00409                         b = 3
00410                     else:
00411                         c = 2
00412                 elif b == 3:
00413                     b = 2
00414                     a = 2
00415             elif a == 2:
00416                 a = 3
00417             else:
00418                 a = 1
00419 
00420             if a == 1:
00421                 if b == 2:
00422                     if c != 3:
00423                         c = 3
00424                         b = 3
00425                     else:
00426                         c = 2
00427                 elif b == 3:
00428                     b = 2
00429                     a = 2
00430             elif a == 2:
00431                 a = 3
00432             else:
00433                 a = 1
00434 
00435             if a == 1:
00436                 if b == 2:
00437                     if c != 3:
00438                         c = 3
00439                         b = 3
00440                     else:
00441                         c = 2
00442                 elif b == 3:
00443                     b = 2
00444                     a = 2
00445             elif a == 2:
00446                 a = 3
00447             else:
00448                 a = 1
00449 
00450             if a == 1:
00451                 if b == 2:
00452                     if c != 3:
00453                         c = 3
00454                         b = 3
00455                     else:
00456                         c = 2
00457                 elif b == 3:
00458                     b = 2
00459                     a = 2
00460             elif a == 2:
00461                 a = 3
00462             else:
00463                 a = 1

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 Constructs.py.

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

Definition at line 209 of file pybench.py.

int Constructs.IfThenElse.rounds = 150000 [static]

Reimplemented from pybench.Test.

Definition at line 7 of file Constructs.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.

float Constructs.IfThenElse.version = 2.0 [static]

Instance variables that each test should override.

Reimplemented from pybench.Test.

Definition at line 5 of file Constructs.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: