Whilst I don't disagree the spec suggest that both should be the same, my test on jsperf gave me an insight http://jsperf.com/incremental-loops/6
Obviously, all benchmarks are subject to conditions and I may have misunderstood the results. But to be fair the numbers are negligible. While loops on the other hand are blindingly fast. On 19 Feb 2011, at 23:35, Angus Croll <[email protected]> wrote: > >>Note I also use ++i over i++ because it's slightly faster on some modern > >>browsers. > > I read the same thing on Andrea Giammarchi's site but I don't think its true. > Check the ECMA 5 standard. Since a for loop does not use the return value of > i++ or ++i the only interesting part is steps 4 and 5 for each case - and > they are identical. > > 11.3.1 Postfix Increment Operator > > The production PostfixExpression : LeftHandSideExpression [no LineTerminator > here] ++ is evaluated as follows: > Let lhs be the result of evaluating LeftHandSideExpression. > Throw a SyntaxError exception if the following conditions are all true: > Type(lhs) is Reference is true > IsStrictReference(lhs) is true > Type(GetBase(lhs)) is Enviroment Record > GetReferencedName(lhs) is either "eval" or "arguments" > Let oldValue be ToNumber(GetValue(lhs)). > Let newValue be the result of adding the value 1 to oldValue, using the same > rules as for the + operator (see 11.6.3). > Call PutValue(lhs, newValue). > Return oldValue. > 11.4.4 Prefix Increment Operator ( ++ ) > > The production UnaryExpression : ++ UnaryExpression is evaluated as follows: > Let expr be the result of evaluating UnaryExpression. > Throw a SyntaxError exception if the following conditions are all true: > Type(expr) is Reference is true > IsStrictReference(expr) is true > Type(GetBase(expr)) is Enviroment Record > GetReferencedName(expr) is either "eval" or "arguments" > Let oldValue be ToNumber(GetValue(expr)). > Let newValue be the result of adding the value 1 to oldValue, using the same > rules as for the + operator (see 11.6.3). > Call PutValue(expr, newValue). > Return . > > > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
