c# - one of my methods has completely different execution time for same input -


i have web service should return answer in less 10 milliseconds. have many validation process including mobile number validation. every thing works fine mobile number validation execution time different!! returns in less millisecond , 2 seconds!! please take @ part of log file:(same entry in different times)

[info ];[2015-08-25 9:51:09,073];[11];[intermediate_mobile.mobilecontentvalidator];[1800.2534 ms] [info ];[2015-08-25 10:47:53,636];[5];[intermediate_mobile.mobilecontentvalidator];[5.4598 ms] [info ];[2015-08-25 10:51:09,073];[38];[intermediate_mobile.mobilecontentvalidator];[0.1379 ms] [info ];[2015-08-25 11:12:09,073];[45];[intermediate_mobile.mobilecontentvalidator];[1780.4578 ms] 

and here method:

public bool mobilecontentvalidator() {     regex len = new regex(@"^.{2,20}$"); //length @ least 6 characters , maximum of 20     regex number = new regex(@"^[0-9]*$"); //a string consisting of numbers      phonenumber mobile;     stopwatch sw = new stopwatch();     phonenumberutil phoneutil = phonenumberutil.getinstance();     sw.start();      try     {         if (!len.ismatch(this.number))         {             this.isnumbervalid = false;             this.userreason = tools_messageaccess.getbriefmessage("user", "mc0001");             this.logreason = tools_messageaccess.getbriefmessage("log", "mc0001");         }         else if (!number.ismatch(this.number))         {             this.isnumbervalid = false;             this.userreason = tools_messageaccess.getbriefmessage("user", "mc0001");             this.logreason = tools_messageaccess.getbriefmessage("log", "mc0001");         }         else if (this.region != "ir")         {             this.isnumbervalid = false;             this.userreason = tools_messageaccess.getbriefmessage("user", "mb0003");             this.logreason = tools_messageaccess.getbriefmessage("user", "mb0003");         }         else         {             mobile = phoneutil.parse(this.number, this.region);             if (phoneutil.isvalidnumber(mobile) != true)             {                 this.isnumbervalid = false;                 this.userreason = tools_messageaccess.getbriefmessage("user", "mc0001");                 this.logreason = tools_messageaccess.getbriefmessage("log", "mc0001");             }             else if (phoneutil.getnumbertype(mobile).tostring() != "mobile")             {                 this.isnumbervalid = false;                 this.userreason = tools_messageaccess.getbriefmessage("user", "mu0001");                 this.logreason = tools_messageaccess.getbriefmessage("log", "mu0001");             }             else                 this.isnumbervalid = true;         }          sw.stop();         tools_log.getlogger().info(tools_log.messageforlogfile("mobile content validation completed successfully. ", "", sw.elapsed.totalmilliseconds));         return true;     }     catch (exception ex)     {         this.userreason = tools_messageaccess.getbriefmessage("user", "g00001");         this.logreason = ex.tostring();         tools_log.getlogger().error(tools_log.messageforlogfile("mobile content validation failed due exception in application. ", ex.tostring(), sw.elapsed.totalmilliseconds));         return false;     } } 

i know googles libphonenumber library little heavy don't know why took long returns answer. said have many validation process , 1 act strange. thanks.

update#1: thought question clear. bad. sorry that. question why execution time different , how can fix it? mean did make mistake in writing method?

update#2: more logs:

[info ];[2015-08-25 12:03:33,793];[14];[intermediate_mobile.convertnumber];[0.3712];[];[(message: converting mobile number completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:33,794];[14];[intermediate_mobile.mobilecontentvalidator];[2100.12];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:33,797];[14];[intermediate_mobile.mobilecontentvalidator];[0.0761];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:33,797];[14];[intermediate_mobile.convertnumber];[0.3456];[];[(message: converting mobile number completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:37,395];[14];[intermediate_mobile.convertnumber];[0.3452];[];[(message: converting mobile number completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:37,395];[14];[intermediate_mobile.mobilecontentvalidator];[0.0496];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:37,398];[14];[intermediate_mobile.mobilecontentvalidator];[0.0752];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:37,399];[14];[intermediate_mobile.convertnumber];[0.3593];[];[(message: converting mobile number completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:38,518];[11];[intermediate_mobile.mobilecontentvalidator];[0.0768];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:38,518];[11];[intermediate_mobile.convertnumber];[0.3776];[];[(message: converting mobile number completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:38,518];[11];[intermediate_mobile.mobilecontentvalidator];[0.0492];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:38,521];[11];[intermediate_mobile.mobilecontentvalidator];[0.0966];[];[(message: mobile content validation completed successfully. )(exeption: )] [info ];[2015-08-25 12:03:38,521];[11];[intermediate_mobile.convertnumber];[0.383];[];[(message: converting mobile number completed successfully. )(exeption: )] 

your updated log shows there 2 second load time once. (kind of) normal if use (larger) external library, needs load assemblies when called first time. should not see such delay in following calls same input (and hence same control flow through library)


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -