⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 explaination.txt

📁 ssd 练习4答案
💻 TXT
字号:
Profile: Function timing, sorted by time
Date:    Wed Nov 12 10:42:37 2008


Program Statistics
------------------
    Command line at 2008 Nov 12 10:42: "F:\d64\Debug\d64" replace.txt call.cpp semantics.cpp math.cpp mach.cpp compiler.cpp
    Total time: 318.350 millisecond
    Time outside of functions: 1.013 millisecond
    Call depth: 6
    Total functions: 40
    Total hits: 32290
    Function coverage: 85.0%
    Overhead Calculated 4
    Overhead Average 4

Module Statistics for d64.exe
-----------------------------
    Time in module: 317.337 millisecond
    Percent of time in module: 100.0%
    Functions in module: 40
    Hits in module: 32290
    Module function coverage: 85.0%

        Func          Func+Child           Hit
        Time   %         Time      %      Count  Function
---------------------------------------------------------
     192.316  60.6      192.316  60.6     1290 CString::Find(char const *,int) (mfc42d.dll)
      54.533  17.2       54.533  17.2     5279 CString::Insert(int,char) (mfc42d.dll)
      19.537   6.2       19.537   6.2        5 CFile::CFile(char const *,unsigned int) (mfc42d.dll)
      15.200   4.8       15.200   4.8       10 CFile::Close(void) (mfc42d.dll)
       6.574   2.1        6.574   2.1     1035 CString::Delete(int,int) (mfc42d.dll)
       5.031   1.6        5.031   1.6        5 CFile::Open(char const *,unsigned int,class CFileException *) (mfc42d.dll)
       4.987   1.6      261.826  82.5       85 substitute(class CString *,class CString *,class CString *) (substitute.obj)
       2.611   0.8        2.611   0.8    10309 CString::operator[](int) (mfc42d.dll)
       2.486   0.8        2.486   0.8        5 CStdioFile::CStdioFile(char const *,unsigned int) (mfc42d.dll)
       2.434   0.8        2.434   0.8     1130 CString::Insert(int,char const *) (mfc42d.dll)
       2.161   0.7        2.161   0.7     1411 CString::~CString(void) (mfc42d.dll)
       2.133   0.7        9.103   2.9      170 parse1(class CString *,int,class CString *) (substitute.obj)
       2.006   0.6        2.006   0.6     7449 CString::GetLength(void) (mfc42d.dll)
       1.233   0.4        1.233   0.4     1130 CString::CString(char,int) (mfc42d.dll)
       0.604   0.2        0.604   0.2     2270 CString::operator char const *(void) (mfc42d.dll)
       0.591   0.2        0.591   0.2       90 CStdioFile::ReadString(class CString &) (mfc42d.dll)
       0.566   0.2        0.566   0.2       11 CString::CString(char const *) (mfc42d.dll)
       0.452   0.1        0.452   0.1        5 CStdioFile::~CStdioFile(void) (mfc42d.dll)
       0.340   0.1        0.340   0.1        5 CFile::Read(void *,unsigned int) (mfc42d.dll)
       0.339   0.1        0.339   0.1        5 CFile::Write(void const *,unsigned int) (mfc42d.dll)
       0.281   0.1        0.281   0.1        5 operator new(unsigned int) (mfc42d.dll)
       0.274   0.1        0.274   0.1        5 CFile::SetLength(unsigned long) (mfc42d.dll)
       0.208   0.1      275.270  86.7        5 do_substitutions(class CString *,class CString *) (substitute.obj)
       0.078   0.0        0.078   0.0        5 operator delete(void *) (mfc42d.dll)
       0.068   0.0        0.068   0.0        5 CFile::GetLength(void) (mfc42d.dll)
       0.065   0.0        0.065   0.0      270 CString::CString(void) (mfc42d.dll)
       0.058   0.0        9.162   2.9       85 parse(class CString *,class CString *,class CString *) (substitute.obj)
       0.047   0.0        0.047   0.0      170 CString::Empty(void) (mfc42d.dll)
       0.043   0.0        0.043   0.0       10 AfxTryCleanup(void) (mfc42d.dll)
       0.042   0.0      317.285 100.0        5 process_file(class CString *,class CString *) (substitute.obj)
       0.019   0.0        0.019   0.0       10 AFX_EXCEPTION_LINK::AFX_EXCEPTION_LINK(void) (mfc42d.dll)
       0.008   0.0        0.051   0.0       10 AFX_EXCEPTION_LINK::~AFX_EXCEPTION_LINK(void) (substitute.obj)
       0.006   0.0        0.006   0.0        5 CFile::~CFile(void) (mfc42d.dll)
       0.006   0.0      317.337 100.0        1 _main (substitute.obj)




1. I observerd that the function substitute spend much time in the profiler. the function do_substitutions call substitue, and process_file calls do_substitutions, so they both spend much time.

2. So I think the bottlenecks is the funtion substitute. In substitute, the find function is called many times, but the location every time starts from the beginning, it's unnecessary. 



