inline void CollectChar(char* _comSQL, const char *_pcAccounts, const char *_pcIP)
{
/*
char buff[128];
_comSQL+=strlen(_comSQL);
memset(buff, 0, sizeof(buff));
sprintf(buff, " onrecv_account_logon('%s','%s'); ", _pcAccounts, _pcIP);
strcpy(_comSQL, buff);
*/
char buff[128];
char *pbuff = buff;
char *str1=" onrecv_account_logon('";
char *str2="','";
char *str3="'); ";
_comSQL+=strlen(_comSQL);
memset(buff, 0, sizeof(buff));
//sprintf(buff, " onrecv_account_logon('%s','%s'); ", _pcAccounts, _pcIP);
--pbuff, --str1;
while(*++pbuff = *++str1);
--pbuff, --_pcAccounts;
while(*++pbuff = *++_pcAccounts);
--pbuff, --str2;
while(*++pbuff = *++str2);
--pbuff, --_pcIP;
while(*++pbuff = *++_pcIP);
--pbuff, --str3;
while(*++pbuff = *++str3);
strcpy(_comSQL, buff);
}
/**/地方是我原先的函数,在本机上测试,100万的循环耗费40秒左右,改为while形式后,只需10-12秒左右
记录如下
最早用sprintf ,耗时为N
改为strcpy,耗时为N/2
改为while(*des++=*src++),性能提升为 (n/2)*20%
改为后缀的加,再次提升5%
改为inline,再次提升5%