Question
In Python We have seen three ways to remove punctuation from a string: using string method replace() and string method translate() in Chapter 4, and
In Python
We have seen three ways to remove punctuation from a string: using string method replace() and string method translate() in Chapter 4, and using regular expressions in chapter 11. Compare the running time of each using the experimental running time analysis framework from Section 10.3.
NOTE: Unlike other problems this quarter, this problem will run automatically when you run the module.
Your output should look like this:
Time analysis on the replace(), translate(), and regular expression methods of
removing punctuation from randomly generated strings using the timing framework from Chapter 10.
Average Run-Time of testRegEx(30) is 3.120041e-06 seconds.
Average Run-Time of testRegEx(280) is 2.340007e-05 seconds.
Average Run-Time of testRegEx(530) is 1.872003e-05 seconds.
Average Run-Time of testTranslate(30) is 1.559997e-06 seconds.
Average Run-Time of testTranslate(280) is 6.240058e-06 seconds.
Average Run-Time of testTranslate(530) is 1.560001e-05 seconds.
Average Run-Time of testReplace(30) is 4.680014e-06 seconds.
Average Run-Time of testReplace(280) is 1.092002e-05 seconds.
Average Run-Time of testReplace(530) is 1.872005e-05 seconds.
timeit.Timer() was used for greater accuracy.
the translate function was the most efficient based on time run analysis.
Time analysis on the replace(), translate(), and regular expression methods of
removing punctuation from randomly generated strings using timeit.Timer()
The average time from on 1,000,000 runs for each input, and each function, is reported.
Testing s = oK~ regEx : 1.8607765000002273e-06 translate : 1.1506263000001126e-06 replace : 4.4082109999997955e-06 Testing s = 6k$VbF.D*vn$Rc00SXFnt#j9|#I"&PGu,?J+VWh)=67K]X~[-h|8;$}6kTeL5mwiH&)!s regEx : 1.4057603399999863e-05 translate : 4.357549200000221e-06 replace : 9.560869499999924e-06 Testing s = _]bh}`=__@{v6lYR/Ea A regEx : 2.5167951100000252e-05 translate : 5.032689299999759e-06 replace : 1.505977929999993e-05
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started