What’s the fastest way to build a
string in C#? We have several options available to us.
string.Format() is a function built right in to the
string class., Concatenation (
"a" + "b") is a feature of the language itself! The
System.Text.StringBuilder class is a built in class with a name that makes it sound like it’s purpose-built for building strings. Today I pit these three against each other to find out just which one you should be using to build strings as quickly as possible.
Posts Tagged performance
What’s the fastest way to build a
The new IL2CPP scripting backend in Unity 4.6.2 and 5.0 is supposed to be much faster than the old Mono backend. I ran some benchmarks, but mostly found slowdowns compared to Mono. Today’s article shows the tests I ran, the results I got, and wonders why the IL2CPP version seems so slow. Perhaps one of you, dear readers, knows the reason why. Update: Part of the reason why has been discovered. Read on for updated results.
Which is the fastest kind of C# function in Unity? There are several to choose from: regular old instance methods, static methods, delegates, and lambdas. Is there any performance reason to choose one over the other? Today’s article answers just these questions by putting each type of function to the test. Read on to see which is fastest and which is slowest!
SQL-style LINQ queries are a concise, readable way of performing various tasks dealing with all kinds of collections. Surely all that convenience comes with a performance cost to it. How bad do you think it is? Today we’ll look at the cost of some basic LINQ queries (
Select) versus the equivalent non-LINQ code. We’ll also see how much slower both of them are compared to manually-written, traditional code that does away with all the flexibility. Read on to see the results!
Unity’s coroutine support allows you to easily create pseudo-threads and write synchronous-looking code that doesn’t block the rest of the app. They can be very handy for a variety of tasks. Before using them, we should understand the performance cost. Today’s article takes a look at the cost of starting a coroutine as well as the cost of running it. Just how expensive are they? Read on to find out!
Reflection allows you to introspect your code at runtime. You can do very dynamic things like call functions by their name as a string. As such, it’s a really powerful tool when you code needs to be more flexible. Unfortunately, it’s slow. Really slow. Today’s article puts it up against regular, non-reflection code to show the difference in speed. It’ll also walk you through reflection in C# in case you’ve never used it before. Read on to learn more about reflection in Unity!
C# has properties similar to AS3’s
set functions. These functions can even be auto-generated for you, which is very convenient. However, the auto-generated versions don’t expose the so-called “backing field” that the property gets and sets. This brings up a question: is there a performance penalty to using an auto-generated property rather than manually implementing the property so we can directly access the backing field? The
set blocks are like functions, so are we paying function call overhead for them every time we access our own private pseudo-variables? Finally, could we do even better by skipping fields altogether and working on local variables instead? Today’s article puts all three approaches to the test by analyzing the bytecode that’s generated and the performance within a Unity test environment. Read on to see which way is fastest!
Unity apps are usually developed within the Unity Editor and then published to standalone apps for iOS, Android, Windows, Mac, and so forth. We’d therefore like to think that what we’re seeing in the Editor is very close to what we’ll see once we publish the app. In many cases, this is true. However, when it comes to performance this is sometimes a bad assumption to make.
Today’s article is the first to test Unity script performance speed. It establishes a way to set up and test C# scripts in Unity whether you have access to Pro or not. As a first example, I was reminded by the news this week that
AddComponent(string) is being removed in Unity 5.0. These alternative versions of
GetComponent aren’t something I normally use, but the news got me thinking of their performance compared to the generic-typed versions:
GetComponent<ComponentType>(). The docs say to avoid the versions taking a
string, but how bad could the performance really be? Today’s article puts the two versions to the test to find out just that!
Many modern strongly-typed languages have introduced a way for you to not have to type a variable’s type. In C#, you can use
var instead of the actual type. In C++, you use
auto. AS3 has a similar feature with it’s “untyped” type:
*. In those other languages,
auto are syntax sugar that the compiler replaces with the actual type. Will the AS3 compiler and/or Flash Player do the same for us? Today’s article finds out if it’s safe to skip the type and just use