New submission from Alex Gaynor <[email protected]>:

Not sure what causes this yet, playing with the number of iterations PyPy is 
consistenly slower than CPython, I think it's because of the super high number 
of 
bridges compiled:

Alexanders-MacBook-Pro:tmp alex_gaynor$ PYPYLOG=jit-summary:- pypy 
decision_tree.py
[ac4ea2fa4a5] {jit-summary
Tracing:        3553    19.518618
Backend:        3552    2.996290
TOTAL:                  51.207841
ops:                    5654103
recorded ops:           2932390
  calls:                95188
guards:                 663823
opt ops:                599629
opt guards:             176790
forcings:               3622
abort: trace too long:  1
abort: compiling:       0
abort: vable escape:    0
abort: bad loop:        0
abort: force quasi-immut:       0
nvirtuals:              3885619
nvholes:                518637
nvreused:               2282863
Total # of loops:       21
Total # of bridges:     3533
Freed # of loops:       7
Freed # of bridges:     3
[ac4ea6187bd] jit-summary}
Alexanders-MacBook-Pro:tmp alex_gaynor$ cat decision_tree.py
import random

class Node(object):
    def __init__(self, idx, thresh, left, right):
      self.idx = idx
      self.thresh = thresh
      self.left = left
      self.right = right

    def predict(self, x):
      if x[self.idx] < self.thresh:
          return self.left.predict(x)
      else:
          return self.right.predict(x)

    def __eq__(self, other):
        return other.__class__ is Node and \
               self.idx == other.idx and \
               self.thresh == other.thresh and \
               self.left == other.left and \
               self.right == other.right

class Leaf(object):
    def __init__(self, value):
        self.value = value

    def predict(self, x):
        return self.value

    def __eq__(self, other):
        return other.__class__ is Leaf and \
               other.value == self.value


def gen_random_tree(n_features, depth):
  #print "n_features = %d, depth = %d" % (n_features, depth)
  if depth == 0:
      return Leaf(random.random())
  else:
    feature_idx = random.randint(0, n_features-1)
    threshold = random.random()
    left = gen_random_tree(n_features, depth - 1)
    right = gen_random_tree(n_features, depth - 1)
    return Node(feature_idx, threshold, left, right)


def predict_labels(feature_list, tree):
  return [tree.predict(v) for v in feature_list]

def gen_random_tuples(n_items, n_features):
  return [tuple([random.random() for _ in range(n_features)])
          for _ in range(n_items)]


if __name__ == '__main__':
  n_samples = 25000
  n_features = 10
  for i in xrange(100):
    tree = gen_random_tree(n_features, depth = 12)
    features = gen_random_tuples(n_samples, n_features)
    predict_labels(features, tree)

----------
messages: 6070
nosy: agaynor, pypy-issue
priority: performance bug
status: unread
title: Pathological case in bridges

________________________________________
PyPy bug tracker <[email protected]>
<https://bugs.pypy.org/issue1584>
________________________________________
_______________________________________________
pypy-issue mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to