stringbench v2.0 3.3.0a0 (default, Dec 17 2011, 16:56:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] 2011-12-17 18:06:28.347610 bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 1.25 4.68 26.6 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 1.36 4.68 29.1 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 1.07 3.99 26.8 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 1.49 5.66 26.3 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 2.91 2.93 99.1 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.12 0.13 90.2 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 3.15 3.22 98.0 dna.count("AACT") (*10) ========== count newlines 0.86 0.84 102.5 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.88 0.30 294.4 ("A"*1000).find("A") (*1000) 0.66 0.07 960.3 "A" in "A"*1000 (*1000) 0.90 0.30 299.4 ("A"*1000).index("A") (*1000) 0.25 0.34 72.7 ("A"*1000).partition("A") (*1000) 0.97 0.31 310.5 ("A"*1000).rfind("A") (*1000) 0.90 0.31 292.5 ("A"*1000).rindex("A") (*1000) 0.22 0.33 66.7 ("A"*1000).rpartition("A") (*1000) 0.60 0.65 92.7 ("A"*1000).rsplit("A", 1) (*1000) 0.60 0.60 99.7 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.88 0.30 296.2 ("AB"*1000).find("AB") (*1000) 0.65 0.07 928.3 "AB" in "AB"*1000 (*1000) 0.89 0.30 299.5 ("AB"*1000).index("AB") (*1000) 0.28 0.36 78.3 ("AB"*1000).partition("AB") (*1000) 0.96 0.32 300.7 ("AB"*1000).rfind("AB") (*1000) 0.90 0.32 283.7 ("AB"*1000).rindex("AB") (*1000) 0.25 0.34 72.4 ("AB"*1000).rpartition("AB") (*1000) 0.62 0.67 91.8 ("AB"*1000).rsplit("AB", 1) (*1000) 0.66 0.71 92.9 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.33 0.35 96.2 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.33 0.34 98.2 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.33 0.34 96.4 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 1.70 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.09 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.09 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 2.23 2.33 95.9 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 2.36 2.48 95.3 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.59 0.64 90.9 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.58 0.68 85.9 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 2.30 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 2.31 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 11.95 12.11 98.7 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 3.27 3.20 102.1 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 7.60 7.29 104.3 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 12.01 12.11 99.3 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 12.74 12.93 98.5 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 11.59 11.26 102.9 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 4.52 4.34 104.0 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 11.41 11.26 101.3 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 12.10 11.84 102.2 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 12.09 11.70 103.3 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 12.98 12.81 101.3 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 2.39 1.76 135.7 ("AB"*300+"C").find("BC") (*1000) 1.96 1.32 147.7 ("AB"*300+"CA").find("CA") (*1000) 2.07 1.50 137.7 "BC" in ("AB"*300+"C") (*1000) 2.40 1.72 139.6 ("AB"*300+"C").index("BC") (*1000) 1.78 1.88 94.4 ("AB"*300+"C").partition("BC") (*1000) 2.30 1.62 142.0 ("C"+"AB"*300).rfind("CA") (*1000) 2.08 1.22 171.0 ("BC"+"AB"*300).rfind("BC") (*1000) 2.24 1.62 138.4 ("C"+"AB"*300).rindex("CA") (*1000) 1.71 1.72 99.1 ("C"+"AB"*300).rpartition("CA") (*1000) 2.00 2.01 99.7 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 2.15 2.20 97.8 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 2.15 1.58 135.8 ("A"*1000).find("B") (*1000) 1.92 1.34 143.4 "B" in "A"*1000 (*1000) 1.37 1.39 98.5 ("A"*1000).partition("B") (*1000) 1.79 1.14 156.5 ("A"*1000).rfind("B") (*1000) 0.94 0.96 98.4 ("A"*1000).rpartition("B") (*1000) 1.26 1.28 99.0 ("A"*1000).rsplit("B", 1) (*1000) 1.28 1.28 100.1 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 5.53 5.07 109.1 ("AB"*1000).find("BC") (*1000) 4.25 3.62 117.6 ("AB"*1000).find("CA") (*1000) 5.34 5.25 101.6 "BC" in "AB"*1000 (*1000) 5.07 5.45 93.1 ("AB"*1000).partition("BC") (*1000) 5.19 3.64 142.6 ("AB"*1000).rfind("BC") (*1000) 5.97 4.79 124.8 ("AB"*1000).rfind("CA") (*1000) 3.24 3.16 102.7 ("AB"*1000).rpartition("BC") (*1000) 3.78 3.48 108.7 ("AB"*1000).rsplit("BC", 1) (*1000) 5.28 5.24 100.8 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.14 0.15 98.1 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.14 0.14 99.0 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.12 0.16 77.8 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.20 0.23 85.5 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.15 0.19 79.0 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.53 0.58 91.3 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 3.72 3.43 108.4 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 4.21 4.28 98.2 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.37 0.47 77.4 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 1.55 2.23 69.8 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.47 0.56 83.0 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.18 0.25 73.9 ("Here are some words. "*2).partition(" ") (*1000) 0.14 0.18 73.9 ("Here are some words. "*2).rpartition(" ") (*1000) 0.49 0.57 85.2 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.50 0.56 88.4 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 2.56 2.99 85.5 "...text...".rsplit("\n") (*10) 2.52 2.96 85.2 "...text...".split("\n") (*10) 2.81 3.48 80.6 "...text...".splitlines() (*10) ========== split newlines 0.53 0.64 81.8 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.52 0.64 81.4 "this\nis\na\ntest\n".split("\n") (*1000) 0.40 0.48 83.0 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 3.39 3.39 100.2 dna.rsplit("ACTAT") (*10) 3.62 3.75 96.6 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.83 1.07 77.9 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.86 1.07 81.1 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 2.15 2.89 74.2 human_text.rsplit() (*10) 2.24 2.97 75.5 human_text.split() (*10) ========== split whitespace (small) 0.66 0.92 71.6 ("Here are some words. "*2).rsplit() (*1000) 0.75 0.95 79.3 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.34 0.35 97.7 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.33 0.34 98.7 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.33 0.34 97.1 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.12 0.29 41.7 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.09 0.14 62.2 "\nHello!".rstrip() (*1000) 0.09 0.14 63.3 "Hello!\n".rstrip() (*1000) 0.09 0.15 62.6 "\nHello!\n".strip() (*1000) 0.09 0.14 63.1 "\nHello!".strip() (*1000) 0.09 0.14 63.0 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.09 0.15 62.4 "\t \tHello".rstrip() (*1000) 0.09 0.15 61.1 "Hello\t \t".rstrip() (*1000) 0.06 0.08 78.6 "Hello\t \t".strip() (*1000) ========== tab split 0.83 1.01 82.3 GFF3_example.rsplit("\t", 8) (*1000) 0.80 0.96 82.8 GFF3_example.rsplit("\t") (*1000) 0.78 0.94 83.3 GFF3_example.split("\t", 8) (*1000) 0.81 0.97 83.7 GFF3_example.split("\t") (*1000) 262.51 272.92 96.2 TOTAL