> About that optimization you suggested:
>
> 34 for (var i = 0; i < len && eq; i++) {
> 35 eq = eq && equiv(a[i], b[i]);
> 36 }
> 37 return eq;
>
> don't forget that the "guard" operator (e.g. &&) will prevent calling
> equiv if eq is false.
thats true, the equiv is not called anymore, but you although have to
iterate over the whole array...
the code i proposed stops looping when there's a difference found..
nevertheless, a benchmark could prove if it is a improvement or not..
(and definitly it will only be faster when there is some inequality..)
another benefit of my code is, that it is easier to read in my
opinion
On 21 Okt., 21:51, Philippe Rathe <[EMAIL PROTECTED]> wrote:
> in reply to the article athttp://philrathe.com/articles/equiv:
>
> About that optimization you suggested:
>
> 34 for (var i = 0; i < len && eq; i++) {
> 35 eq = eq && equiv(a[i], b[i]);
> 36 }
> 37 return eq;
>
> don't forget that the "guard" operator (e.g. &&) will prevent calling
> equiv if eq is false.
>
> I've already thought about that optimization (e.g. checking for the
> value of eq in the for condition) but I've figured out
> that for test suites writing, usually you expected your actual and
> expected to be equals. And the for loop has been code
> in that philosophy, optimized for equlity.
>
> And because of that your optimization will be slower when comparing
> equivalent "values".
>
> It is hard to say if it is really an optimization. May when using
> equiv outside test suites purpose that
> optimization could be honored.
>
> Continue reading your replies...
>
> Regards,
> Philippe Rathe
>
> On 21-Oct-08, at 12:02 PM, markus.staab wrote:
>
>
>
> > in reply to the article athttp://philrathe.com/articles/equiv:
>
> > in the equiv method there is several times a loop like
>
> > 34 for (var i = 0; i < len; i++) {
> > 35 eq = eq && equiv(a[i], b[i]);
> > 36 }
> > 37 return eq;
>
> > this could be optimized, because if one of the elements is not equal,
> > you found, that the origin elements aren't equal..
>
> > so better use
>
> > 34 for (var i = 0; i < len && eq; i++) {
> > 35 eq = eq && equiv(a[i], b[i]);
> > 36 }
> > 37 return eq;
>
> > see the additional abort condition in the for loop...
> > This little "trick" could be applied in several places of the
> > function, e.g.
>
> > 52 for (var i in a) {
> > 53 if (a.hasOwnProperty(i)) {
> > 54 eq = eq && equiv(a[i], b[i]);
> > 55 }
> > 56 }
>
> > 59 for (var i in b) {
> > 60 if (b.hasOwnProperty(i)) {
> > 61 eq = eq && equiv(b[i], a[i]);
> > 62 }
> > 63 }
>
> > in the for(x in y) there should be a break, since there is no abort
> > condition.
>
> > greets, markus
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---