env-js
env-js copied to clipboard
minor improvement to __trim__
i've benchmarked a bunch of trim methods on Rhino by pointing Env.JS at http://stevenlevithan.com/demo/trim.cfm
C:\Documents and Settings\user\My Documents\Downloads\rhino1_7R2>java -jar js.jar -opt -1 Rhino 1.7 release 2 2009 03 22 js> load('env.rhino.1.2.js') [ Envjs/1.6 (Rhino; U; Windows XP x86 5.1; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13 ] js> Envjs.scriptTypes['text/javascript'] = true; true js> window.location='http://stevenlevithan.com/demo/trim.cfm' http://stevenlevithan.com/demo/trim.cfm js> $('times').value = 200 200 js> benchmark(); js> $('log').innerHTML Original length: 27663 trim1: 422ms (length: 27656) trim2: 797ms (length: 27656) trim3: 828ms (length: 27656) trim4: 1156ms (length: 27656) trim5: 1469ms (length: 27656) trim6: 3922ms (length: 27656) trim7: 3656ms (length: 27656) trim8: 2079ms (length: 27656) trim9: 5969ms (length: 27656) trim10: 0ms (length: 27656) trim11: 32ms (length: 27656) trim12: 32ms (length: 27656)
but for smaller strings i get
Original length: 55 trim1: 16ms (length: 49) trim2: 15ms (length: 49) trim3: 31ms (length: 49) trim4: 31ms (length: 49) trim5: 31ms (length: 49) trim6: 78ms (length: 49) trim7: 78ms (length: 49) trim8: 47ms (length: 49) trim9: 172ms (length: 49) trim10: 62ms (length: 49) trim11: 31ms (length: 49) trim12: 15ms (length: 49)
trim1 seems to take half the time of the current trim method (trim4), might be an idea to switch to this one.
thanks for the insight... without having looked at the benchmark harness, and only relying on the numbers, why wouldn't I use trim12 instead of trim4?
yip, sorry trim12, don't know how I drew that conclusion, it must have been late.