############################################ # Before PR 22904 ################# ############################################ 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 22904 ################# ############################################ 2020-10-23 18:41:57.374181 bytes unicode (in ms) (in ms) % comment ========== case conversion -- dense 0.25 0.25 98.7 ("WHERE IN THE WORLD IS CARMEN SAN DEIGO?"*10).lower() (*1000) 0.24 0.25 97.4 ("where in the world is carmen san deigo?"*10).upper() (*1000) ========== case conversion -- rare 0.28 0.29 98.5 ("Where in the world is Carmen San Deigo?"*10).lower() (*1000) 0.24 0.25 97.8 ("wHERE IN THE WORLD IS cARMEN sAN dEIGO?"*10).upper() (*1000) ========== concat 20 strings of words length 4 to 15 1.05 1.03 101.8 s1+s2+s3+s4+...+s20 (*1000) ========== concat two strings 0.05 0.06 87.7 "Andrew"+"Dalke" (*1000) ========== count AACT substrings in DNA example 0.63 0.67 94.0 dna.count("AACT") (*10) ========== count newlines 0.72 0.72 100.1 ...text.with.2000.newlines.count("\n") (*10) ========== early match, single character 0.11 0.11 104.8 ("A"*1000).find("A") (*1000) 0.29 0.07 406.4 "A" in "A"*1000 (*1000) 0.19 0.18 106.3 ("A"*1000).index("A") (*1000) 0.17 0.17 98.3 ("A"*1000).partition("A") (*1000) 0.13 0.12 106.8 ("A"*1000).rfind("A") (*1000) 0.13 0.12 108.4 ("A"*1000).rindex("A") (*1000) 0.16 0.17 95.6 ("A"*1000).rpartition("A") (*1000) 0.18 0.19 94.5 ("A"*1000).rsplit("A", 1) (*1000) 0.18 0.20 93.8 ("A"*1000).split("A", 1) (*1000) ========== early match, two characters 0.12 0.11 104.8 ("AB"*1000).find("AB") (*1000) 0.24 0.03 742.4 "AB" in "AB"*1000 (*1000) 0.12 0.11 104.8 ("AB"*1000).index("AB") (*1000) 0.18 0.18 99.9 ("AB"*1000).partition("AB") (*1000) 0.13 0.12 105.2 ("AB"*1000).rfind("AB") (*1000) 0.13 0.12 108.1 ("AB"*1000).rindex("AB") (*1000) 0.18 0.18 96.6 ("AB"*1000).rpartition("AB") (*1000) 0.20 0.21 96.0 ("AB"*1000).rsplit("AB", 1) (*1000) 0.20 0.21 96.9 ("AB"*1000).split("AB", 1) (*1000) ========== endswith multiple characters 0.10 0.10 99.1 "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.0 "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.33 1.20 111.0 "A".join(["Bob"]*100)) (*1000) ========== join list of 100 words, with 5 character sep 1.42 1.26 113.1 "ABCDE".join(["Bob"]*100)) (*1000) ========== join list of 26 characters, with 1 character sep 0.43 0.33 129.2 "A".join(list("ABC..Z")) (*1000) ========== join list of 26 characters, with 5 character sep 0.43 0.33 131.7 "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.63 0.0 "ABCDE".join("ABC..Z") (*1000) ========== late match, 100 characters 6.06 6.01 100.8 s="ABC"*33; ((s+"D")*500+s+"E").find(s+"E") (*100) 0.92 0.91 101.4 s="ABC"*33; ((s+"D")*500+"E"+s).find("E"+s) (*100) 3.63 3.59 101.2 s="ABC"*33; (s+"E") in ((s+"D")*300+s+"E") (*100) 6.00 5.94 101.1 s="ABC"*33; ((s+"D")*500+s+"E").index(s+"E") (*100) 6.05 6.10 99.2 s="ABC"*33; ((s+"D")*500+s+"E").partition(s+"E") (*100) 2.64 4.07 64.9 s="ABC"*33; ("E"+s+("D"+s)*500).rfind("E"+s) (*100) 1.95 1.85 105.2 s="ABC"*33; (s+"E"+("D"+s)*500).rfind(s+"E") (*100) 2.64 3.97 66.4 s="ABC"*33; ("E"+s+("D"+s)*500).rindex("E"+s) (*100) 2.85 4.09 69.7 s="ABC"*33; ("E"+s+("D"+s)*500).rpartition("E"+s) (*100) 2.91 4.08 71.2 s="ABC"*33; ("E"+s+("D"+s)*500).rsplit("E"+s, 1) (*100) 6.04 6.02 100.3 s="ABC"*33; ((s+"D")*500+s+"E").split(s+"E", 1) (*100) ========== late match, two characters 0.55 0.56 98.4 ("AB"*300+"C").find("BC") (*1000) 0.64 0.70 91.4 ("AB"*300+"CA").find("CA") (*1000) 0.66 0.53 125.9 "BC" in ("AB"*300+"C") (*1000) 0.55 0.57 97.1 ("AB"*300+"C").index("BC") (*1000) 0.58 0.62 93.0 ("AB"*300+"C").partition("BC") (*1000) 0.47 0.60 78.0 ("C"+"AB"*300).rfind("CA") (*1000) 0.62 0.61 101.2 ("BC"+"AB"*300).rfind("BC") (*1000) 0.47 0.60 78.2 ("C"+"AB"*300).rindex("CA") (*1000) 0.48 0.66 73.4 ("C"+"AB"*300).rpartition("CA") (*1000) 0.52 0.69 74.8 ("C"+"AB"*300).rsplit("CA", 1) (*1000) 0.60 0.72 83.4 ("AB"*300+"C").split("BC", 1) (*1000) ========== no match, single character 0.32 0.32 100.5 ("A"*1000).find("B") (*1000) 0.45 0.21 210.6 "B" in "A"*1000 (*1000) 0.26 0.25 103.4 ("A"*1000).partition("B") (*1000) 0.38 0.36 105.1 ("A"*1000).rfind("B") (*1000) 0.33 0.31 104.3 ("A"*1000).rpartition("B") (*1000) 0.34 0.33 101.6 ("A"*1000).rsplit("B", 1) (*1000) 0.58 0.33 175.4 ("A"*1000).split("B", 1) (*1000) ========== no match, two characters 1.49 1.51 98.7 ("AB"*1000).find("BC") (*1000) 1.77 2.00 88.5 ("AB"*1000).find("CA") (*1000) 1.63 1.54 105.9 "BC" in "AB"*1000 (*1000) 1.45 1.45 99.6 ("AB"*1000).partition("BC") (*1000) 1.78 1.75 101.7 ("AB"*1000).rfind("BC") (*1000) 1.25 1.75 71.8 ("AB"*1000).rfind("CA") (*1000) 1.41 1.70 83.0 ("AB"*1000).rpartition("BC") (*1000) 1.45 1.72 84.7 ("AB"*1000).rsplit("BC", 1) (*1000) 1.48 1.49 99.2 ("AB"*1000).split("BC", 1) (*1000) ========== quick replace multiple character match 0.04 0.04 102.5 ("A" + ("Z"*128*1024)).replace("AZZ", "BBZZ", 1) (*10) ========== quick replace single character match 0.04 0.04 100.8 ("A" + ("Z"*128*1024)).replace("A", "BB", 1) (*10) ========== repeat 1 character 10 times 0.05 0.06 84.6 "A"*10 (*1000) ========== repeat 1 character 1000 times 0.13 0.14 94.8 "A"*1000 (*1000) ========== repeat 5 characters 10 times 0.07 0.09 78.7 "ABCDE"*10 (*1000) ========== repeat 5 characters 1000 times 0.25 0.26 96.6 "ABCDE"*1000 (*1000) ========== replace and expand multiple characters, big string 1.28 1.74 73.2 "...text.with.2000.newlines...replace("\n", "\r\n") (*10) ========== replace multiple characters, dna 1.01 1.06 95.0 dna.replace("ATC", "ATT") (*10) ========== replace single character 0.09 0.09 104.1 "This is a test".replace(" ", "\t") (*1000) ========== replace single character, big string 0.41 0.52 78.4 "...text.with.2000.lines...replace("\n", " ") (*10) ========== replace/remove multiple characters 0.15 0.15 94.4 "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 90.3 ("Here are some words. "*2).rpartition(" ") (*1000) 0.11 0.13 83.7 ("Here are some words. "*2).rsplit(None, 1) (*1000) 0.10 0.13 82.8 ("Here are some words. "*2).split(None, 1) (*1000) ========== split 2000 newlines 1.24 1.41 88.1 "...text...".rsplit("\n") (*10) 1.26 1.40 90.2 "...text...".split("\n") (*10) 1.34 1.69 79.4 "...text...".splitlines() (*10) ========== split newlines 0.14 0.17 85.4 "this\nis\na\ntest\n".rsplit("\n") (*1000) 0.14 0.17 84.7 "this\nis\na\ntest\n".split("\n") (*1000) 0.14 0.17 81.8 "this\nis\na\ntest\n".splitlines() (*1000) ========== split on multicharacter separator (dna) 0.67 0.83 81.0 dna.rsplit("ACTAT") (*10) 0.83 0.89 92.7 dna.split("ACTAT") (*10) ========== split on multicharacter separator (small) 0.33 0.37 88.4 "this--is--a--test--of--the--emergency--broadcast--system".rsplit("--") (*1000) 0.34 0.39 87.4 "this--is--a--test--of--the--emergency--broadcast--system".split("--") (*1000) ========== split whitespace (huge) 0.77 1.21 63.6 human_text.rsplit() (*10) 0.75 1.12 66.8 human_text.split() (*10) ========== split whitespace (small) 0.23 0.33 69.7 ("Here are some words. "*2).rsplit() (*1000) 0.23 0.32 73.4 ("Here are some words. "*2).split() (*1000) ========== startswith multiple characters 0.10 0.10 98.9 "Andrew".startswith("Andrew") (*1000) ========== startswith multiple characters - not! 0.10 0.10 101.6 "Andrew".startswith("Anders") (*1000) ========== startswith single character 0.10 0.10 99.7 "Andrew".startswith("A") (*1000) ========== strip terminal newline 0.05 0.13 41.2 s="Hello!\n"; s[:-1] if s[-1]=="\n" else s (*1000) 0.05 0.06 82.5 "\nHello!".rstrip() (*1000) 0.05 0.06 84.6 "Hello!\n".rstrip() (*1000) 0.05 0.07 71.7 "\nHello!\n".strip() (*1000) 0.05 0.06 83.9 "\nHello!".strip() (*1000) 0.05 0.06 84.7 "Hello!\n".strip() (*1000) ========== strip terminal spaces and tabs 0.05 0.06 81.1 "\t \tHello".rstrip() (*1000) 0.05 0.06 86.8 "Hello\t \t".rstrip() (*1000) 0.03 0.03 93.6 "Hello\t \t".strip() (*1000) ========== tab split 0.23 0.27 83.8 GFF3_example.rsplit("\t", 8) (*1000) 0.22 0.26 82.9 GFF3_example.rsplit("\t") (*1000) 0.21 0.25 82.0 GFF3_example.split("\t", 8) (*1000) 0.23 0.31 74.8 GFF3_example.split("\t") (*1000) 88.60 99.03 89.5 TOTAL