does not
indicate code bytes?
John
- Original Message -
From: "Steven Sacks | BLITZ" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list"
Sent: Wednesday, September 20, 2006 12:07 AM
Subject: RE: [Flashcoders] Find item in array
> using a for..i..in loop will always
He's right, and declaring the variable i inside of the loop rather than
before actually (weirdly) runs faster. I don't know what pcode it produces,
but I know CPU doesn't care about pcode. I think the only way to test speed
is timing the thing. It's all very interesting, but I doubt even 10 ms of
Actually, Tyler's tests proved that "var a in" is faster with today's
player. I tried his test out myself and my results were even wider than
his. I published for AS2 and ran in Flash Player 9. I was averaging
roughly 265ms for "var a in" and 275ms for "(--a -(-1))".
Then I compiled for AS3
no longer be
the case.
regards,
Muzak
- Original Message -
From: "Tyler Wright" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list"
Sent: Tuesday, September 19, 2006 10:35 PM
Subject: Re: [Flashcoders] Find item in array
> :)
>
> So, for the sake of a
And to be specific about why your for in as you put it would not be
faster, you're declaring var i in your loop, which results in more
pcode, which means it will take longer.
var a;
for (a in array) {}
would be faster.
___
Flashcoders@chattyfig.figlea
> using a for..i..in loop will always be faster
It's been proven before here on flashcoders that for in is not faster
than --a -(-1) because it compiles to more lines of pcode. I guess it's
time to use Flasm to bust out some pcode and post it here on the list
instead of making claims based on hun
mailing list
Subject: RE: [Flashcoders] Find item in array
Wow, good thread.
Here's my 2 cents. Perhaps one other thing to factor is if the array is
sorted:
"If the array is not sorted the best you can do is iterate through all of
the items in the array, checking each element, until you e
ler
Wright
Sent: Tuesday, September 19, 2006 4:36 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Find item in array
:)
So, for the sake of another one of those big arguments over what's better
where no one ever test, I wrote some code to find out exact results:
The followi
:)
So, for the sake of another one of those big arguments over what's better
where no one ever test, I wrote some code to find out exact results:
The following code executes one particular test on my Windows XP machine.
For results I got an averate of 347 miliseconds executeing the --i -(-1) and
using a for..i..in loop will always be faster. Even more then --a
-(-1)
I'm ducking and running for cover.
Jason Merrill
Bank of America
Learning & Organization Effectiveness - Technology Solutions
___
Flashcoders@chattyfig.figleaf.com
for (var i:String in myArray)
{
if (myArray[i] == value)
return Number(i);
}
using a for..i..in loop will always be faster. Even more then --a -(-1)
iteration. Unless you can guarentee that your element will always be near
the beginning of a large array, as the for..i..in starts from th
> So, now I just end up using it for everything since it's become a
habit.
> The flipside is that sometimes I need to do forward loops for
> reiterating to maintain proper order. However, I would have to do
that
> anyway regardless of which backwards looping method I used.
To clarify, I don't mea
I guess what it depends on is what you're doing with that for loop.
If you're using it to attach or create or animate movieclips, or parse
through xml or a recordset, or anything that would make Flash
unresponsive during the loop, then the benefits of while (--a -(-1))
outweigh the readability com
Mike, that sounds very reasonable to me.
What I've been able to ascertain is reading and writing to the register
(in the case of (--i -(-1)) is significantly faster than reading and
writing to a variable (in the case of (i--)) that the first case's
additional instruction to subtract doesn't ou
L PROTECTED] [mailto:flashcoders-
> [EMAIL PROTECTED] On Behalf Of Steven Sacks | BLITZ
> Sent: Tuesday, September 19, 2006 1:45 AM
> To: Flashcoders mailing list
> Subject: RE: [Flashcoders] Find item in array
>
> As to why exactly --i -(-1) runs faster in a while loop than i--,
well,
>
ander over into
AS2 and 3 land and have to squint at oddball loops.
>
> From: "Steven Sacks | BLITZ" <[EMAIL PROTECTED]>
> Date: 2006/09/18 Mon PM 11:27:33 CDT
> To: "Flashcoders mailing list"
> Subject: RE: [Flashcoders] Find item in array
>
> Ther
you live and learn.
M
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Fumio Nonaka
> Sent: 19 September 2006 14:38
> To: Flashcoders mailing list
> Subject: Re: [Flashcoders] Find item in array
>
> Unlike to eva
Unlike to evaluation of a condition, the initial value should be
evaluated only once anyway.
for (var i = initialValue(); i
var l = myArray.length;
for (var i = l; --i -(-1); ) {}
Then you're not looking up the length on every iteration..
--
Fumio Nonaka
mailto:[EMAIL PROTECTED]
http://ww
It's a hell of a lot easier to
> read than the fastest for loop syntax.
>
> for (var i = myArray.length; --i -(-1); ) {}
>
Actually that would be:
var l = myArray.length;
for (var i = l; --i -(-1); ) {}
Then you're not looking up the length on every iteration..
:p
M
__
>>My original question to Jason was clarification on *why* (--i -(-1))
>>would run faster than (i--) as it seemed to me that two calculations
per
>>loop would run slower than 1. Since he used an expression I've never
>>seen before I figured he might might know the reasoning behind the
>>optimizati
As to why exactly --i -(-1) runs faster in a while loop than i--, well,
it can't be the same exact pcode or it wouldn't be faster so it must be
less pcode. I didn't bother to verify it myself because at the time,
somebody did for me. It's explained somewhere in the archives. If you
dig, you'll f
My original question to Jason was clarification on *why* (--i -(-1))
would run faster than (i--) as it seemed to me that two calculations per
loop would run slower than 1. Since he used an expression I've never
seen before I figured he might might know the reasoning behind the
optimization. I
There has been extensive testing on this (search the archives) and it's
been proven to my satisfaction that pre-decrementated loops are
consistently faster than post-decremented loops, and specifically that
while (--i -(-1)) is faster than while (i--), less p-code or not.
To the point that it's mo
September 2006 1:23 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Find item in array
Steven Sacks | BLITZ wrote:
> It's the fastest because:
>
> Pre-decrementation (--i) is faster than post-decrementation (i--)
I don't see why that would be. Both "var i=
Steven Sacks | BLITZ wrote:
It's the fastest because:
Pre-decrementation (--i) is faster than post-decrementation (i--)
I don't see why that would be. Both "var i=1;i--;" and "var i=1;--i;"
compile down to the exact same 8 lines of p-code:
_constantPool "i"
_push "i" 1
_var
_push "i" "
It's the fastest because:
Pre-decrementation (--i) is faster than post-decrementation (i--)
And substraction (- (-1) is faster than addition (+ 1).
They are faster because it's less code that gets produced when you
compile.
http://flasm.sourceforge.net/#optimization
For most cases, it's a matter
Merrill, Jason wrote:
while (--i -(-1)) {
Jason, very interesting way of counting through the array. I haven't
see this approach before. Are there any benefits to using (--i -(-i))
in the expression over something like the following?:
while (i--) {
It seems like your loop would need t
Yeah, you may want to try an indexed(?, sorry tired!) array:
var a:Array = new Array();
a["b"] = 1;
.
.
a["d"] = 4;
then,
var y:Number = a["b"];
will result in y == 1;
Scott
On 9/18/06, Mendelsohn, Michael <[EMAIL PROTECTED]> wrote:
Hi list...
Is there an easy/quick way to find out if an
>>Is there an easy/quick way to find out if an item is in an array?
No built in methods I know of. But quick and easy, is just to loop.
Something like:
public function findStringItem(theArray:Array,
identifier:String):Number{
var i:Number = theArray.length
29 matches
Mail list logo