Posts Tagged operator

Operator Speed: Part 2

Tags: ,

Today’s article is a followup to a flawed article I wrote last October. Skyboy’s comment brought this to my attention, so today I’m (hopefully) correcting the problems with an important test: AS3 operators. Read on for the updated test code and results.

Read the rest of this article »

11 Comments

Calling Functions

Tags: , , ,

There are actually three ways to call a function in AS3. Can you name all three? Do you know which is fastest? Does the type of function being called matter? Today I’ll tackle these questions and find some surprising facts about the three ways to call a function in AS3.

Read the rest of this article »

18 Comments

Accessing Objects

Tags: , , , , , , , , , , ,

There are three main ways to access the contents of objects in AS3: the dot (.) operator, the index ([]) operator, and the in operator. The first two are well known and functionally-equivalent because obj.property evaluates to the same value as obj["property"]. The in operator is different as I’ve described before: it returns a Boolean indicating whether or not the object has the given property. There are a lot of cases—error checking, for example—where we only care if an object has a property and not what that property is. So, can we improve performance by using the is operator rather than the index or dot operators? (UPDATE: hasOwnProperty results added)

Read the rest of this article »

2 Comments

Operator Speed

Tags: ,

Today’s article is about the basic operators that make up most languages, and in particular AS3. Without them there wouldn’t be much of a language. So it would seem vitally important that we know how they perform relative to each other. Is shifting faster than adding? Adding faster than multiplying? Multiplying faster than dividing? Does the type of the operands matter? Read on for the results in high detail. Update: see my comment below for an important change to the results.

Read the rest of this article »

15 Comments

Logical Operator Performance

Tags: , ,

An absolute fundamental of programming is the concept of logical operators like && and ||. In a recent comment, Chris H pointed out that MXMLC doesn’t do a particularly good job generating bytecode for these operators. Today I’ll look further into the subject and see just how much this impacts performance.

Read the rest of this article »

10 Comments

Object Creation

Tags: , , , ,

A comment posted before the Flash Player 10.1 series of articles asked about the performance differences between creating an object with o = new Object() and with o = {}. Below I’ll look into the generated bytecode for these two approaches and test their relative performance to see if either approach is faster than the other.

Read the rest of this article »

19 Comments

Declaring Vectors

Tags: , , , , ,

The differences between Vector and Array have been quite interesting since Vector was introduced in Flash Player 10. Until just recently I didn’t know that there was special syntax for declaring a Vector akin to Array's special a = [1,2,3,4,5] trick. This got me thinking about the various ways one can declare a Vector and, of course, how they’re implemented in bytecode and what the speed differences, if any, are. Read on for some nitty gritty about how you declare Vectors in AS3.

Read the rest of this article »

26 Comments

Increment and Decrement

Tags: ,

This is a quick article to discuss a point brought up in a recent comment. Which is the fastest way to increment: j++, ++j, or j+=1? Likewise, which is the fastest way to decrement? Below I will dispel the myth that there is any difference between them at all.

Read the rest of this article »

7 Comments

Flexible If Syntax

Tags: , , ,

This article is sort of a follow-up to my article on Flexible Loop Syntax. This was reported to my by a coworker who spotted the anomaly. I guess he had done with if the same sort of thing that I had done with for. Read on for a little insight into how the comma operator interacts with the if statement.

Read the rest of this article »

5 Comments

Case Statements

Tags: , , ,

The lowly switch statement and its attendant case statements is a basic element of most C-style languages. Still, I was surprised by it recently when it seemingly ate one of my functions. Read on to see how.

Read the rest of this article »

7 Comments