############################################ # Before PR 22679 ################# ############################################ bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 0.24 0.25 98.5 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 0.24 0.24 99.2 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 0.24 0.24 99.5 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 0.24 0.25 96.7 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 1.02 1.07 95.3 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.06 0.06 93.6 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 0.55 0.70 77.7 dna.count("AACT") (*10) ========== count newlines 0.69 0.69 99.6 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.12 0.11 107.5 ("A"*1000).find("A") (*1000) 0.24 0.03 834.4 "A" in "A"*1000 (*1000) 0.12 0.11 109.1 ("A"*1000).index("A") (*1000) 0.17 0.17 97.8 ("A"*1000).partition("A") (*1000) 0.13 0.12 106.3 ("A"*1000).rfind("A") (*1000) 0.13 0.12 108.5 ("A"*1000).rindex("A") (*1000) 0.16 0.17 98.1 ("A"*1000).rpartition("A") (*1000) 0.18 0.19 94.3 ("A"*1000).rsplit("A", 1) (*1000) 0.18 0.19 93.8 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.12 0.11 106.8 ("AB"*1000).find("AB") (*1000) 0.24 0.03 717.8 "AB" in "AB"*1000 (*1000) 0.12 0.11 107.2 ("AB"*1000).index("AB") (*1000) 0.18 0.18 100.7 ("AB"*1000).partition("AB") (*1000) 0.13 0.13 106.0 ("AB"*1000).rfind("AB") (*1000) 0.14 0.13 107.6 ("AB"*1000).rindex("AB") (*1000) 0.18 0.17 103.4 ("AB"*1000).rpartition("AB") (*1000) 0.19 0.20 96.8 ("AB"*1000).rsplit("AB", 1) (*1000) 0.19 0.20 97.3 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.10 0.10 97.4 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.10 0.10 100.9 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.10 0.10 97.4 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 0.55 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.01 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.01 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 1.28 1.16 110.3 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 1.39 1.27 109.4 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.41 0.34 121.5 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.42 0.35 121.6 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 0.65 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 0.66 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 2.73 3.88 70.4 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 2.01 3.54 56.8 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 1.66 2.36 70.2 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 2.74 3.89 70.5 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 3.93 4.00 98.4 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 3.99 4.59 86.8 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 1.64 2.23 73.3 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 3.97 4.59 86.4 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 4.69 4.67 100.3 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 4.09 2.82 145.0 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 3.50 3.51 99.7 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 0.44 0.58 76.2 ("AB"*300+"C").find("BC") (*1000) 0.59 0.73 80.5 ("AB"*300+"CA").find("CA") (*1000) 0.55 0.49 112.5 "BC" in ("AB"*300+"C") (*1000) 0.45 0.58 76.5 ("AB"*300+"C").index("BC") (*1000) 0.61 0.62 98.6 ("AB"*300+"C").partition("BC") (*1000) 0.62 0.64 96.4 ("C"+"AB"*300).rfind("CA") (*1000) 0.57 0.65 87.5 ("BC"+"AB"*300).rfind("BC") (*1000) 0.62 0.64 96.5 ("C"+"AB"*300).rindex("CA") (*1000) 0.68 0.69 99.0 ("C"+"AB"*300).rpartition("CA") (*1000) 0.82 0.60 137.8 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 0.63 0.61 103.0 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 0.31 0.29 104.9 ("A"*1000).find("B") (*1000) 0.43 0.21 203.6 "B" in "A"*1000 (*1000) 0.24 0.24 103.2 ("A"*1000).partition("B") (*1000) 0.37 0.37 102.2 ("A"*1000).rfind("B") (*1000) 0.32 0.31 104.1 ("A"*1000).rpartition("B") (*1000) 0.34 0.33 102.4 ("A"*1000).rsplit("B", 1) (*1000) 0.59 0.33 176.6 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 1.12 1.63 68.8 ("AB"*1000).find("BC") (*1000) 1.61 2.11 76.2 ("AB"*1000).find("CA") (*1000) 1.25 1.54 80.8 "BC" in "AB"*1000 (*1000) 1.61 1.58 101.8 ("AB"*1000).partition("BC") (*1000) 1.59 1.90 83.5 ("AB"*1000).rfind("BC") (*1000) 1.77 1.87 94.7 ("AB"*1000).rfind("CA") (*1000) 1.85 1.82 101.5 ("AB"*1000).rpartition("BC") (*1000) 1.46 1.60 91.1 ("AB"*1000).rsplit("BC", 1) (*1000) 1.34 1.33 100.9 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.03 0.03 103.5 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.03 0.03 102.5 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.05 0.06 81.8 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.13 0.14 95.8 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.07 0.08 88.2 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.26 0.26 97.1 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 1.27 1.71 74.3 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 1.04 1.13 91.6 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.10 0.09 109.9 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 0.40 0.56 72.0 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.15 0.15 98.2 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.10 0.11 94.0 ("Here are some words. "*2).partition(" ") (*1000) 0.08 0.09 96.3 ("Here are some words. "*2).rpartition(" ") (*1000) 0.11 0.13 84.7 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.11 0.13 84.2 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 1.24 1.42 87.4 "...text...".rsplit("\n") (*10) 1.26 1.39 90.9 "...text...".split("\n") (*10) 1.35 1.68 80.0 "...text...".splitlines() (*10) ========== split newlines 0.14 0.16 86.6 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.14 0.16 82.6 "this\nis\na\ntest\n".split("\n") (*1000) 0.13 0.16 82.6 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 0.76 0.69 109.9 dna.rsplit("ACTAT") (*10) 0.86 0.88 97.3 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.31 0.34 91.4 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.30 0.34 87.1 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 0.81 1.24 65.9 human_text.rsplit() (*10) 0.74 1.17 63.4 human_text.split() (*10) ========== split whitespace (small) 0.23 0.32 72.7 ("Here are some words. "*2).rsplit() (*1000) 0.24 0.32 74.8 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.10 0.10 98.7 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.10 0.10 102.0 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.10 0.10 99.7 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.06 0.13 44.5 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.05 0.06 85.9 "\nHello!".rstrip() (*1000) 0.05 0.06 84.6 "Hello!\n".rstrip() (*1000) 0.05 0.06 84.8 "\nHello!\n".strip() (*1000) 0.05 0.06 83.9 "\nHello!".strip() (*1000) 0.05 0.06 84.6 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.05 0.07 72.3 "\t \tHello".rstrip() (*1000) 0.05 0.06 85.9 "Hello\t \t".rstrip() (*1000) 0.03 0.03 95.7 "Hello\t \t".strip() (*1000) ========== tab split 0.23 0.27 86.9 GFF3_example.rsplit("\t", 8) (*1000) 0.22 0.28 81.2 GFF3_example.rsplit("\t") (*1000) 0.22 0.25 86.1 GFF3_example.split("\t", 8) (*1000) 0.23 0.29 81.3 GFF3_example.split("\t") (*1000) 81.82 92.62 88.3 TOTAL ############################################ # After PR 22679 ################# ############################################ bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 0.24 0.25 96.0 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 0.24 0.18 130.7 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 0.24 0.25 97.0 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 0.24 0.18 131.3 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 1.04 1.09 94.6 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.06 0.06 88.8 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 0.56 0.55 101.4 dna.count("AACT") (*10) ========== count newlines 0.72 0.70 102.0 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.12 0.11 107.0 ("A"*1000).find("A") (*1000) 0.24 0.03 854.3 "A" in "A"*1000 (*1000) 0.12 0.11 109.6 ("A"*1000).index("A") (*1000) 0.17 0.17 97.4 ("A"*1000).partition("A") (*1000) 0.13 0.12 105.0 ("A"*1000).rfind("A") (*1000) 0.13 0.12 109.7 ("A"*1000).rindex("A") (*1000) 0.16 0.17 96.9 ("A"*1000).rpartition("A") (*1000) 0.19 0.20 95.5 ("A"*1000).rsplit("A", 1) (*1000) 0.19 0.19 97.3 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.12 0.11 108.1 ("AB"*1000).find("AB") (*1000) 0.24 0.03 729.1 "AB" in "AB"*1000 (*1000) 0.12 0.11 109.5 ("AB"*1000).index("AB") (*1000) 0.18 0.18 97.8 ("AB"*1000).partition("AB") (*1000) 0.13 0.13 105.1 ("AB"*1000).rfind("AB") (*1000) 0.14 0.13 107.5 ("AB"*1000).rindex("AB") (*1000) 0.18 0.18 99.6 ("AB"*1000).rpartition("AB") (*1000) 0.20 0.21 96.1 ("AB"*1000).rsplit("AB", 1) (*1000) 0.20 0.21 95.6 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.10 0.10 99.7 "Andrew".endswith("Andrew") (*1000) ========== endswith multiple characters - not! 0.10 0.10 101.0 "Andrew".endswith("Anders") (*1000) ========== endswith single character 0.10 0.10 99.3 "Andrew".endswith("w") (*1000) ========== formatting a string type with a dict N/A 0.55 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.01 0.0 "A".join("") (*100) ========== join empty string, with 5 character sep N/A 0.01 0.0 "ABCDE".join("") (*100) ========== join list of 100 words, with 1 character sep 1.30 1.18 110.4 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 1.40 1.27 110.4 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.43 0.32 131.6 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.43 0.33 131.2 "ABCDE".join(list("ABC..Z")) (*1000) ========== join string with 26 characters, with 1 character sep N/A 0.63 0.0 "A".join("ABC..Z") (*1000) ========== join string with 26 characters, with 5 character sep N/A 0.64 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 0.17 0.15 116.3 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 0.89 0.87 101.8 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 0.15 0.13 111.5 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 0.17 0.15 112.4 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 0.30 0.27 108.0 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 3.13 2.51 124.5 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 1.54 1.82 84.5 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 3.18 2.53 125.8 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 3.37 2.66 126.9 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 3.39 2.62 129.5 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 0.30 0.28 106.0 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 0.57 0.48 120.2 ("AB"*300+"C").find("BC") (*1000) 0.56 0.72 77.5 ("AB"*300+"CA").find("CA") (*1000) 0.66 0.37 177.7 "BC" in ("AB"*300+"C") (*1000) 0.57 0.49 116.5 ("AB"*300+"C").index("BC") (*1000) 0.72 0.52 137.2 ("AB"*300+"C").partition("BC") (*1000) 0.49 0.49 101.6 ("C"+"AB"*300).rfind("CA") (*1000) 0.51 0.57 89.3 ("BC"+"AB"*300).rfind("BC") (*1000) 0.50 0.49 101.2 ("C"+"AB"*300).rindex("CA") (*1000) 0.61 0.54 113.5 ("C"+"AB"*300).rpartition("CA") (*1000) 0.63 0.57 112.0 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 0.74 0.54 138.2 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 0.30 0.29 103.7 ("A"*1000).find("B") (*1000) 0.43 0.20 212.9 "B" in "A"*1000 (*1000) 0.24 0.24 100.1 ("A"*1000).partition("B") (*1000) 0.37 0.37 102.4 ("A"*1000).rfind("B") (*1000) 0.32 0.31 104.0 ("A"*1000).rpartition("B") (*1000) 0.33 0.33 102.3 ("A"*1000).rsplit("B", 1) (*1000) 0.58 0.33 178.3 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 1.52 1.24 122.9 ("AB"*1000).find("BC") (*1000) 1.51 2.03 74.6 ("AB"*1000).find("CA") (*1000) 1.62 1.14 141.4 "BC" in "AB"*1000 (*1000) 1.93 1.18 163.4 ("AB"*1000).partition("BC") (*1000) 1.41 1.64 85.7 ("AB"*1000).rfind("BC") (*1000) 1.33 1.34 99.5 ("AB"*1000).rfind("CA") (*1000) 1.79 1.52 117.5 ("AB"*1000).rpartition("BC") (*1000) 1.59 1.58 100.9 ("AB"*1000).rsplit("BC", 1) (*1000) 1.96 1.20 163.7 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.03 0.04 89.6 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.03 0.04 87.9 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.05 0.06 87.6 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.13 0.14 92.0 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.07 0.08 85.8 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.27 0.27 98.0 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 1.28 1.64 78.1 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) 1.04 0.96 109.2 dna.replace("ATC", "ATT") (*10) 0.09 0.09 104.2 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 0.41 0.50 81.9 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.15 0.15 102.5 "When shall we three meet again?".replace("ee", "") (*1000) ========== split 1 whitespace 0.10 0.11 92.8 ("Here are some words. "*2).partition(" ") (*1000) 0.08 0.09 92.7 ("Here are some words. "*2).rpartition(" ") (*1000) 0.11 0.13 87.3 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.11 0.13 85.1 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 1.24 1.45 85.3 "...text...".rsplit("\n") (*10) 1.25 1.41 89.2 "...text...".split("\n") (*10) 1.31 1.68 78.3 "...text...".splitlines() (*10) ========== split newlines 0.14 0.16 83.4 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.14 0.16 84.6 "this\nis\na\ntest\n".split("\n") (*1000) 0.13 0.16 77.2 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 0.76 0.70 108.5 dna.rsplit("ACTAT") (*10) 0.93 0.84 111.8 dna.split("ACTAT") (*10) 0.33 0.37 89.6 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.34 0.38 87.8 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 0.78 1.21 64.5 human_text.rsplit() (*10) 0.75 1.12 67.3 human_text.split() (*10) ========== split whitespace (small) 0.23 0.33 70.0 ("Here are some words. "*2).rsplit() (*1000) 0.24 0.31 76.3 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.10 0.10 99.2 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.10 0.10 102.2 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.10 0.10 98.5 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.06 0.13 43.8 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.05 0.06 84.9 "\nHello!".rstrip() (*1000) 0.05 0.06 82.4 "Hello!\n".rstrip() (*1000) 0.05 0.06 83.7 "\nHello!\n".strip() (*1000) 0.05 0.06 83.9 "\nHello!".strip() (*1000) 0.05 0.06 84.6 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.05 0.06 84.6 "\t \tHello".rstrip() (*1000) 0.05 0.06 83.7 "Hello\t \t".rstrip() (*1000) 0.03 0.03 92.6 "Hello\t \t".strip() (*1000) ========== tab split 0.23 0.27 84.0 GFF3_example.rsplit("\t", 8) (*1000) 0.21 0.26 83.5 GFF3_example.rsplit("\t") (*1000) 0.21 0.25 83.6 GFF3_example.split("\t", 8) (*1000) 0.23 0.32 72.9 GFF3_example.split("\t") (*1000) 64.70 62.41 103.7 TOTAL