Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r50465:bbbbff8ac1d3 Date: 2011-12-13 16:53 +0100 http://bitbucket.org/pypy/pypy/changeset/bbbbff8ac1d3/
Log: Checking a lighter variant of SpecialisedTuples with only 'ii', 'ff' and 'oo' specialisations. It seems that the previous version causes long warm-up times on the sympy_* benchmarks. We will see how it compares in performance. diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py --- a/pypy/objspace/std/specialisedtupleobject.py +++ b/pypy/objspace/std/specialisedtupleobject.py @@ -177,52 +177,55 @@ _specialisations = [] Cls_ii = make_specialised_class((int, int)) -Cls_is = make_specialised_class((int, str)) -Cls_io = make_specialised_class((int, object)) -Cls_si = make_specialised_class((str, int)) -Cls_ss = make_specialised_class((str, str)) -Cls_so = make_specialised_class((str, object)) -Cls_oi = make_specialised_class((object, int)) -Cls_os = make_specialised_class((object, str)) +#Cls_is = make_specialised_class((int, str)) +#Cls_io = make_specialised_class((int, object)) +#Cls_si = make_specialised_class((str, int)) +#Cls_ss = make_specialised_class((str, str)) +#Cls_so = make_specialised_class((str, object)) +#Cls_oi = make_specialised_class((object, int)) +#Cls_os = make_specialised_class((object, str)) Cls_oo = make_specialised_class((object, object)) Cls_ff = make_specialised_class((float, float)) -Cls_ooo = make_specialised_class((object, object, object)) +#Cls_ooo = make_specialised_class((object, object, object)) def makespecialisedtuple(space, list_w): if len(list_w) == 2: w_arg1, w_arg2 = list_w w_type1 = space.type(w_arg1) - w_type2 = space.type(w_arg2) + #w_type2 = space.type(w_arg2) # if w_type1 is space.w_int: + w_type2 = space.type(w_arg2) if w_type2 is space.w_int: return Cls_ii(space, w_arg1, w_arg2) - elif w_type2 is space.w_str: - return Cls_is(space, w_arg1, w_arg2) - else: - return Cls_io(space, w_arg1, w_arg2) + #elif w_type2 is space.w_str: + # return Cls_is(space, w_arg1, w_arg2) + #else: + # return Cls_io(space, w_arg1, w_arg2) # - elif w_type1 is space.w_str: - if w_type2 is space.w_int: - return Cls_si(space, w_arg1, w_arg2) - elif w_type2 is space.w_str: - return Cls_ss(space, w_arg1, w_arg2) - else: - return Cls_so(space, w_arg1, w_arg2) + #elif w_type1 is space.w_str: + # if w_type2 is space.w_int: + # return Cls_si(space, w_arg1, w_arg2) + # elif w_type2 is space.w_str: + # return Cls_ss(space, w_arg1, w_arg2) + # else: + # return Cls_so(space, w_arg1, w_arg2) # - elif w_type1 is space.w_float and w_type2 is space.w_float: - return Cls_ff(space, w_arg1, w_arg2) + elif w_type1 is space.w_float: + w_type2 = space.type(w_arg2) + if w_type2 is space.w_float: + return Cls_ff(space, w_arg1, w_arg2) # - else: - if w_type2 is space.w_int: - return Cls_oi(space, w_arg1, w_arg2) - elif w_type2 is space.w_str: - return Cls_os(space, w_arg1, w_arg2) - else: - return Cls_oo(space, w_arg1, w_arg2) + #else: + # if w_type2 is space.w_int: + # return Cls_oi(space, w_arg1, w_arg2) + # elif w_type2 is space.w_str: + # return Cls_os(space, w_arg1, w_arg2) + # else: + return Cls_oo(space, w_arg1, w_arg2) # - elif len(list_w) == 3: - return Cls_ooo(space, list_w[0], list_w[1], list_w[2]) + #elif len(list_w) == 3: + # return Cls_ooo(space, list_w[0], list_w[1], list_w[2]) else: raise NotSpecialised diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py --- a/pypy/objspace/std/test/test_specialisedtupleobject.py +++ b/pypy/objspace/std/test/test_specialisedtupleobject.py @@ -33,15 +33,15 @@ N_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": False}) S_space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True}) - def hash_test(values): + def hash_test(values, must_be_specialized=True): N_values_w = [N_space.wrap(value) for value in values] S_values_w = [S_space.wrap(value) for value in values] N_w_tuple = N_space.newtuple(N_values_w) S_w_tuple = S_space.newtuple(S_values_w) - - assert isinstance(S_w_tuple, W_SpecialisedTupleObject) + + if must_be_specialized: + assert isinstance(S_w_tuple, W_SpecialisedTupleObject) assert isinstance(N_w_tuple, W_TupleObject) - assert not N_space.is_true(N_space.eq(N_w_tuple, S_w_tuple)) assert S_space.is_true(S_space.eq(N_w_tuple, S_w_tuple)) assert S_space.is_true(S_space.eq(N_space.hash(N_w_tuple), S_space.hash(S_w_tuple))) @@ -53,7 +53,7 @@ hash_test([1,(1,2)]) hash_test([1,('a',2)]) hash_test([1,()]) - hash_test([1,2,3]) + hash_test([1,2,3], must_be_specialized=False) class AppTestW_SpecialisedTupleObject: @@ -83,6 +83,8 @@ return ("SpecialisedTupleObject" + expected) in r def test_createspecialisedtuple(self): + have = ['ii', 'ff', 'oo'] + # spec = {int: 'i', float: 'f', str: 's', @@ -92,14 +94,14 @@ for y in [43, 4.3, "bar", []]: expected1 = spec[type(x)] expected2 = spec[type(y)] - if (expected1 == 'f') ^ (expected2 == 'f'): - if expected1 == 'f': expected1 = 'o' - if expected2 == 'f': expected2 = 'o' + if expected1 + expected2 not in have: + expected1 = expected2 = 'o' obj = (x, y) assert self.isspecialised(obj, '_' + expected1 + expected2) # - obj = (1, 2, 3) - assert self.isspecialised(obj, '_ooo') + if 'ooo' in have: + obj = (1, 2, 3) + assert self.isspecialised(obj, '_ooo') def test_delegation(self): t = self.forbid_delegation((42, 43)) @@ -214,6 +216,8 @@ raises(IndexError, "t[-3]") def test_three_tuples(self): + if not self.isspecialised((1, 2, 3)): + skip("don't have specialization for 3-tuples") b = self.forbid_delegation((1, 2, 3)) c = (1,) d = c + (2, 3) @@ -221,6 +225,16 @@ assert b == d def test_mongrel(self): + a = self.forbid_delegation((2.2, '333')) + assert self.isspecialised(a) + assert len(a) == 2 + assert a[0] == 2.2 and a[1] == '333' + b = ('333',) + assert a == (2.2,) + b + assert not a != (2.2,) + b + # + if not self.isspecialised((1, 2, 3)): + skip("don't have specialization for 3-tuples") a = self.forbid_delegation((1, 2.2, '333')) assert self.isspecialised(a) assert len(a) == 3 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit