Liam's group learning process (ii): Comparing program operation time (2015.10.20)

Source: Internet
Author: User
Tags intel core i7

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.