Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvement to __trim__ #14

Open
chillitom opened this issue Aug 3, 2010 · 2 comments
Open

minor improvement to __trim__ #14

chillitom opened this issue Aug 3, 2010 · 2 comments

Comments

@chillitom
Copy link

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.

@thatcher
Copy link
Owner

thatcher commented Aug 4, 2010

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?

@chillitom
Copy link
Author

yip, sorry trim12, don't know how I drew that conclusion, it must have been late.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants