lr计算程序执行消耗时间的比较:

时间:2022-11-13 17:15:55

去除程序执行的两种方式:

1.通过一个事务:在需要消除的代码段,使用lr_wasted_time(wasteTime);

querySubmit()
{

	char newStr4[10000]="";

	int num4;//获取fid、roomid的个数
 

        double wasteTime,waste;  //定义变量

        merc_timer_handle_t timer;


	lr_vuser_status_message( "当前用户名:%s,迭代次数:%d",lr_eval_string("{fname}"),++iteration );


    
	lr_convert_string_encoding( lr_eval_string("{building}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时building是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
  
	lr_save_string( lr_eval_string("{UnicodeString}"),"building" );   //把UnicodeString参数的值又覆盖回building参数,前2步相当于完成了building参数的汉字到utf-8的转换

	web_convert_param("building","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把building参数从utf-8又转换到url编码
	
	lr_convert_string_encoding( lr_eval_string("{gardenid}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时gardenid是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中

        lr_save_string( lr_eval_string("{UnicodeString}"),"gardenid" );     //把UnicodeString参数的值又覆盖回gardenid参数,前2步相当于完成了gardenid参数的汉字到utf-8的转换
	
	web_convert_param("gardenid","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);   //这一步把gardenid参数从utf-8又转换到url编码

	lr_convert_string_encoding( lr_eval_string("{roomNo}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );   //此时roomNo是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
 
	lr_save_string( lr_eval_string("{UnicodeString}"),"roomNo" );    //把UnicodeString参数的值又覆盖回roomNo参数,前2步相当于完成了roomNo参数的汉字到utf-8的转换

	
	web_convert_param("roomNo","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把roomNo参数从utf-8又转换到url编码

//	lr_output_message("roomNo的Url编码=%s", lr_eval_string("{roomNo}"));


	web_set_max_html_param_len("1000000");   //设置关联参数接收最大的字节数


	web_reg_save_param_ex(
		"ParamName=fid4",
		"LB=id\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);

	web_reg_save_param_ex(
		"ParamName=roomid4",
		"LB=roomId\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);



	lr_rendezvous("设置提交集合点");
	
	lr_start_transaction("查询开始事务");

	web_custom_request("queryData_4",
		"URL=http://0755.qfang.com/qfang-broker/house/search/queryData",
		"Method=POST",
		"TargetFrame=",
		"Resource=0",
		"RecContentType=application/json",
		"Referer=http://0755.qfang.com/qfang-broker/house/search",
		"Snapshot=t33.inf",
		"Mode=HTML",
		"EncType=application/x-www-form-urlencoded; charset=UTF-8",
		"Body=houseState='RENT_SALE'%2C'RENT'%2C'SALE'%2C'OUTSIDE_SALED'%2C'COMPANY_SALED'%2C'OUTSIDE_RENTED'%2C'COMPANY_RENTED'%2C'STOP'%2C'DATA'&garden='{gardenid}'&building={building}&roomNo={roomNo}&crTypeValue=APARTMENT&subClassType='APARTMENT'&roomPattern='{roomPattern}'&permission=1&orgId={orgid}&searchPage=new&sqlQuery=false&curTab=ALL&changeSearchCondition=true",
		LAST);

	timer=lr_start_timer();   //timer开始:创建计时器,返回值是计时器标志,统计for循环花费的时间

	if (strcmp(lr_eval_string("{fid4}")," ")==0)
	{
//		lr_output_message("该条记录无法匹配到精确的楼盘信息!");

		strcpy(newStr4,"");

		lr_save_string( newStr4,"lastStr4" );

//		lr_output_message("newStr4的值:%s", newStr4);

	}
	else
	{
			for(num4 =1;num4<=atoi(lr_eval_string("{roomid4_count}"));num4++)

				{

					sprintf( fidVar4,"{fid4_%d}",num4 );   //将num变量保存到fidVar中,

					sprintf( fidValue4,"%s",lr_eval_string(fidVar4) );

					sprintf( roomidVar4,"{roomid4_%d}",num4 );  //将num变量保存到fidVar中,

					sprintf( roomidValue4,"%s",lr_eval_string(roomidVar4) );

					lr_output_message("fid4_%d的值:%s", num4, fidValue4);

					lr_output_message("roomid4_%d的值:%s", num4, roomidValue4);


					strcat( fidValue4,"_" );

					strcat( fidValue4,roomidValue4 );

//					lr_output_message("%s", fidValue4);

						if(num4 != atoi(lr_eval_string("{roomid4_count}")))

							{

								strcat( fidValue4,"," );

							}

							strcat( newStr4,fidValue4 );

				}


			lr_save_string( newStr4,"lastStr4" );


//			lr_output_message("newStr4的值:%s", newStr4);

//			lr_output_message("拼接后的整体字符串lastStr4的值:%s", lr_eval_string("{lastStr4}"));
 
 

	}

  waste = lr_end_timer(timer);  //停止timer

wasteTime=waste * 1000; 

lr_wasted_time(wasteTime); web_submit_data("getNewFollows_4", "Action=http://0755.qfang.com/qfang-broker/house/follow/getNewFollows", "Method=POST", "TargetFrame=", "RecContentType=application/json", "Referer=http://0755.qfang.com/qfang-broker/house/search", "Snapshot=t34.inf", "Mode=HTML", ITEMDATA, "Name=roomIds", "Value={lastStr4}", ENDITEM, LAST); lr_end_transaction("查询开始事务", LR_AUTO); return 0; }

 

方案二:通过在父事务中插入两个子事务

querySubmit()
{

	char newStr4[10000]="";

	int num4;//获取fid、roomid的个数
 

	lr_vuser_status_message( "当前用户名:%s,迭代次数:%d",lr_eval_string("{fname}"),++iteration );

    
	lr_convert_string_encoding( lr_eval_string("{building}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时building是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
  
	lr_save_string( lr_eval_string("{UnicodeString}"),"building" );   //把UnicodeString参数的值又覆盖回building参数,前2步相当于完成了building参数的汉字到utf-8的转换

	web_convert_param("building","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把building参数从utf-8又转换到url编码

	
	lr_convert_string_encoding( lr_eval_string("{gardenid}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时gardenid是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中

    lr_save_string( lr_eval_string("{UnicodeString}"),"gardenid" );     //把UnicodeString参数的值又覆盖回gardenid参数,前2步相当于完成了gardenid参数的汉字到utf-8的转换
	
	web_convert_param("gardenid","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);   //这一步把gardenid参数从utf-8又转换到url编码




	lr_convert_string_encoding( lr_eval_string("{roomNo}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );   //此时roomNo是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
 
	lr_save_string( lr_eval_string("{UnicodeString}"),"roomNo" );    //把UnicodeString参数的值又覆盖回roomNo参数,前2步相当于完成了roomNo参数的汉字到utf-8的转换

	
	web_convert_param("roomNo","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把roomNo参数从utf-8又转换到url编码





	web_set_max_html_param_len("1000000");   //设置关联参数接收最大的字节数


	web_reg_save_param_ex(
		"ParamName=fid4",
		"LB=id\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);


	web_reg_save_param_ex(
		"ParamName=roomid4",
		"LB=roomId\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);


//	lr_think_time(16);

	lr_rendezvous("设置提交集合点");
	

	lr_start_transaction("查询开始事务");


	    lr_start_sub_transaction("queryDate","查询开始事务");

	web_custom_request("queryData_4",
		"URL=http://0755.qfang.com/qfang-broker/house/search/queryData",
		"Method=POST",
		"TargetFrame=",
		"Resource=0",
		"RecContentType=application/json",
		"Referer=http://0755.qfang.com/qfang-broker/house/search",
		"Snapshot=t33.inf",
		"Mode=HTML",
		"EncType=application/x-www-form-urlencoded; charset=UTF-8",
		"Body=houseState='RENT_SALE'%2C'RENT'%2C'SALE'%2C'OUTSIDE_SALED'%2C'COMPANY_SALED'%2C'OUTSIDE_RENTED'%2C'COMPANY_RENTED'%2C'STOP'%2C'DATA'&garden='{gardenid}'&building={building}&roomNo={roomNo}&crTypeValue=APARTMENT&subClassType='APARTMENT'&roomPattern='{roomPattern}'&permission=1&orgId={orgid}&searchPage=new&sqlQuery=false&curTab=ALL&changeSearchCondition=true",
		LAST);

		lr_end_sub_transaction("queryDate",LR_AUTO);



	if (strcmp(lr_eval_string("{fid4}")," ")==0)
	{
//		lr_output_message("该条记录无法匹配到精确的楼盘信息!");

		strcpy(newStr4,"");

		lr_save_string( newStr4,"lastStr4" );


	}
	else
	{
			for(num4 =1;num4<=atoi(lr_eval_string("{roomid4_count}"));num4++)

				{

					sprintf( fidVar4,"{fid4_%d}",num4 );   //将num变量保存到fidVar中,

					sprintf( fidValue4,"%s",lr_eval_string(fidVar4) );

					sprintf( roomidVar4,"{roomid4_%d}",num4 );  //将num变量保存到fidVar中,

					sprintf( roomidValue4,"%s",lr_eval_string(roomidVar4) );

					lr_output_message("fid4_%d的值:%s", num4, fidValue4);

					lr_output_message("roomid4_%d的值:%s", num4, roomidValue4);


					strcat( fidValue4,"_" );

					strcat( fidValue4,roomidValue4 );


						if(num4 != atoi(lr_eval_string("{roomid4_count}")))

							{

								strcat( fidValue4,"," );

							}

							strcat( newStr4,fidValue4 );

				}


			lr_save_string( newStr4,"lastStr4" );
 

	}



		lr_start_sub_transaction("getNewFollows","查询开始事务");

	web_submit_data("getNewFollows_4",
		"Action=http://0755.qfang.com/qfang-broker/house/follow/getNewFollows",
		"Method=POST",
		"TargetFrame=",
		"RecContentType=application/json",
		"Referer=http://0755.qfang.com/qfang-broker/house/search",
		"Snapshot=t34.inf",
		"Mode=HTML",
		ITEMDATA,
		"Name=roomIds", "Value={lastStr4}", ENDITEM,
		LAST);

		lr_end_sub_transaction("getNewFollows",LR_AUTO);




	lr_end_transaction("查询开始事务", LR_AUTO);


	return 0;


}

 lr计算程序执行消耗时间的比较:

 

方法三:不添加任何消除时间方法:

querySubmit()
{

	char newStr4[10000]="";

	int num4;//获取fid、roomid的个数
 

	lr_vuser_status_message( "当前用户名:%s,迭代次数:%d",lr_eval_string("{fname}"),++iteration );

    
	lr_convert_string_encoding( lr_eval_string("{building}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时building是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
  
	lr_save_string( lr_eval_string("{UnicodeString}"),"building" );   //把UnicodeString参数的值又覆盖回building参数,前2步相当于完成了building参数的汉字到utf-8的转换

	web_convert_param("building","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把building参数从utf-8又转换到url编码

	
	lr_convert_string_encoding( lr_eval_string("{gardenid}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );  //此时gardenid是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中

    lr_save_string( lr_eval_string("{UnicodeString}"),"gardenid" );     //把UnicodeString参数的值又覆盖回gardenid参数,前2步相当于完成了gardenid参数的汉字到utf-8的转换
	
	web_convert_param("gardenid","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);   //这一步把gardenid参数从utf-8又转换到url编码




	lr_convert_string_encoding( lr_eval_string("{roomNo}"),LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"UnicodeString" );   //此时roomNo是一个汉字列表的参数,把它转换为utf-8,存入UnicodeString参数中
 
	lr_save_string( lr_eval_string("{UnicodeString}"),"roomNo" );    //把UnicodeString参数的值又覆盖回roomNo参数,前2步相当于完成了roomNo参数的汉字到utf-8的转换

	
	web_convert_param("roomNo","SourceEncoding=PLAIN","TargetEncoding=URL",LAST);  //这一步把roomNo参数从utf-8又转换到url编码





	web_set_max_html_param_len("1000000");   //设置关联参数接收最大的字节数


	web_reg_save_param_ex(
		"ParamName=fid4",
		"LB=id\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);


	web_reg_save_param_ex(
		"ParamName=roomid4",
		"LB=roomId\":\"",
		"RB=\",",
		"NotFound=warning",
		"Ordinal=All",
		SEARCH_FILTERS,
		"Scope=Body",
		"RequestUrl=*/queryData*",
		LAST);


//	lr_think_time(16);

	lr_rendezvous("设置提交集合点");
	

	lr_start_transaction("查询开始事务");


	web_custom_request("queryData_4",
		"URL=http://0755.qfang.com/qfang-broker/house/search/queryData",
		"Method=POST",
		"TargetFrame=",
		"Resource=0",
		"RecContentType=application/json",
		"Referer=http://0755.qfang.com/qfang-broker/house/search",
		"Snapshot=t33.inf",
		"Mode=HTML",
		"EncType=application/x-www-form-urlencoded; charset=UTF-8",
		"Body=houseState='RENT_SALE'%2C'RENT'%2C'SALE'%2C'OUTSIDE_SALED'%2C'COMPANY_SALED'%2C'OUTSIDE_RENTED'%2C'COMPANY_RENTED'%2C'STOP'%2C'DATA'&garden='{gardenid}'&building={building}&roomNo={roomNo}&crTypeValue=APARTMENT&subClassType='APARTMENT'&roomPattern='{roomPattern}'&permission=1&orgId={orgid}&searchPage=new&sqlQuery=false&curTab=ALL&changeSearchCondition=true",
		LAST);


	if (strcmp(lr_eval_string("{fid4}")," ")==0)
	{
//		lr_output_message("该条记录无法匹配到精确的楼盘信息!");

		strcpy(newStr4,"");

		lr_save_string( newStr4,"lastStr4" );


	}
	else
	{
			for(num4 =1;num4<=atoi(lr_eval_string("{roomid4_count}"));num4++)

				{

					sprintf( fidVar4,"{fid4_%d}",num4 );   //将num变量保存到fidVar中,

					sprintf( fidValue4,"%s",lr_eval_string(fidVar4) );

					sprintf( roomidVar4,"{roomid4_%d}",num4 );  //将num变量保存到fidVar中,

					sprintf( roomidValue4,"%s",lr_eval_string(roomidVar4) );

					lr_output_message("fid4_%d的值:%s", num4, fidValue4);

					lr_output_message("roomid4_%d的值:%s", num4, roomidValue4);


					strcat( fidValue4,"_" );

					strcat( fidValue4,roomidValue4 );


						if(num4 != atoi(lr_eval_string("{roomid4_count}")))

							{

								strcat( fidValue4,"," );

							}

							strcat( newStr4,fidValue4 );

				}


			lr_save_string( newStr4,"lastStr4" );
 

	}



	web_submit_data("getNewFollows_4",
		"Action=http://0755.qfang.com/qfang-broker/house/follow/getNewFollows",
		"Method=POST",
		"TargetFrame=",
		"RecContentType=application/json",
		"Referer=http://0755.qfang.com/qfang-broker/house/search",
		"Snapshot=t34.inf",
		"Mode=HTML",
		ITEMDATA,
		"Name=roomIds", "Value={lastStr4}", ENDITEM,
		LAST);



	lr_end_transaction("查询开始事务", LR_AUTO);


	return 0;


}

 lr计算程序执行消耗时间的比较: