Posts Tagged loop

Loops in IL2CPP

Tags: , , , , , , ,

There are many permutations of loops we can write, but what do they compile to? We should know the consequences of using an array versus a List<T>, for versus foreach, caching Length, and other factors. So today’s article dives into the C++ code that IL2CPP outputs when we write these various types of loops to examine the differences. We’ll even go further and look at the ARM assembly that the C++ compiles to and really find out how much overhead our choices are costing us.

Read the rest of this article »


C++ Scripting: Part 27 – Foreach Loops

Tags: , , ,

C++ doesn’t have a foreach keyword, but it does have an equivalent in “range for loops”. Today we’ll implement support for them so we can easily loop over arrays and types implementing IEnumerable and IEnumerable<T>.

Read the rest of this article »

No Comments

Do Foreach Loops Still Create Garbage?

Tags: , , ,

Over a year ago I wrote an article title Do Foreach Loops Create Garbage using Unity 5.2 and tested foreach with a variety of collections: List, Dictionary, arrays, etc. Since then Unity has a new C# compiler and version 5.6 has been released. Is it safe to use foreach now? Read on to find out!

Read the rest of this article »


For vs. Foreach

Tags: , , , , ,

foreach loops are really convenient, but are for loops faster? It’s a simple question, but one that has really wide implications in almost any codebase. Today’s article tests them out to see which is faster for looping over arrays and Lists. Read on to see which is quicker!

Read the rest of this article »


From AS3 to C#, Part 15: Loops, Casts, and Operators

Tags: , ,

As with types and variables, there is a lot of subtlety in the differences between AS3 and C# when it comes to loops, casts, and operators. As core parts of the language, it’s important that we know all the little details of our most fundamental tools. Read on to learn what they have in common, what new operators C# offers, and what operators C# doesn’t have.

Read the rest of this article »


Bytecode Analysis: Why do-while Is so Slow

Tags: , , , ,

The do-while loop is slower than the for and while loops… at least in Flash. Why? Today’s article digs into the bytecode the compiler generates for a variety of these loops to find out why.

Read the rest of this article »


5x Faster For-In Loops

Tags: , , ,

I’ve recently been notified of a way to dramatically speed up for-in loops. I’ve tested this method out and indeed there is a 5x speedup. Employing the technique is also really easy. Unfortunately, the speedup is sometimes an illusion. Read on to learn a little more about for-in loops and how you could potentially speed yours up by 5x.

Read the rest of this article »


Loop Speed Redux

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

AS3 has three kinds of loops—for, for-in, and for-each—but which is fastest? I attempted to answer that question about three years ago, but the article is in dire need of a followup as many version of Flash Player have been released since then and the question is core to our everyday lives as AS3 programmers. So which type of loop is fastest in 2012?

Read the rest of this article »


Amazing Lookups Optimization

Tags: , , , , ,

Today’s article is about an unintuitive-yet-simple optimization you can use to hugely increase the speed of reading from Array, Vector, Dictionary, Object, and dynamic classes. Need I say more? Read on for this amazing speedup!

Read the rest of this article »


Loops With int and uint

Tags: , , , , , , , , ,

AS3 has two integer types: int and uint. In my experience, most AS3 programmers just use int everywhere and ignore uint. This is usually acceptable as the need for unsigned integers is rare compared to their signed counterparts. However, there are significant performance differences between the two. Read on for the impact of uint on your loops. The original version of this article’s performance test contained a small-but-critical error that led to a lot of incorrect analysis and results. This version of the article has been corrected.

Read the rest of this article »