C ++ embedded assembly and speed Testing

Source: Internet
Author: User

By the way, Consortium compiled a strcpy. Let's take an example and test the speed ..

Char * strcpy (char * des, const char * SRC, unsigned _ int32 count)
{
If (des = NULL)
{
Return 0;
}

If (src = NULL)
{
Des [0] = 0;
Return des;
}

_ ASM
{
MoV EDI, des
MoV ESI, SRC
MoV ECx, count
Dec ECx

_ Loop:
CMP byte PTR [esi], 0
JZ _ break
Movsb
Loop _ Loop

_ Break:
MoV byte PTR [EDI], 0
MoV eax, des
}
}

Int main ()
{
Byte bytype = 2;
Char des [10] = {0 };
Char * src = "masefee ";

Large_integer itemp;
Longlong lltime1, lltime2;
Double dtime;
Queryperformancefrequency (& itemp );
Queryperformancecounter (& itemp );
Lltime1 = itemp. quadpart;

Strcpy (DES, SRC, 8 );

Queryperformancecounter (& itemp );
Lltime2 = itemp. quadpart;
Dtime = (double) (lltime2-lltime1 );

Printf ("% F/N", dtime );

Return 0;
}

 

Output: 1210.000000

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.