[Prototype-core] Re: iterable/$A
I didn't understand why don't use Array.prototype.slice from here http://www.danwebb.net/2006/11/7/a-low-down-dirty-goblin-of-a-hack ? It was working well when I tested with my app ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
You're getting conflicting results there with an array of length == 10. Any idea why that is ? On Sep 2, 5:58 am, Robert Katić [EMAIL PROTECTED] wrote: In Opera I was able to perform similar timing with much more repetitions. Conclusion: 'init' function is double faster then 'push' function On Sep 2, 5:16 am, Robert Katić [EMAIL PROTECTED] wrote: I wrote small profilehttp://pastie.textmate.org/93190thatI paste on firebug. This is results on my laptop: Size: 100 Times: 1 push: 4672ms init: 2922ms Size: 10 Times: 1 push: 266ms init: 594ms Size: 4 Times: 1 push: 141ms init: 79ms On Sep 2, 4:31 am, Tobie Langel [EMAIL PROTECTED] wrote: Can we have benchmarks ? On Sep 1, 7:32 pm, Robert Katić [EMAIL PROTECTED] wrote: I have another question about $A and similar. Why you prefer do this var results = []; for (var i = 0, length = iterable.length; i length; i++) results.push(iterable[i]); instead of var length = iterable.length, results = new Array(length); for (var i = 0; i length; i++) results[i] = iterable[i]; It's more faster! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
I have another question about $A and similar. Why you prefer do this var results = []; for (var i = 0, length = iterable.length; i length; i++) results.push(iterable[i]); instead of var length = iterable.length, results = new Array(length); for (var i = 0; i length; i++) results[i] = iterable[i]; It's more faster! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
Can we have benchmarks ? On Sep 1, 7:32 pm, Robert Katić [EMAIL PROTECTED] wrote: I have another question about $A and similar. Why you prefer do this var results = []; for (var i = 0, length = iterable.length; i length; i++) results.push(iterable[i]); instead of var length = iterable.length, results = new Array(length); for (var i = 0; i length; i++) results[i] = iterable[i]; It's more faster! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
I wrote small profile http://pastie.textmate.org/93190 that I paste on firebug. This is results on my laptop: Size: 100 Times: 1 push: 4672ms init: 2922ms Size: 10 Times: 1 push: 266ms init: 594ms Size: 4 Times: 1 push: 141ms init: 79ms On Sep 2, 4:31 am, Tobie Langel [EMAIL PROTECTED] wrote: Can we have benchmarks ? On Sep 1, 7:32 pm, Robert Katić [EMAIL PROTECTED] wrote: I have another question about $A and similar. Why you prefer do this var results = []; for (var i = 0, length = iterable.length; i length; i++) results.push(iterable[i]); instead of var length = iterable.length, results = new Array(length); for (var i = 0; i length; i++) results[i] = iterable[i]; It's more faster! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
On 8/31/07, Nicolás Sanguinetti [EMAIL PROTECTED] wrote: As discussed in http://redhanded.hobix.com/inspect/showingPerfectTime.html String.prototype.replace with a callback is broken in Safari (at least up until v2). Ah yes, the Safari issue. Why not simply do : var $A = Prototype.Browser.WebKit ? Array.from : Array.slice TAG, nice catch. I would have never thought of that just by looking at it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
On 8/31/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: newArray = Array.slice( arguments ); Yeah, this is known to us for some time. I've spent some time getting rid of all the $A calls internal to Prototype (they're everywhere!) and replacing them with Array.prototype.slice calls, but I never get around of finishing that. I will, though, before 1.6.0 final. The thing is, I can't suggest this change to the Prototype team unless I actually benchmark the performance. also, for generating unique arrays: function uniqueArray( array ){ var uniqueHash = {}, unique=[], i; for( i=array.length; i--; ){ if( !uniqueHash[ a[i] ]){ unique.push( array[i] ); uniqueHash[ a[i] ] = true; } } return unique; } This is a very nice hack! I'll benchmark that also. and is there any reason not to use String.replace([regexp], function() {} ) for a large part of the functions implemented by iterating through arrays? this can be blazingly fast even for complicated regex as long as they are precompiled, and the code is far more readable and compact (i.e. camelization, templating, etc etc ) Nothing prevents you from submitting patches. We will welcome optimizations for camelization, templating and related stuff. and --- a big kudos to the prototype team -- discovering prototype way back when completely changed the way i code javascript - thanks. Discovering Prototype taught me JavaScript, also. Probably because it didn't have any documentation back then :) Thanks for the suggestions. As I've already said: focus on the string stuff and see if you can get a performance boost. Camelization, for instance, was a bottleneck in setStyle :( --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
On Aug 30, 2007, at 5:52 PM, Mislav Marohnić wrote: On 8/31/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: also, for generating unique arrays: function uniqueArray( array ){ var uniqueHash = {}, unique=[], i; for( i=array.length; i--; ){ if( !uniqueHash[ a[i] ]){ unique.push( array[i] ); uniqueHash[ a[i] ] = true; } } return unique; } Although I expect this to be faster (linear time), this produces incorrect results for certain arrays due to the implicit toString(). Arrays of DOM elements might not be properly uniq-ed, for example. The same is true for the following array (which uniq() handles properly): var a = [true, true]; console.log( a.uniq() ); // [true, true] console.log( uniqueArray(a) ); // [true] TAG --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
On 8/31/07, Nicolás Sanguinetti [EMAIL PROTECTED] wrote: As discussed in http://redhanded.hobix.com/inspect/showingPerfectTime.html String.prototype.replace with a callback is broken in Safari (at least up until v2). Ah yes, the Safari issue. TAG, nice catch. I would have never thought of that just by looking at it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: iterable/$A
Not only that, but if the array contains objects, the toString() method on the Object prototype will cause all but one object to be removed from the array, because all objects without an overridden toString() method report [object]. On Aug 30, 2007, at 5:50 PM, Tom Gregory wrote: On Aug 30, 2007, at 5:52 PM, Mislav Marohnić wrote: On 8/31/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: also, for generating unique arrays: function uniqueArray( array ){ var uniqueHash = {}, unique=[], i; for( i=array.length; i--; ){ if( !uniqueHash[ a[i] ]){ unique.push( array[i] ); uniqueHash[ a[i] ] = true; } } return unique; } Although I expect this to be faster (linear time), this produces incorrect results for certain arrays due to the implicit toString (). Arrays of DOM elements might not be properly uniq-ed, for example. The same is true for the following array (which uniq() handles properly): var a = [true, true]; console.log( a.uniq() ); // [true, true] console.log( uniqueArray(a) ); // [true] TAG --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---