Tuesday, May 29, 2012
Monday, May 28, 2012
Kroolz
As recently promised, "Krool Joolz" has made a comeback on the iOS platform as "Kroolz". Get it here, it's Free!
Monday, May 07, 2012
Micro Optimisation in Unity3D
NGUI caches the transform component in a member variable called mTrans, to optimise speed of access. I think this is UGLY, so I decided to do some benchmarks to see if the ugliness is worth the performance increase.
In short, the answer is NO.
My tests showed that using a local variable is always as fast as using a member variable, and usually faster.
Here are some typical results.
They show that caching and accessing the target reference is twice as fast as just using the reference. They also show that assigning to a local variable and using that variable for access is usually even faster than a member variable.
This is the code I used for benchmarking.
In short, the answer is NO.
My tests showed that using a local variable is always as fast as using a member variable, and usually faster.
Here are some typical results.
Cached: Time elapsed: 00:00:04.8086550 Uncached: Time elapsed: 00:00:09.1058490 Local: Time elapsed: 00:00:04.7870590
They show that caching and accessing the target reference is twice as fast as just using the reference. They also show that assigning to a local variable and using that variable for access is usually even faster than a member variable.
This is the code I used for benchmarking.
using UnityEngine; using System.Collections; public class Benchmark : MonoBehaviour { Transform cachedTransform; void Start () { cachedTransform = transform; TestCached(); TestUncached(); TestLocal(); } void TestUncached() { var stopwatch = new System.Diagnostics.Stopwatch (); stopwatch.Start (); for (int i = 0; i < 100000000; i++) { var p = transform.position; } stopwatch.Stop (); Debug.Log (string.Format("Uncached: Time elapsed: {0}", stopwatch.Elapsed)); } void TestCached() { var stopwatch = new System.Diagnostics.Stopwatch (); stopwatch.Start (); for (int i = 0; i < 100000000; i++) { var p = cachedTransform.position; } stopwatch.Stop (); Debug.Log (string.Format("Cached: Time elapsed: {0}", stopwatch.Elapsed)); } void TestLocal() { var stopwatch = new System.Diagnostics.Stopwatch (); stopwatch.Start (); var t = transform; for (int i = 0; i < 100000000; i++) { var p = t.position; } stopwatch.Stop (); Debug.Log (string.Format("Local: Time elapsed: {0}", stopwatch.Elapsed)); } }
Saturday, May 05, 2012
Rendering HTML
Rendering HTML in Unity3D sure is... tricky. It would seem simple enough, but page/text layout algorithms can certainly be challenging, even when supporting only a subset of HTML.
Subscribe to:
Posts (Atom)
Popular Posts
-
I've just seen and used a brilliant ssh option. The command: sudo ssh -D localport user@externalhost will set up a local SOCKS proxy l...
-
Working with multiple threads is often a necessary evil. This is how I do it safely inside a Unity3D component. There are only certain time...
-
Update: This is another planet shader, with more physical fidelity. Shader "Planet" { Properties { _MainTex ("Di...
-
When you start working with threads in your Unity3D project, you will discover that many things need to be done in the main loop. For exampl...
-
Space is awesome. Especially when it is generated using Perlin noise, and some cool shaders. You can try it out over here.
-
Possibly slightly more correct lighting. The rim light is now only applied in the direction of the sun, rather than being purely based on v...
-
So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along. ...
-
It is not an official port, but a very good replica. This is one of my favorite games, and I don't have many. It's deep, difficult, ...
-
Summary: NodeJS wins. Test Program ab -n 10000 -c 5 http://localhost/ Gevent Code from gevent import wsgi class WebServer(object): ...
-
Thank to Adrian Boeing I was inspired this morning to hack together a ripple shader for Unity3D. Thanks for the math Adrian. You can see t...

