|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Optimizing Performance help
I am looking to optimize this chunk of code. What it should do is trim anyMark W. Breneman 05/20/03 05:07 P <cfloop collection="#FORM#" item="idx">Bryan F. Hogan 05/20/03 05:09 P I don't think that will do what I am looking for.Mark W. Breneman 05/20/03 05:29 P > I am looking to optimize this chunk of code. What it shouldPhilip Arnold 05/20/03 05:39 P The cfset is where the trimming happens for all form values that do alreadyMark W. Breneman 05/20/03 05:50 P > The cfset is where the trimming happens for all form valuesPhilip Arnold 05/20/03 06:11 P <egg on red face> Yes, you are correct. That cfset should have had a Trim()Mark W. Breneman 05/20/03 06:29 P That is exactly the info I am looking for!Mark W. Breneman 05/20/03 06:10 P I am looking to optimize this chunk of code. What it should do is trim any leading or trailing spaces and to also define any form.vars that do not exist. i.e check boxes. I have optimized it as much as I know how. Can this be made faster or better? <cfloop index="i" list="Firstname,lastname, address1,etc...."> <!--- sets all blank raidio and check boxes to "" to prevent errors ---> <cfparam name="form.#Trim(i)#" default=""><CFSET "form.#Trim(i)#" = form[trim(i)]> </cfloop> Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 <cfloop collection="#FORM#" item="idx"> <cfset FORM['idx']=Trim(FORM['idx'])> </cfloop> I am looking to optimize this chunk of code. What it should do is trim any leading or trailing spaces and to also define any form.vars that do not exist. i.e check boxes. I have optimized it as much as I know how. Can this be made faster or better? <cfloop index="i" list="Firstname,lastname, address1,etc...."> <!--- sets all blank raidio and check boxes to "" to prevent errors ---> <cfparam name="form.#Trim(i)#" default=""><CFSET "form.#Trim(i)#" = form[trim(i)]> </cfloop> Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 I don't think that will do what I am looking for. I think what you are trying to show here is to loop through the form structure. This will not define a blank form.var for a radio button that was not selected on the "submitting page". But, this does make me wonder if setting the values in the structure would be faster then <CFSET "form.#Trim(i)#"... Any ideas? Thanks Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 <cfloop collection="#FORM#" item="idx"> <cfset FORM['idx']=Trim(FORM['idx'])> </cfloop> I am looking to optimize this chunk of code. What it should do is trim any leading or trailing spaces and to also define any form.vars that do not exist. i.e check boxes. I have optimized it as much as I know how. Can this be made faster or better? <cfloop index="i" list="Firstname,lastname, address1,etc...."> <!--- sets all blank raidio and check boxes to "" to prevent errors ---> <cfparam name="form.#Trim(i)#" default=""><CFSET "form.#Trim(i)#" = form[trim(i)]> </cfloop> Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 ----- Excess quoted text cut - see Original Post for more ----- Get rid of the list and convert it to an array, they're faster for loops That'll speed it up the longer the list it - loops over long lists are HORRIBLY slow Not to mention that that your CFSET does nothing really Oh, and since you're only making sure that the variables empty, don't use CFPARAM, it's slower than doing it by code Also, do it in CFSCRIPT HTH The cfset is where the trimming happens for all form values that do already exist. So, something like <cfif not StructKeyExists(form, i) ><CFSET "form.#Trim(i)#" = ""></cfif> is faster than <cfparam name="form.#Trim(i)#" default=""> ? CFscrip is the next step. Thanks Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 ----- Excess quoted text cut - see Original Post for more ----- Get rid of the list and convert it to an array, they're faster for loops That'll speed it up the longer the list it - loops over long lists are HORRIBLY slow Not to mention that that your CFSET does nothing really Oh, and since you're only making sure that the variables empty, don't use CFPARAM, it's slower than doing it by code Also, do it in CFSCRIPT HTH ----- Excess quoted text cut - see Original Post for more ----- Actually, the CFSET doesn't do that <CFSET "form.#Trim(i)#" = form[trim(i)]> There should be a Trim() outside of the form[] But putting it in CFSCRIPT should look like this; FieldArray=ListToArray("Firstname,lastname, address1,etc...."); For (i=1; I lte ArrayLen(FieldArray); i=i+1) { j=FieldArray[i]; if (not isDefined("form.#j#")) { form[j]=""; } form[j]=Trim(form[j]); } That should do it perfectly <egg on red face> Yes, you are correct. That cfset should have had a Trim() outside of the form[]. I missed that when I wrote the code for the email. That is very embarrassing! Sorry </egg on red face> CFscript... Thank you very much... I was not expecting (nor looking for) anyone to convert it to cfscrip for me. That was way beyond the "call of duty"... Thanks. Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 ----- Excess quoted text cut - see Original Post for more ----- Actually, the CFSET doesn't do that <CFSET "form.#Trim(i)#" = form[trim(i)]> There should be a Trim() outside of the form[] But putting it in CFSCRIPT should look like this; FieldArray=ListToArray("Firstname,lastname, address1,etc...."); For (i=1; I lte ArrayLen(FieldArray); i=i+1) { j=FieldArray[i]; if (not isDefined("form.#j#")) { form[j]=""; } form[j]=Trim(form[j]); } That should do it perfectly Just jumping on here, cfparam used on a large scale basis is as has been stated here, very slow. We had a client that CFPARAM'ed 100's of vars with every request and the slowdown in performance was pretty severe. Just my 2 cents (sorry pence <I came from England> [good job I did not say francs!];O) Kind Regards - Mike Brunt Original Message ----------------------- The cfset is where the trimming happens for all form values that do already exist. So, something like <cfif not StructKeyExists(form, i) ><CFSET "form.#Trim(i)#" = ""></cfif> is faster than <cfparam name="form.#Trim(i)#" default=""> ? CFscrip is the next step. Thanks Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 ----- Excess quoted text cut - see Original Post for more ----- Get rid of the list and convert it to an array, they're faster for loops That'll speed it up the longer the list it - loops over long lists are HORRIBLY slow Not to mention that that your CFSET does nothing really Oh, and since you're only making sure that the variables empty, don't use CFPARAM, it's slower than doing it by code Also, do it in CFSCRIPT HTH That is exactly the info I am looking for! The chunk of code that I have submitted is important to be optimized, but what I am really "fishing" for is info for how to optimize stuff like this. I deal with large forms on a daily basis and I have written several server side error checking and validation snippets that I use on every form. Now I am just trying to take these snippets to the next level and make them better. Thanks! Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 Just jumping on here, cfparam used on a large scale basis is as has been stated here, very slow. We had a client that CFPARAM'ed 100's of vars with every request and the slowdown in performance was pretty severe. Just my 2 cents (sorry pence <I came from England> [good job I did not say francs!];O) Kind Regards - Mike Brunt Original Message ----------------------- The cfset is where the trimming happens for all form values that do already exist. So, something like <cfif not StructKeyExists(form, i) ><CFSET "form.#Trim(i)#" = ""></cfif> is faster than <cfparam name="form.#Trim(i)#" default=""> ? CFscrip is the next step. Thanks Mark W. Breneman -Macromedia Certified ColdFusion Developer -Network / Web Server Administrator Vivid Media mark@vividmedia.com www.vividmedia.com 608.270.9770 ----- Excess quoted text cut - see Original Post for more ----- Get rid of the list and convert it to an array, they're faster for loops That'll speed it up the longer the list it - loops over long lists are HORRIBLY slow Not to mention that that your CFSET does nothing really Oh, and since you're only making sure that the variables empty, don't use CFPARAM, it's slower than doing it by code Also, do it in CFSCRIPT HTH
|
May 23, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||