Analysis of memory memcpy efficiency test based on C + + _c language

Source: Internet
Author: User

In the memcpy operation, although it is a memory operation, but still consumes a little CPU, today tested a single thread to perform the memcpy efficiency, this result for the configuration of TCP Epoll work thread

Quantity is instructive. The following 8K-based memory fast execution memcpy, 1 threads about 1S can copy 500M, if the server bandwidth or network card to the upper limit is 1G, then network IO work thread open 2, considering the resolution of the message loss, 3 threads enough to withstand the highest hardware load.

Before I went to the test machine, the test results were:

Intel (R) Xeon (r) CPU E5405 @ 2.00GHz

Do memcpy speed:12.27 MS/MB
Each thread can do memcpy 667.645 MB

Copy Code code as follows:

#include <iostream>
#include <sys/time.h>
#include <string.h>

using namespace Std;

int main (int argc, char* argv[])
{
Long len = 8192;
int loop = 200;
char* p = new Char[len];
char* q = p;
struct timeval start, end;
Gettimeofday (&start, NULL);
for (int i =0; i < loop; ++i)
{
char* p = new Char[len];
*p = char (i);
memcpy (P, Q, Len);
delete [] p;
}
Gettimeofday (&end, NULL);
cout << "Do memcpy Speed:" << (end.tv_sec-start.tv_sec) *1000 + double (end.tv_usec-start.tv_usec)/(Len*lo op/1000/1000))/loop<< "ms/mb\n";
cout << "Each thread can do memcpy" << double (len) *loop/1000/1000/(END.TV_SEC-START.TV_SEC) + double (end.t V_USEC-START.TV_USEC)/1000/1000) << "mb\n";

}

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.