Wei Xin 20190919-3 Effectiveness Analysis

See the requirements for this job: https: //edu.cnblogs.com/campus/nenu/2019fall/homework/7628

The modified code address is: https: //e.coding.net/Eustia/wf.git

Requirements 0

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.

cpu parameters: Intel Core i7-4710MQ 2.50GHz

Time-consuming: 4.872s, 4.811s, 4.818s

Average elapsed time: 4.834s

Screenshot below:

Requirements 1

Given 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).

Sorting the number of characters appeared many times were sort of useless, resulting in an increase in time. I think there will be optimized for best results here.

// appears the word frequency sort 
for (I = 0 ; I < 50000 ; I ++ ) 
{ 
    Q [I] = WD [I] .time; 
} 
Sort (Q, Q + 50000 , Greater < int > ());

Requirement 2

By profile to identify bottlenecks program. We are given the most time running three functions (or code fragment). Requirements include a screenshot.

Since last week codeblocks used to program this week to analyze the effectiveness of the code moved vs2017 above, but after several hours of debugging is still not successfully carry out performance analysis, so can not give shots. Guessing programs running most time three functions or code fragment:

for(i=0;i<total+1;i++)
{
    q[i]=wd[i].time;
}
sort(q,q+total+1,greater<int>());
for(j=0;j<total;j++)
{
    if(wd[j].time==q[i])
    {
        j=j+flag;
        while(wd[j].time!=q[i])
        {
            j=j+1;
            flag++;
        }
        printf("%s",wd[j].s_wd);
        strcpy(c_temp,wd[j].s_wd);
        len=strlen(wd[j].s_wd);
        s=15-len;
        temp=q[i];
        break;
    }
}      
while((c=getchar())!=EOF)
{
    if(fflag==1)
    {
        if((c>=65&&c<=90)||(c>=97&&c<=122))
        {
            if(c>=65&&c<=90)
            {
                c=c+32;
            }
            word[ii]=c;
            ii++;
        }
        fflag=0;
    }
    else
    {
        if((c>=65&&c<=90)||(c>=97&&c<=122)||(c==39)||(c==45))
        {
            if(c>=65&&c<=90)
            {
            c=c+32;
            }
            word[ii]=c;
            ii++;
        }
        else
        {
            if(ii>0)
            {
                wdcount(word);
                memset(word, 0, sizeof (word)); 
                ii = 0 ; 
                flag = 1 ; 
            } 
        } 
    } 
}

Requirement 3

According to the bottleneck, "best effort" to optimize program performance.

Since this function is relatively simple, can simply modify the parameters, the modified code as follows:

for(i=0;i<total+1;i++)
{
    q[i]=wd[i].time;
}
sort(q,q+total+1,greater<int>());

Screenshot optimized to run as follows:

Running time: 4.776s, 4.790s, 4.796s

The average running time: 4.787s

Requirements 4

Again profile given in this case spent most time in claim 3 in 1 function. Requirements include a screenshot.

Performance analysis can not be successful, therefore the question can not be completed.

Guess you like

Origin www.cnblogs.com/Eustia/p/11584297.html