<s> import ufora . config . Setup as Setup <EOL> import ufora . FORA . python . FORA as FORA <EOL> import ufora . FORA . test as FORATestModule <EOL> import sys <EOL> import os <EOL> import logging <EOL> import time <EOL> import numpy as np <EOL> testPath = os . path . split ( FORATestModule . __file__ ) [ <NUM_LIT:0> ] <EOL> def evalTimingsForModuleMember ( filename , memberName , callResult = False ) : <EOL> foraModule = FORA . importModule ( os . path . join ( testPath , filename ) ) <EOL> if callResult : <EOL> toCall = getattr ( foraModule , memberName ) <EOL> evalFun = lambda n : FORA . eval ( <EOL> "<STR_LIT>" , <EOL> locals = { '<STR_LIT>' : toCall } , <EOL> parsePath = [ "<STR_LIT>" ] <EOL> ) <EOL> else : <EOL> evalFun = lambda n : FORA . eval ( <EOL> "<STR_LIT>" % memberName , <EOL> locals = { '<STR_LIT>' : foraModule } , <EOL> parsePath = [ "<STR_LIT>" ] <EOL> ) <EOL> measureTimingsInLoop ( evalFun ) <EOL> def evalTimingsForExpr ( expression , callResult = False ) : <EOL> if callResult : <EOL> toCall = FORA . eval ( expression ) <EOL> evalFun = lambda n : FORA . eval ( <EOL> "<STR_LIT>" , <EOL> locals = { "<STR_LIT>" : toCall } , <EOL> parsePath = [ "<STR_LIT>" ] <EOL> ) <EOL> else : <EOL> evalFun = lambda n : FORA . eval ( <EOL> expression , parsePath = [ "<STR_LIT>" ] <EOL> ) <EOL> measureTimingsInLoop ( evalFun ) <EOL> def measureTimingsInLoop ( evalFun ) : <EOL> timings = [ ] <EOL> totalAttempts = <NUM_LIT:0> <EOL> while True : <EOL> totalAttempts += <NUM_LIT:1> <EOL> if totalAttempts > <NUM_LIT:100> : <EOL> print "<STR_LIT>" <EOL> return <EOL> t0 = time . time ( ) <EOL> evalFun ( totalAttempts ) <EOL> timings . append ( time . time ( ) - t0 ) <EOL> if len ( timings ) > <NUM_LIT:20> : <EOL> timings = timings [ len ( timings ) - <NUM_LIT:20> : ] <EOL> if len ( timings ) > <NUM_LIT:10> : <EOL> st = sorted ( timings ) <EOL> if ( st [ <NUM_LIT:2> ] - st [ <NUM_LIT:0> ] ) / st [ <NUM_LIT:0> ] < <NUM_LIT> : <EOL> print st [ <NUM_LIT:0> ] <EOL> return <EOL> def main ( argv ) : <EOL> """<STR_LIT>""" <EOL> callResult = "<STR_LIT>" in sys . argv <EOL> if "<STR_LIT>" in sys . argv : <EOL> evalTimingsForModuleMember ( <EOL> filename = sys . argv [ <NUM_LIT:1> ] , memberName = sys . argv [ <NUM_LIT:2> ] , <EOL> callResult = callResult <EOL> ) <EOL> else : <EOL> evalTimingsForExpr ( <EOL> expression = sys . argv [ <NUM_LIT:1> ] , callResult = callResult <EOL> ) <EOL> return <NUM_LIT:0> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> try : <EOL> setup = Setup . defaultSetup ( ) <EOL> setup . config . configureLogging ( logging . WARN ) <EOL> import ufora . FORA . python . Evaluator . LocalEvaluator as LocalEvaluator <EOL> LocalEvaluator . DISABLE_SPLITTING = True <EOL> with Setup . PushSetup ( setup ) : <EOL> FORA . initialize ( ) <EOL> resultCode = main ( sys . argv ) <EOL> except : <EOL> import traceback <EOL> print >> sys . stderr , traceback . format_exc ( ) <EOL> resultCode = <NUM_LIT:255> <EOL> sys . stdout . flush ( ) <EOL> sys . stderr . flush ( ) <EOL> os . _exit ( resultCode ) </s>
