lr計算程式執行消耗時間的比較:

weixin_33831673發表於2015-05-20

去除程式執行的兩種方式:

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;


}

 

 

方法三:不新增任何消除時間方法:

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;


}

 

 

相關文章