Posts Tagged performance

Event Performance: C# vs. UnityEvent

Unity programmers have their choice of two kinds of events. We could use the built-in C# event keyword or Unity’s UnityEvent classes. Which is faster? Which one creates more garbage? Today’s article finds out!

Read the rest of this entry »

Tags: , ,

7 Comments

Delegate() vs. Delegate.Invoke()

In reading others’ C# code I consistently see some programmers call delegates like a function—del()—and others use the Invoke method of the Delegate class: del.Invoke(). Is there any difference between the two? Is one better than the other? Today’s article finds out!

Read the rest of this entry »

Tags: , ,

No Comments

Using Structs to Avoid Creating Garbage

It’s easy to forget about struct in C#. After all, it’s not available in other languages like Java or AS3 and it seems to have fewer features than good old class. But struct can really help you out when it comes to garbage creation! Today’s article discusses some strategies to get the most out of struct. Read on to learn how to use structs to put a stop to that pesky garbage collector!

Read the rest of this entry »

Tags: , , , ,

No Comments

Do Foreach Loops Create Garbage?

We know that we should reduce the garbage our code produces to lighten the load on Unity’s garbage collector. The trouble is that many of the ways we’re creating garbage are hidden from us. One such way to inadvertently create a lot of garbage is to use a foreach loop… at least that’s what we’ve been told. Do foreach loops really create garbage for all types of arrays, lists, dictionaries, and the rest of the collections? Do they create garbage for every loop or just the first one? Today’s article investigates to put these questions to rest. Are you safe using foreach loops or should you re-write everything to use for. Read on to find out!

Read the rest of this entry »

Tags: , , , , , ,

4 Comments

Too Many Coroutines: A Queue Solution

Unity’s coroutine support is great. So great that it’s easy to go overboard and end up with too many of them. That could be for any number of reasons. Perhaps the coroutines are using too much memory or have too many files open at once. In any case, you’ll need to find a way to limit how many are running at a single time. Today’s article introduces a solution to the problem that queues coroutines so you never have too many running. Read on to learn about the solution and for the class that implements it.

Read the rest of this entry »

Tags: , , ,

2 Comments

String Concatenation Performance

As programmers, we concatenate strings all the time. Should we worry about the performance? How about the amount of garbage we’re producing for the garbage collector? Today’s article runs a quick test to find out!

Read the rest of this entry »

Tags: , , ,

No Comments

Encryption Algorithm Performance

Last week I covered the performance of cryptographic hash algorithms like MD5 and SHA-1. This week I’ll continue by testing the performance of the closely-related encryption algorithms. This includes algorithms like AES, DES, RC2, Rijndael, and TripleDES. Which is fastest? Does the key size, block size, padding mode, or cipher mode matter? Read on to see!

Read the rest of this entry »

Tags: , , , , , ,

2 Comments

Hash Algorithm Performance

Sooner or later you’ll need to use a cryptographic hash function. Sometimes it’s to quickly check if two large byte arrays are the same, sometimes it’s for interoperability with some server, and other times it’s to obfuscate a string. In any case, performance of the various hash algorithms varies wildly. Today’s article performance tests all 27 hash algorithm permutations to see which is fastest and which is slowest. Read on for the performance test results!

Read the rest of this entry »

Tags: , ,

6 Comments

Efficiently Keeping Lists Sorted

List<T> (and SafeList) have a great feature for fast lookups: BinarySearch. However, the list needs to be sorted in order to use it. You could call Sort() first, but that would give back all the performance you got with BinarySearch. It’s better to just keep the list sorted all the time. Unfortunately, there is no function on IList<T>, List<T>, or SafeList to efficiently insert an item into a list that’s already sorted. Today’s article presents an extension function that adds this functionality on to IList<T> and even the non-generic IList so your list will always be sorted for quick lookups with BinarySearch. Read on for the code, unit tests, and a performance test showing the advantages you stand to gain.

Read the rest of this entry »

Tags: , , , , ,

2 Comments

Delegates As Function Pointers: Performance Boost?

C# delegates can be used like function pointers. Assign it once and you don’t have to use an if over and over. But is the overhead of the delegate worth it? Today’s article puts it to the test to see if this a valid performance boost versus just using an if over and over. Read on to see if a delegate is worth your time.

Read the rest of this entry »

Tags: , , ,

4 Comments