Results 1 to 5 of 5
Thread: unsigned vs signed
-
August 19th, 2008, 08:29 PM #1
unsigned vs signed
I know this is not specifically AS3 related, but it's close.
In a lot of programming languages, and ESPECIALLY in Actionscript 3, there's a huge difference in processing time between unsigned and signed integers.
Now, to me, it's just simply logical that an unsigned integer (uint) should be faster. It's a less dynamic type since it can only hold positive numbers and should logically reserve less memory resources.
So why are signed integers (int) so much faster? I don't get it. The difference is enormous! At least on a micro scale.
Any insight is welcome.
Thanks
* [ Flash portfolio ] http://www.erikhallander.com/
* [ Flash blog ] http://www.erikhallander.com/blog/
* [ Work @ ] http://www.visualjazz.com.au
-
August 19th, 2008, 09:12 PM #2
I'm also interested in knowing what's up with AS3's uint slowness.
They're both 32-bit integers, why would unsigned integers take up less space? The sign bit is included as one of the 32 bits.It's a less dynamic type since it can only hold positive numbers and should logically reserve less memory resources.
What other languages have slow uints? (I haven't heard of similar speed issues in other languages, but I haven't been looking.) In a lower level language like C, at least, uints and ints seem to be equal. I used this code and a copy of this code only using signed integers instead:
Code:int main(){ unsigned int i = 0; unsigned int j = 0; unsigned int k = 0; for(i = 0; i < 100000; i++){ for(j = 0; j < 10000; j++){ k = i + j; } } }Unless gcc is doing some optimization that I don't know about, then it seems like these two program took about the same amount of time even though two different integer types were used.
Originally Posted by bash
-
August 19th, 2008, 09:33 PM #3
Yeah you're completely right, they are both 32 bit. My bad. I wasn't quite thinking when I wrote that.
Question still remains though
* [ Flash portfolio ] http://www.erikhallander.com/
* [ Flash blog ] http://www.erikhallander.com/blog/
* [ Work @ ] http://www.visualjazz.com.au
-
August 19th, 2008, 09:49 PM #4
Well I'd assume a check is performed to see if the number provided is greater or equal to 0 when using uint, which may result in a slower speed.
-
August 20th, 2008, 01:49 PM #5

Reply With Quote



Bookmarks