blah, forgot for last post
phyconinja, youre suggesting is kind of pointless, since 'or' and 'and' have been removed in AS3 :p
blah, forgot for last post
phyconinja, youre suggesting is kind of pointless, since 'or' and 'and' have been removed in AS3 :p
At 9/8/06 12:30 PM, -dELta- wrote: blah, forgot for last post
phyconinja, youre suggesting is kind of pointless, since 'or' and 'and' have been removed in AS3 :p
oh..lol.. didnt know that!! sorry
At 9/8/06 12:29 PM, -dELta- wrote: using loop of 10,000,000
sqrt, int: 1902ms
pow,int: 4255ms
sqrt, Number: 1885ms
pow,Number: 4165ms
i cant say that im suprised with this mind, surely a specific function for square root is faster than an arbitary power function.
Yeah, but code speeds have surprised us all quite a bit here so far, so you never know where you stand.
Also, if they're up to it, someone should try finding the longest string of multiplication before powers outperform multiplication, e.g. x * x * x * ... * x; versus Math.pow(x, y);. It could be that powers are always inferior when you know specifically what it is you're putting the number to or it's a non-integer.
At 9/9/06 04:39 AM, _Paranoia_ wrote: so, if they're up to it, someone should try finding the longest string of multiplication before powers outperform multiplication, e.g. x * x * x * ... * x; versus Math.pow(x, y);.
you cant really test this, because really, it depends on the number youre multiplying, but there will be a time, at which pow(x,y) will be faster than x*x*x....*x, simply because pow(x,y) has constant number of operations, so at some point it will do less than multiplying them together
At 9/9/06 05:37 AM, -dELta- wrote:At 9/9/06 04:39 AM, _Paranoia_ wrote: so, if they're up to it, someone should try finding the longest string of multiplication before powers outperform multiplication, e.g. x * x * x * ... * x; versus Math.pow(x, y);.you cant really test this, because really, it depends on the number youre multiplying, but there will be a time, at which pow(x,y) will be faster than x*x*x....*x, simply because pow(x,y) has constant number of operations, so at some point it will do less than multiplying them together
lol, I never got my head around how computers work out powers and roots and complex stuff like that. Even multiplications and divisions... :S Can someone explain it?
well, lets start with addition, addition, requires 5 logic gates, per bit. although you can shorten the first one.
2XOR gates, an OR gate, and two AND gates
if you have two numbers
a = [a3,a2,a1,a0];
b = [b3,b2,b1,b0];
then you get a sum of
s = [(a3^b3)^c2, (a2^b2)^c1, (a1^b1)^c0, a0^b0];
where c0 = a0&b0
cn = (an&bn)|((an^bn)&c[n-1])
so if we have two numbers, 5 and 7
5 = 0101 = (a3,a2,a1,a0)
7 = 0111 = (b3,b2,b1,b0)
s0 = 1^1 = 0, c0 = 1&1 = 1
s1 = (0^1)^1 = 1^1 = 0, c1 = (0&1)|((0^1)&1) = 0|(1&1) = 0|1 = 1
s2 = (1^1)^1 = 0^1 = 1, c2 = (1&1)|((1^1)&1) = 1|(0&1) = 1|0 = 1
s3 = (0^0)^1 = 0^1 = 1, c3 = (0&0)|((0^0)&1) = 0|(0&1) = 0|0 = 0
0101 + 0111 = (0)1100
5 + 7 = 12
the last carry bit, c3, is for overflow, for example, if you add 9+8, but you only allow 4 bits per number, you will get an overflow of 1, in c3, which also explains, how in languages like C++ with int data type, if you go over the max, it overflows, and its looped back to 0 and continued from there.
-a = !a+!, i.e.
5 = 0101
!5 = 1010, +1 = 1011 = -5
this is signed integers, where the first bit signifies if its negative, and the last three, if negative, is how close to the max negative number it is, such that with this method of negatives
a - b = a + (!b+1)
you can optimize electronic speed of this, by using NOT on b input to the addition, and setting the first carry bit, used to find the first bit to 1, so it automaticly adds 1
Wow. That's actually quite helpful. Cheers, Delt!
I've decided to do a few more speed tests. You guys should add some more stuff to this too.
Multiple number variables against Arrays
Arrays
vA = [5, 8, 2];
Numbers
vA = 5;
vB = 8;
vC = 2;
With three values:
Array avg - 1165ms
Number avg - 355ms
With ten values:
Array avg - 1915
Number avg - 708
From this we can see that multiple number variables are much faster for storing a small to medium number of number values.
The multiplication for higher numbers of values proves slightly less different than for lower ones. While the time seems to double for numbers on an increase in values, it is increased by less for arrays over the same time. It is reasonable to conclude that there is a (quite high) number of values over which arrays outperform numbers for storage.
At 10/30/06 04:28 PM, The-Frosties-Kid wrote: I've decided to do a few more speed tests. You guys should add some more stuff to this too.
are these AS3, and did you use strict data typing on the variables, and did you also try the different declaration methods of the array, and different number types for use in the individual variables and array stored variables?
one of the reasons that arrays will always be slower is because you cant strict type the data within an array, the flash player will always need to determine what type the data is before continuing, and depending upon how flash's arrays work, i dont thin they are, but they might not be in a vector style format, they might be in a linked list style format or alternative, in which case random access is not very fast, so the further towards the middle the data youre accessing is the slower it will be, thats supposing its a doubly linked list style format.
At 7/31/06 08:53 AM, The-Frosties-Kid wrote: Here's another one - modulo assignments versus if statements for resetting counters:
Modulo -
j += 1;
j %= 2;
If (equality) -
j += 1;
if(j == 2){
j = 0;
};
If (comparison) -
j += 1;
if(j >= 2){
j = 0;
};
Modulo assignment - 1082
Number equality check - 87
Number comparison - 91
those all do totally different things. in order to recreate a modulus you would need a loop
a % b
is equivilent to
while(a>b){
a-=b;
}
i would like to see a test of formatted code verse unformatted (like with semi colons missing and stuff). it would be nice to isolate which typo causes how much lag. also do...while verse while verse for loops. i already know while beats fors but i would like lag times.
also, this is a very nice thread. and I'm glad that most my methods are dominant, i still choose binary increment over ifs whenever possible, but I'm definitely going to lay off the conditionals.
At 7/31/06 08:53 AM, The-Frosties-Kid wrote:for resetting counters:
whoops, i didn't see that, i never use % for that, always >=, because they mostly increase by numbers greater than 1.
At 7/28/06 07:13 AM, dELtaluca wrote: int (strict): 562ms
int (non strict): 6385ms
int (not declared): undefined
Number (strict): 1128
Number (non strict): 6385ms
Number (not declared): undefined
im confused, can i have an example of both strict and non strict datatyping?
im confused, can i have an example of both strict and non strict datatyping?
Strict data typing is when u declare everything, ect.
Ex, var lol:Number = 0; and not declared would be lol = 0; and i think delta meant with not strict as var lol = 0;.
And btw delta u should test speed diference while using classes.
*User Page under construction*
At 10/30/06 08:45 PM, JD77 wrote:im confused, can i have an example of both strict and non strict datatyping?Strict data typing is when u declare everything, ect.
Ex, var lol:Number = 0; and not declared would be lol = 0; and i think delta meant with not strict as var lol = 0;.
ok, the non strict thing was what i didnt get.
And btw delta u should test speed diference while using classes.
also, if you could find a way to do it, test a code spread out on movieclips instead of completely on the frame
At 10/30/06 07:33 PM, ImpotentBoy2 wrote: those all do totally different things. in order to recreate a modulus you would need a loop
a % b
is equivilent to
while(a>b){
a-=b;
}
I'm fully aware of what the modulo does and how it's different, but this was just a test for one use of it in a specific situation, which many people use it for. If you want to test the loop then feel free, though it probably goes without saying that the loop will be faster for small numbers and slower for big ones.
OMG! The top half of my reply got lost!
At 10/30/06 04:39 PM, dELtaluca wrote:At 10/30/06 04:28 PM, The-Frosties-Kid wrote: I've decided to do a few more speed tests. You guys should add some more stuff to this too.are these AS3, and did you use strict data typing on the variables, and did you also try the different declaration methods of the array, and different number types for use in the individual variables and array stored variables?
Just AS2, I'm afraid, with one test for the way people would normally be using it. Variables defined strictly before hand and assigned values in the loop.
If you want to take this further and test with multiple data types, or different definitions, or objects as holders for values, then feel free.
At 10/31/06 03:55 AM, The-Frosties-Kid wrote: Just AS2, I'm afraid, with one test for the way people would normally be using it. Variables defined strictly before hand and assigned values in the loop.
well i appreciate the contribution, but these speed tests are for AS3 only, the results differe GRAVELY between AS2 and AS3, and most of these speed tests are irrelevant or have different results in AS2 than AS3.
At 10/31/06 03:52 AM, The-Frosties-Kid wrote:At 10/30/06 07:33 PM, ImpotentBoy2 wrote: those all do totally different things. in order to recreate a modulus you would need a loopI'm fully aware of what the modulo does and how it's different, but this was just a test for one use of it in a specific situation, which many people use it for. If you want to test the loop then feel free, though it probably goes without saying that the loop will be faster for small numbers and slower for big ones.
a % b
is equivilent to
while(a>b){
a-=b;
}
ya sorry,i apologized for that earlier, and i realized i a was kinda wrong with the for loop too you can just do:
trace(a - Math.floor(a / b) * b);