Profile: Function timing, sorted by time
Date:    Wed Nov 12 11:19:03 2008


Program Statistics
------------------
    Command line at 2008 Nov 12 11:19: "F:\d64\Debug\d64" replace.txt call.cpp semantics.cpp math.cpp mach.cpp compiler.cpp
    Total time: 139.337 millisecond
    Time outside of functions: 1.026 millisecond
    Call depth: 6
    Total functions: 40
    Total hits: 33325
    Function coverage: 85.0%
    Overhead Calculated 4
    Overhead Average 4

Module Statistics for d64.exe
-----------------------------
    Time in module: 138.311 millisecond
    Percent of time in module: 100.0%
    Functions in module: 40
    Hits in module: 33325
    Module function coverage: 85.0%

        Func          Func+Child           Hit
        Time   %         Time      %      Count  Function
---------------------------------------------------------
      45.273  32.7       45.273  32.7     5279 CString::Insert(int,char) (mfc42d.dll)
      38.725  28.0       38.725  28.0     1290 CString::Find(char const *,int) (mfc42d.dll)
      15.770  11.4       15.770  11.4       10 CFile::Close(void) (mfc42d.dll)
       6.875   5.0        6.875   5.0     1035 CString::Delete(int,int) (mfc42d.dll)
       5.639   4.1      100.528  72.7       85 substitute(class CString *,class CString *,class CString *) (substitute.obj)
       3.078   2.2        3.078   2.2        5 CStdioFile::CStdioFile(char const *,unsigned int) (mfc42d.dll)
       2.803   2.0        2.803   2.0    10309 CString::operator[](int) (mfc42d.dll)
       2.637   1.9        2.637   1.9        5 CFile::Open(char const *,unsigned int,class CFileException *) (mfc42d.dll)
       2.548   1.8        2.548   1.8     1130 CString::Insert(int,char const *) (mfc42d.dll)
       2.444   1.8        2.444   1.8        5 CFile::CFile(char const *,unsigned int) (mfc42d.dll)
       2.325   1.7        2.325   1.7     8484 CString::GetLength(void) (mfc42d.dll)
       2.252   1.6        2.252   1.6     1411 CString::~CString(void) (mfc42d.dll)
       2.212   1.6        9.355   6.8      170 parse1(class CString *,int,class CString *) (substitute.obj)
       1.381   1.0        1.381   1.0     1130 CString::CString(char,int) (mfc42d.dll)
       0.917   0.7        0.917   0.7       11 CString::CString(char const *) (mfc42d.dll)
       0.594   0.4        0.594   0.4       90 CStdioFile::ReadString(class CString &) (mfc42d.dll)
       0.498   0.4        0.498   0.4     2270 CString::operator char const *(void) (mfc42d.dll)
       0.444   0.3        0.444   0.3        5 CStdioFile::~CStdioFile(void) (mfc42d.dll)
       0.329   0.2        0.329   0.2        5 CFile::Write(void const *,unsigned int) (mfc42d.dll)
       0.327   0.2        0.327   0.2        5 CFile::Read(void *,unsigned int) (mfc42d.dll)
       0.324   0.2        0.324   0.2        5 operator new(unsigned int) (mfc42d.dll)
       0.268   0.2        0.268   0.2        5 CFile::SetLength(unsigned long) (mfc42d.dll)
       0.203   0.1      114.801  83.0        5 do_substitutions(class CString *,class CString *) (substitute.obj)
       0.086   0.1        0.086   0.1        5 operator delete(void *) (mfc42d.dll)
       0.068   0.0        0.068   0.0      270 CString::CString(void) (mfc42d.dll)
       0.062   0.0        0.062   0.0        5 CFile::GetLength(void) (mfc42d.dll)
       0.060   0.0        9.415   6.8       85 parse(class CString *,class CString *,class CString *) (substitute.obj)
       0.046   0.0        0.046   0.0      170 CString::Empty(void) (mfc42d.dll)
       0.043   0.0        0.043   0.0       10 AfxTryCleanup(void) (mfc42d.dll)
       0.038   0.0      138.259 100.0        5 process_file(class CString *,class CString *) (substitute.obj)
       0.018   0.0        0.018   0.0       10 AFX_EXCEPTION_LINK::AFX_EXCEPTION_LINK(void) (mfc42d.dll)
       0.011   0.0        0.054   0.0       10 AFX_EXCEPTION_LINK::~AFX_EXCEPTION_LINK(void) (substitute.obj)
       0.006   0.0        0.006   0.0        5 CFile::~CFile(void) (mfc42d.dll)
       0.005   0.0      138.311 100.0        1 _main (substitute.obj)





3. I take actions by change the find location to the just necessary part (newloc=loc-pattern->GetLength()+1)every time, then I observed that the function take much less time than ever before.

4. Since I have cut the time down a half more, and even I don't call the function, the time it spend can't be less.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -