View Single Post
Old 11-25-2003, 11:59 PM   PM User | #21
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Yah, I know it's sneaky. It's one of the tricks I thought of when I read through the JavaScript and ECMAScript specs recently, and this is the first time I've got to put it to use. Try it: <javascript:alert(Number(Boolean(2)));void(0);>

Oh, just wondering - what might be fastest:
Code:
(( Math.floor((n%100)/10) == 1)
With one scope jump, one property lookup, one function call, one remainder, one division and one comparison, or
Code:
( this % 100 - nModTen != 10 ) * nModeTen
With one remainder, one subtraction, one comparison, one autocasting, and one multiplication.

I believe your code would win out, in those cases. (The access part (scope jump and property lookup) should be fast compared to my math, and the function call and the autocast should both be almost unnoticable) However, my single comparison should make my code faster in the cases of 'th', when I won't have to perform all those numerical operations. So, how would they compare for many numbers, performance wise?
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

Last edited by liorean; 11-26-2003 at 12:08 AM..
liorean is offline   Reply With Quote