예제 #1
0
파일: __main__.py 프로젝트: marklr/falcon
def main():
  if not sys.argv[1:]:
    print 'Usage: -mfalcon <script> <args>'
    sys.exit(2)

  script = sys.argv[1]
  sys.argv = sys.argv[1:]
  
  sys.path.insert(0, os.path.dirname(script))
  with open(script, 'rb') as fp:
      code = compile(fp.read(), script, 'exec')

  e = falcon.Evaluator()
  e.eval_python(code, (), {})
예제 #2
0
  def time_compare(self, function, *args, **kw):
#    print 'Original bytecode, %s:\n' % function.func_name
#    dis.dis(function)

    if 'repeat' in kw:
      repeat = kw['repeat']
      del kw['repeat']

    if falcon:
      evaluator = falcon.Evaluator()

    py_times = []
    f_times = []
    for i in range(repeat):
      random.seed(10)
      st = time.time()
      py_result = function(*args)
      py_times.append(time.time() - st)

      if falcon:
        random.seed(10)
        st = time.time()
        falcon_result = evaluator.eval_python(function, args, kw)
        f_times.append(time.time() - st)
      else:
        f_time = 0

      if falcon:
        if isinstance(py_result, list):
            # long lists seem to take a bizarrely long time for assertEqual
            # so I added a special case here
            assert isinstance(falcon_result, list), \
              "Expected list but got %s" % type(falcon_result)
            assert len(py_result) == len(falcon_result), \
              "Expected list of length %d but got list of %d" % \
              (len(py_result), len(falcon_result))
            for py_elt, falcon_elt in zip(py_result, falcon_result):
              assert py_elt == falcon_elt, "%s != %s" % (py_elt, falcon_elt)
        else:
            self.assertEqual(py_result, falcon_result)
    f_time_sum = np.sum(f_times)
    # f_time_std = np.std(f_times)
    py_time_sum = np.sum(py_times)
    # py_time_std = np.std(py_times)
    logging.info('PERFORMANCE %s (n = %d): Python %.3f, Falcon: %.3f' % \
            (function_name(function), repeat, py_time_sum, f_time_sum))
예제 #3
0
def main():
    if not sys.argv[1:]:
        print 'Usage: -mfalcon <script> <args>'
        sys.exit(2)

    script = sys.argv[1]
    sys.argv = sys.argv[1:]

    sys.path.insert(0, os.path.dirname(script))
    with open(script, 'rb') as fp:
        code = compile(fp.read(), script, 'exec')

    m = imp.new_module("__main__")
    d = m.__dict__
    d['__builtins__'] = __builtins__
    d['__file__'] = script
    e = falcon.Evaluator()
    e.eval_python_module(code, d)
예제 #4
0
파일: __main__.py 프로젝트: trouger/falcon
def main():
    if not sys.argv[1:]:
        print 'Usage: -mfalcon <script> <args>'
        sys.exit(2)

    script = sys.argv[1]
    sys.argv = sys.argv[1:]

    # this is a hack to cooperate with python benchmark
    if script == '-c':
        exec sys.argv[1]
        return

    sys.path.insert(0, os.path.dirname(script))
    with open(script, 'rb') as fp:
        code = compile(fp.read(), script, 'exec')

    d = sys.modules['__main__'].__dict__
    d['__file__'] = script
    e = falcon.Evaluator()
    e.eval_python_module(code, d)
예제 #5
0
 def run_falcon(self, function, *args, **kw):
   evaluator = falcon.Evaluator()
   return evaluator.eval_python(function, args, None)