stringbench v2.0 3.2.2+ (default, Dec 17 2011, 16:55:59) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] 2011-12-17 18:05:13.490980 bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 1.47 3.75 39.1 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 1.37 3.82 36.0 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 1.20 3.85 31.2 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 1.70 4.84 35.1 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 3.00 3.17 94.6 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.13 0.10 123.2 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 3.15 3.18 98.8 dna.count("AACT") (*10) ========== count newlines 0.94 0.86 108.8 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.26 0.25 103.1 ("A"*1000).find("A") (*1000) 0.59 0.06 1006.2 "A" in "A"*1000 (*1000) 0.26 0.26 103.1 ("A"*1000).index("A") (*1000) 0.25 0.29 85.6 ("A"*1000).partition("A") (*1000) 0.29 0.29 102.3 ("A"*1000).rfind("A") (*1000) 0.28 0.28 102.8 ("A"*1000).rindex("A") (*1000) 0.23 0.26 86.8 ("A"*1000).rpartition("A") (*1000) 0.57 0.61 93.5 ("A"*1000).rsplit("A", 1) (*1000) 0.56 0.59 94.3 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.27 0.26 104.5 ("AB"*1000).find("AB") (*1000) 0.61 0.06 974.1 "AB" in "AB"*1000 (*1000) 0.28 0.26 105.3 ("AB"*1000).index("AB") (*1000) 0.30 0.37 81.1 ("AB"*1000).partition("AB") (*1000) 0.29 0.28 104.3 ("AB"*1000).rfind("AB") (*1000) 0.29 0.28 104.1 ("AB"*1000).rindex("AB") (*1000) 0.26 0.33 80.8 ("AB"*1000).rpartition("AB") (*1000) 0.62 0.67 92.4 ("AB"*1000).rsplit("AB", 1) (*1000) 0.63 0.68 93.0 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.27 0.27 97.5 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.27 0.26 105.3 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.26 0.26 100.4 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 0.86 0.0 "The %(k1)s is %(k2)s the %(k3)s."%{"k1":"x","k2":"y","k3":"z",} (*1000) ========== join empty string, with 1 character sep N/A 0.08 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.08 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 2.44 2.02 121.2 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 2.42 2.04 118.3 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.61 0.59 104.1 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.60 0.75 80.5 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 2.07 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 2.28 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 12.39 12.34 100.4 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 3.21 3.64 88.2 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 6.97 7.19 97.0 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 12.38 12.41 99.8 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 12.76 13.12 97.2 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 11.43 11.83 96.6 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 3.21 3.55 90.4 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 11.53 11.80 97.7 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 12.05 13.02 92.5 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 12.14 13.09 92.8 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 12.99 13.39 97.0 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 1.71 1.73 98.6 ("AB"*300+"C").find("BC") (*1000) 1.30 1.41 92.3 ("AB"*300+"CA").find("CA") (*1000) 2.11 1.48 142.6 "BC" in ("AB"*300+"C") (*1000) 1.71 1.68 102.1 ("AB"*300+"C").index("BC") (*1000) 1.79 1.71 104.5 ("AB"*300+"C").partition("BC") (*1000) 1.62 1.65 97.9 ("C"+"AB"*300).rfind("CA") (*1000) 1.19 1.22 97.1 ("BC"+"AB"*300).rfind("BC") (*1000) 1.59 1.66 96.2 ("C"+"AB"*300).rindex("CA") (*1000) 1.67 1.67 100.0 ("C"+"AB"*300).rpartition("CA") (*1000) 1.98 2.02 97.8 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 2.09 2.00 104.4 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 1.11 1.10 101.0 ("A"*1000).find("B") (*1000) 1.45 0.91 159.4 "B" in "A"*1000 (*1000) 0.95 1.36 69.5 ("A"*1000).partition("B") (*1000) 1.11 1.10 100.8 ("A"*1000).rfind("B") (*1000) 0.94 0.95 99.8 ("A"*1000).rpartition("B") (*1000) 1.26 1.25 101.1 ("A"*1000).rsplit("B", 1) (*1000) 1.26 1.23 102.1 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 5.06 5.05 100.3 ("AB"*1000).find("BC") (*1000) 3.58 3.98 90.0 ("AB"*1000).find("CA") (*1000) 5.46 4.77 114.4 "BC" in "AB"*1000 (*1000) 5.06 4.96 102.0 ("AB"*1000).partition("BC") (*1000) 3.34 3.41 97.9 ("AB"*1000).rfind("BC") (*1000) 4.74 4.87 97.3 ("AB"*1000).rfind("CA") (*1000) 3.15 3.26 96.8 ("AB"*1000).rpartition("BC") (*1000) 3.99 3.58 111.2 ("AB"*1000).rsplit("BC", 1) (*1000) 5.27 5.16 102.0 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.14 0.27 53.2 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.14 0.27 53.4 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.13 0.14 87.8 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.21 1.04 19.8 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.16 0.21 76.6 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.54 0.76 71.7 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 3.69 3.12 118.0 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 4.09 4.37 93.5 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.34 0.38 89.8 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 1.55 1.39 111.6 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.45 0.52 86.0 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.19 0.20 97.4 ("Here are some words. "*2).partition(" ") (*1000) 0.14 0.16 91.5 ("Here are some words. "*2).rpartition(" ") (*1000) 0.48 0.58 82.3 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.49 0.51 95.6 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 2.62 3.40 76.9 "...text...".rsplit("\n") (*10) 2.48 3.28 75.5 "...text...".split("\n") (*10) 2.75 3.87 71.0 "...text...".splitlines() (*10) ========== split newlines 0.51 0.49 104.1 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.51 0.49 104.4 "this\nis\na\ntest\n".split("\n") (*1000) 0.46 0.50 91.9 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 3.47 3.35 103.3 dna.rsplit("ACTAT") (*10) 3.55 2.96 119.9 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.83 1.00 83.0 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.88 0.83 105.8 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 2.12 3.35 63.3 human_text.rsplit() (*10) 2.19 3.18 68.8 human_text.split() (*10) ========== split whitespace (small) 0.67 0.94 71.0 ("Here are some words. "*2).rsplit() (*1000) 0.71 0.74 95.6 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.27 0.28 97.1 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.26 0.26 101.2 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.26 0.27 98.8 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.13 0.27 45.7 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.09 0.09 102.0 "\nHello!".rstrip() (*1000) 0.09 0.09 102.2 "Hello!\n".rstrip() (*1000) 0.10 0.10 100.5 "\nHello!\n".strip() (*1000) 0.10 0.10 100.1 "\nHello!".strip() (*1000) 0.10 0.09 102.1 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.10 0.10 101.0 "\t \tHello".rstrip() (*1000) 0.10 0.10 99.8 "Hello\t \t".rstrip() (*1000) 0.06 0.07 92.2 "Hello\t \t".strip() (*1000) ========== tab split 0.85 0.90 94.5 GFF3_example.rsplit("\t", 8) (*1000) 0.80 0.85 94.3 GFF3_example.rsplit("\t") (*1000) 0.81 0.80 100.8 GFF3_example.split("\t", 8) (*1000) 0.82 0.81 101.7 GFF3_example.split("\t") (*1000) 245.64 269.24 91.2 TOTAL