Plum rain operational requirements 20190919-3

This job requires See https://edu.cnblogs.com/campus/nenu/2019fall/homework/7628

• Requirements 0 to war and peace as the input file, and re-read by the file system to read into. Three consecutive runs, given time, CPU consumption of each parameter.

Requirements 0  to "War and Peace" as the input file, and re-read by the file system to read into. Three consecutive runs, each given time, CPU consumption parameters

Test Method: Inputptime wf -s < war_and_peace.txt

The first test time shots:

 

 The second test time shots:

 

 Screenshot third test of time:

 

 Statistics:

 

 Requirements 1 shows the bottleneck in your program's guess. Do you think there will be optimized for best results, or last week's optimized here (or take into account optimization, and therefore worse code not written).

Bottlenecks: the character conversion process used too much time, code efficiency can be optimized by the process of the function package

while True:
        lastchar = word1[-1:]
        if lastchar in [",", ".", "!", "?", ";", '"',"-","*","%"]:
            word2 = word1.rstrip(lastchar)
            word1 = word2
        else:
            word2 = word1
            break
 
    while True:
        firstchar = word2[0:]
        if firstchar in [",", ".", "!", "?", ";", '"',"-","*","%"]:
            word3 = word2.lstrip(firstchar)
            word2 = word3
        else:
            word3 = word2
            break

 

Requirement 2 bottlenecks profile to find out the program. We are given the most time running three functions (or code fragment). Requirements include a screenshot. (5 points)

要求 分析为什么此处是瓶颈。要求 profile需要得到函数的运行时间和次数。仅得到CPU和内存占用,不得分。

Entrypython -m cProfile -s time wf.py -s < war_and_peace.txt

 

 

The most time-consuming three functions:

 

 The bottleneck in claim 3, "best effort" to optimize the performance of the program. (5 points)

 Modified snippet:

while True:
               lastchar = word1[-1:]
               for lastchar in '\r .,"':
                   word2 = word1.rstrip(lastchar)
                   word1 = word2
               else:
                   word2 = word1
                   break
 
           while True:
               firstchar = word2[0:]
               for lastchar in '\r .,"':
                   word3 = word2.lstrip(firstchar)
                   word2 = word3
               else:
                   word3 = word2
                   break
                   # build a wordList of lower case modified words
           word_list2.append(word3)

English character formatting section encapsulates

Requirements 4: profile again, takes most time three functions in claim 1 at this time is given.

 

 At this point three functions Cost:

 

 And then tested three times:

 

 

 

 

Requirements to run 5 times. Depending on the speed run on the teacher's machine (Windows8.1) ranking, divided into three files. This problem score 20 points of the first gear, the second gear 10 min, the third gear 5 minutes. Functional test can not pass, 0.

git address for teachers to test

 

 

 

 


 

Guess you like

Origin www.cnblogs.com/MAY6/p/11576061.html