During the memcpy operation, although it is a memory operation, it still consumes a little CPU. Today we tested the efficiency of executing memcpy in a single thread. The result is for configuring the work thread in TCP epoll.
The quantity has guiding significance. The following example shows how to execute memcpy quickly based on 8 K memory. One thread can copy 500 M in about 1 second. If the server bandwidth or network card reach the upper limit of 1 GB, the network I/O work thread can be opened with two threads. Considering the message parsing loss, the three threads are sufficient to resist the maximum Hardware load.
The test result is as follows:
Intel (R) Xeon (R) CPU E5405 @ 2.00 GHz
Do memcpy speed: 12.27 MS/MB
Each threads can do memcpy 667.645 MB
Copy codeThe Code is 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 * loop/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. TV _usec-start. TV _usec)/1000/1000) <"MB \ n ";
}