Compare Execution Time experiments
Machine Spec: CPU model: Intel Core i7-366u;
CPU Frequency: 2.0 GHz (Max Turbo: 3.2GHZ);
Number of cores: Dual core, number of threads: four threads;
RAM:8GB;
Number of operating system bits: 64 bits.
Write the following code in VS:
#include"stdafx.h"#include"iostream"#include"windows.h"#include"time.h"using namespacestd;intsrc[2048][2048];intdst[2048][2048]; SYSTEMTIME Lpsystime;voidCopyij (intsrc[2048][2048],intdst[2048][2048]);voidCopyji (intsrc[2048][2048],intdst[2048][2048]);voidprinttime ();int_tmain (intARGC, _tchar*argv[]) {printtime (); Copyij (SRC,DST); Printtime (); Copyji (SRC, DST); Printtime (); return 0;}voidCopyij (intsrc[2048][2048],intdst[2048][2048]){ intI, J; for(i =0; I <2048; i++) for(j =0; J <2048; J + +) Dst[i][j]=src[i][j];}voidCopyji (intsrc[2048][2048],intdst[2048][2048]){ intI, J; for(j =0; J <2048; J + +) for(i =0; I <2048; i++) Dst[i][j]=src[i][j];}voidPrinttime () {Getlocaltime (&lpsystime); printf ("%u:%u:%u:%u\n", Lpsystime.whour, Lpsystime.wminute, Lpsystime.wsecond, lpsystime.wmilliseconds);}
The results of the operation are as follows:
Analysis:
From the result we can calculate: run I after the time of running J is 16 milliseconds, first run J after the time of running I is 203 milliseconds difference of more than 12 times times. This is mainly because each line I is running after I run J is in the tell cache, the read can be processed quickly, and if you run J and then run I, you need to store one item per processing to the cache, which greatly increases the processing time of the program, resulting in the above results.
Liam's group learning process (ii): Comparing program operation time (2015.10.20)