Index: stringbench.py =================================================================== --- stringbench.py (revision 76951) +++ stringbench.py (working copy) @@ -116,10 +116,6 @@ #### same tests as 'in' but use 'find' -# XXX: TODO: Add rfind - - - @bench('("A"*1000).find("A")', "early match, single character", 1000) def find_quick_match_single_character(STR): s1 = STR("A" * 1000) @@ -161,7 +157,7 @@ for x in _RANGE_1000: s1_find(s2) -@bench('s="ABC"*33; ((s+"D")*500+s+"E").find(s)', +@bench('s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E")', "late match, 100 characters", 100) def find_test_slow_match_100_characters(STR): m = STR("ABC"*33) @@ -171,6 +167,60 @@ for x in _RANGE_100: s1_find(s2) + +#### same tests as 'find' + +@bench('("A"*1000).rfind("A")', "early match, single character", 1000) +def rfind_quick_match_single_character(STR): + s1 = STR("A" * 1000) + s2 = STR("A") + s1_find = s1.rfind + for x in _RANGE_1000: + s1_find(s2) + +@bench('("A"*1000).rfind("B")', "no match, single character", 1000) +def rfind_test_no_match_single_character(STR): + s1 = STR("A" * 1000) + s2 = STR("B") + s1_find = s1.rfind + for x in _RANGE_1000: + s1_find(s2) + + +@bench('("AB"*1000).rfind("AB")', "early match, two characters", 1000) +def rfind_test_quick_match_two_characters(STR): + s1 = STR("AB" * 1000) + s2 = STR("AB") + s1_find = s1.rfind + for x in _RANGE_1000: + s1_find(s2) + +@bench('("AB"*1000).rfind("BC")', "no match, two characters", 1000) +def rfind_test_no_match_two_character(STR): + s1 = STR("AB" * 1000) + s2 = STR("BC") + s1_find = s1.rfind + for x in _RANGE_1000: + s1_find(s2) + +@bench('("C"+"AB"*300).rfind("CA")', "late match, two characters", 1000) +def rfind_test_slow_match_two_characters(STR): + s1 = STR("C" + "AB" * 300) + s2 = STR("CA") + s1_find = s1.rfind + for x in _RANGE_1000: + s1_find(s2) + +@bench('s="ABC"*33; ("E"+s+("D"+s)*500).find("E"+s)', + "late match, 100 characters", 100) +def rfind_test_slow_match_100_characters(STR): + m = STR("ABC"*33) + s1 = "E" + m + ("D" + m)*500 + s2 = "E" + m + s1_find = s1.rfind + for x in _RANGE_100: + s1_find(s2) + #### Now with index. # Skip the ones which fail because that would include exception overhead. # Add rindex tests.