Posts Tagged ‘Abha Anjan’

Unity 3D Game

March 4th, 2010 by

During my experiment for a 3D game  I found Unity3D. Let me share some facts about the Unity3D.

It’s not only how fast the 3D rendering is. Unity3D has a very intuitive interface organized around a simple and clear concept.

Unity is a multiplatform game development tool, designed from the start to ease creation. A fully integrated professional application.

Something more about Unity 3D I got from Its website and other sources :

  1. 1. Scripting language:

Unity supports three scripting languages: JavaScript, C#, and a dialect of Python called Boo. All three are equally fast and interoperate. All three can use the underlying .NET libraries which support databases, regular expressions, XML, file access and networking.

  1. 2. NET based

Game logic runs on the Open Source .NET platform, Mono.

  1. 3. Java Script

Unity’s JavaScript implementation JIT-compiles to native machine code. It runs 20x faster than      Flash or Director based JavaScript, and the same speed as C# and Boo.

4. SCOPE for Multiplayer games

Create real-time networked multiplayer functionality. Unity supports all networking needs out of the box with little learning and even less effort.

  1. 1. Web Browser Integration

When running in a web browser, the deployed Web Player can communicate seamlessly with the container web page. That way you get javascript communication and full AJAX capabilities.

  1. 2. Backend Connectivity

.NET socket libraries can be used for real-time networking, by opening TCP/IP sockets or sending UDP messages. They also make speaking XML easy, and can connect to ODBC database connections.

  1. 3. Advanced Physics

  1. 4. Fully Integrated Editor

This integration allows the Editor to do everything a published game can do. The simple, visual, and intuitive nature of the Editor makes building games fun again.

  1. 5. Graphical Fidelity

Unity has a highly optimized graphics pipeline for both DirectX and OpenGL. Animated meshes, particle systems, advanced lighting and shadows, all will run blazing fast.

  1. 6. Supported File format

All major tools and file formats are supported, any art application can be used with Unity.

  1. 7. Web Deployment

Unity-made games can be played inside a web browser thanks to the Unity Web Player Plug-in. The plug-in download is small (about 3 MB), auto-installs without a browser restart, and already has a 8-digit distribution. It works on all modern browsers including Internet Explorer, Firefox, Safari, and most Mozilla-based browsers

  1. 8. iPhone publishing

9. Shadow & Light

Unity’s provides a highly optimized lighting system with realtime shadows and baked lightmaps. Use    shadow and light to great effect, without worrying about the gritty technical details.

10. Supported File format

All major tools and file formats are supported, any art application can be used with Unity.

11. Web Deployment

Unity-made games can be played inside a web browser thanks to the Unity Web Player Plug-in. The plug-in download is small (about 3 MB), auto-installs without a browser restart, and already has a 8-digit distribution. It works on all modern browsers including Internet Explorer, Firefox, Safari, and most Mozilla-based browsers


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

iPhone Tutorial5–Views-Transition

January 3rd, 2010 by aabhaanjan

This tutorial will focus on transitioning from one view to another. We will be utilizing Windows based Application to move from one view to another view.

In this tutorial you will learn:

  • Add A Windows Based Application.
  • Add a View Controller
  • Add a class to create Array
  • Set Up The Transition To The View
  • Connect The View To The Code

Creating a New Window Based Application

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this:

Make sure Application is selected under iPhone OS and then select Windows-Based Application. Click Choose… It will ask you to name your project. Type in “Tutorial 3 –transition between view” and let’s get started.

Now, all of these files together create a basic program.When you click Go ahead and click on the Build and Go button ,It display the bellow

You will see the iPhone simulator start and your program will launch.

Use Array to display Fresa Content in First View:-

Process to create Array class :-

  1. For Creating Array for fresa application à GO TO FILE à ADDà New Fileàand Select Objective C –Class and enter the name of file .The Screen will look like this

2. Now start by opening FresaCellView.h. This is the class for view controller that Apple display fresa content to main view .

Here you are creating the instance of Label and image to display the content to label and Picture to Image view control and you are creating method .

  1. Now start FresaCellView.m.

Here you have created the class and initialize the label.

  1. Now you want to utilize this class , you have to create a new table view controller class. For Creating New Viewcontroller Class . All of the functions you see already created in here are functions that have been overridden from the Table View super class.

Process to create viewController Class

  1. GO TO File à ADD à New File àSelect Objective C Class àEnter the name àFresaTableViewController.

Automatically two file will created .

  1. FresaTableViewController.h
  2. FresaTableViewController.m

Now you have to write code to utilize the FresaCellView Class .

Here you have to import fresaCellView class in FresaTableViewController.h .

This is fresatableViewController.m file . here you have to define your fresa content , Which will be appear in simulator

Since we are editing a table, all of these functions will be related to editing a table. So find the function called numberOfRowsInSection.

This function tells the application how many rows are in our table. Currently, it returns 0. Let’s change that to return no of content defined in array

.

Now go down to the function called cellForRowAtIndexPath. This function gets called once for every row. This is where we define what content to display in a given row. In this case we want the row to be a string that says.

What this function is doing is creating a new cell object and returning it. The code between the i(cell==null) block checks to see if we have created a cell before, if not build a new cell, otherwise use the one we created before. This helps in performance so we don’t need to build new cells each time we visit this function. So right before the // Set up the cell comment add the following code:

[call setLabelText:[arryData objectAtIndex:indexPath.row]];

Now come to the main file Tutorial2_NsArrayAppDelegate.h and Tutorial2_NsArrayAppDelegate.m .

For displaying view to the main window you have to create navigationControll to mapped with the view.

Now You have to create User Interface to display the fresa content .

Process to Create User Interface View :-

1.GOTOà ResourceàAdd File àView UIàAdd Label and ImageView

Now most important part to mapping with label and image. You have to mapped with the class .Here description text properties which is defined in fresaCellView.h class is mapped with label .

Process for User Interface :

  1. Now open Window.xib file.
  2. Drag and drop Navigation control to mainwindow.xib .
  3. Select Tutorial2_NsarrayAppdelegate class from Class identity.
  4. Now most important part here is that, You have to mapped navigationcontroller with the navigationControlle tab which you have selected from Library.

5. Now Call FresatableViewcontroller.xib file in View Controller properties . the screen will be look like this .

After Mapping Click the Build and Go button again to launch the iPhone simulator. You should see screen look like this and your content will display on the screen

Now here you want to transition between one view to another view . When you will click the Fresa menu the data or content of the respective menu will be display to other view . For displaying the content or description of the menu You have to follow the following process .

Add A New View

We will now add the view that we will be transitioning to. Click on. Once inside Interface Builder click on File -> New and select View.

It will add a blank View to your project mention the name nextviewcontroller . For now, we will keep it simple. Go ahead and drag a new Label on to the View.

Let’s save the view. Click File -> Save. Call it NextViewController.

Add A View Controller

Now we need to create a NextViewController class. This class will be used to connect the view that we just created to our code. Inside of Xcode click File -> New File… Select UIViewController subclass and click Next.


Name it NextViewController and make sure “Also create “NextViewController.h” “ is checked. Click Finish to continue. This will add the new ViewController to your project.

Set Up The Transition To The New View

Open up Tutorial2_transitionAppdelegate.h and add the following code:

Now go and Run

When you click on “ Fresa menu” it should transition to:

Notice the back button at the top with the text “Fresa”.

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

IPhone Tutorial4-View Based(Using Array)

January 3rd, 2010 by aabhaanjan

Hi All In this tutorial I would like to describe how to used NSArray to display the content I am going to show you the simplest way to create a list of content using array .

You will learn how to:

  • Create a Windows Based Application
  • Create Class to display fresa menu .
  • Create User Interface to display the menu .

Creating a New Windows-Based Application

Open Xcode

Start a new iPhone OS Project
Click Xcode > New Project and a window should pop up like this:

Make sure Application is selected under iPhone OS and then select Windows-Based Application. Click Choose… It will ask you to name your project. Type in “Tutorial 2 -NSArray” and let’s get started.

Now, all of these files together create a basic program.When you click Go ahead and click on the Build and Go button ,It display the bellow

will see the iPhone simulator start and your program will launch.

http://www.dremsus.com/welcome/3.JPG

http://www.dremsus.com/welcome/3.JPG

Use Array to display Fresa Content in View:-

Process to create Array :-

  1. For Creating Array for fresa application à GO TO FILE à ADDà New Fileàand Select Objective C –Class and enter the name of file .The Screen will look like this
http://www.dremsus.com/welcome/1.1.JPG

http://www.dremsus.com/welcome/1.1.JPG

2. Now start by opening FresaCellView.h. This is the class for view controller that Apple display fresa content to main view .

http://www.dremsus.com/welcome/1.2.JPG

http://www.dremsus.com/welcome/1.2.JPG

Here you are creating the instance of Label and image to display the content to label and Picture to Image view control and you are creating method .

  1. Now start FresaCellView.m.
http://www.dremsus.com/welcome/fresaarray/fresa3.JPG

http://www.dremsus.com/welcome/fresaarray/fresa3.JPG

Here you have created the class and initialize the label and imageView.

  1. Now you want to utilize this class , you have to create a new table view controller class. For Creating New Viewcontroller Class . All of the functions you see already created in here are functions that have been overridden from the Table View super class.

GO TO File à ADD à New File àSelect Objective C Class àEnter the name àFresaTableViewController.

Automatically two file will created .

  1. FresaTableViewController.h
  2. FresaTableViewController.m

Now you have to write code to utilize the FresaCellView Class .

http://www.dremsus.com/welcome/fresaarray/fresa5.JPG

http://www.dremsus.com/welcome/fresaarray/fresa5.JPG

Here you have to import fresaCellView class in FresaTableViewController.h .

http://www.dremsus.com/welcome/fresaarray/fresa6.JPG

http://www.dremsus.com/welcome/fresaarray/fresa6.JPG

This is fresatableViewController.m file . here you have to define your fresa content , Which will be appear in simulator

Since we are editing a table, all of these functions will be related to editing a table. So find the function called numberOfRowsInSection.

http://www.dremsus.com/welcome/4.JPG

http://www.dremsus.com/welcome/4.JPG

This function tells the application how many rows are in our table. Currently, it returns 0. Let’s change that to return no of content defined in array

Now go down to the function called cellForRowAtIndexPath. This function gets called once for every row. This is where we define what content to display in a given row. In this case we want the row to be a string that says.

http://www.dremsus.com/welcome/5.JPG

http://www.dremsus.com/welcome/5.JPG

What this function is doing is creating a new cell object and returning it. The code between the i(cell==null) block checks to see if we have created a cell before, if not build a new cell, otherwise use the one we created before. This helps in performance so we don’t need to build new cells each time we visit this function. So right before the // Set up the cell comment add the following code:

[call setLabelText:[arryData objectAtIndex:indexPath.row]];

http://www.dremsus.com/welcome/fresaarray/fresa8.JPG

http://www.dremsus.com/welcome/fresaarray/fresa8.JPG

  1. Now come to the main file Tutorial2_NsArrayAppDelegate.h and Tutorial2_NsArrayAppDelegate.m .

For displaying view to the main window you have to create navigationControll to mapped with the view.

Now You have to create User Interface to display the fresa content .

Process to Create View :-

1.GOTO –> Resource –>Add File –>View UI –>Add Label and ImageView

Now most important part to mapping with label and image. You have to mapped with the class .Here description text properties which is defined in fresaCellView.h class is mapped with label .

Process for User Interface :

  1. Now open Window.xib file.
  2. Drag and drop Navigation control to mainwindow.xib .
  3. Select Tutorial2_NsarrayAppdelegate class from Class identity.
  4. Now most important part here is that, You have to mapped navigationcontroller with the navigationControlle tab which you have selected from Library.

5.Now Call FresatableViewcontroller.xib file in View Controller properties . the screen will be look like this .

After Mapping Click the Build and Go button again to launch the iPhone simulator. You should see screen look like this and your content will display on the screen:

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

IPhone Tutorial2 -(View Based Application)

December 26th, 2009 by aabhaanjan

Hi All I will show you how to create “Welcome ” application using the interface builder . There are many way to create application in IPhone .IN this tutorial no need to write code at all .

Create a new View based Project

Process to Create Application

  1. Open XCode for creating a new View – Based Application .

Go -> File ->New Project and select View Based Application and name the project Welcome

I have already described in earlier tutorial,When you are creating application there are some additional file which I have already described . Here you can only see one view at a time, you will need to create a new view for each screen in your application.

Go ahead and click Build and Go.

Process to Create Application

1. Open XCode for creating a new View – Based Application .

2.Go -> File ->New Project and select View Based Application and name the project Welcome

I have already described in earlier tutorial,When you are creating application there are some additional file which I have already described . Here you can only see one view at a time, you will need to create a new view for each screen in your application.

Go ahead and click Build and Go.

The program will compile and launch the iPhone Simululator. Your screen should look something like this.

you want to display “WelCome to IPhone”. So let’s add some UI components to our view to make it more interesting. To do this we will be editing WelcomeViewsViewController.xib . A file with the .xib extension is known as a nib file. These files open with Interface Builder and are where you define the look and feel of your application. Apple is nice enough to have provided us with one.

Once you open Interface Builder, you should see a few different windows… You should see a blank window that says View. If not click the View icon in the smaller box. This is the main window we will be editing.

Just click on the one’s you want and drag them on to your view. Make sure you at least use a Label.

Executing the Code

Go ahead and click Build and Go again to launch the iPhone Simulator. Your screens should look something like this:

Once you open Interface Builder, you should see a few different windows… You should see a blank window that says View. If not click the View icon in the smaller box. This is the main window we will be editing.

Just click on the one’s you want and drag them on to your view. Make sure you at least use a Label.

Executing the Code

Go ahead and click Build and Go again to launch the iPhone Simulator. Your screens should look something like this:

If you have any questions, feel free to leave them in the comments.

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

CPU optimization for Games

August 9th, 2009 by

Hi All,

I got some important facts about memory optimization from my personal experience and various sources . Those are here :

1) Attaching moviclips: for loop vs. while loop
A typical game loop where you attach movieclips to a target mc.
Using the while loop instead of for results in better performance, and if you’re also
reading data from an array then the for in loop should be the best choice.

2) Read data from Array (for, for in, while)
Here we compared the three loops in reading data from an array and the for in is definetely the best way to go.

3) Write data to an array (for, while)
Writing data to an array also shows that the while loop performs better, even if this time the difference is less significant.

4) Single vs Multiple var declaration.
Whenever possible try to assign values to your variables using multiple assignment.
This can speed things up pretty nicely.
If you have in a loop something like this:

a = b = c = 0
d = e = 100

5) Var name lookup
This test shows how important is saving name lookup time especially when insidea looping structure.
Instead of calling Math.random() at every cycle, define a reference to it and use it in the loop, this will save you time because the function name is resolved once, before entering the loop.

Example:

var num = null
t = getTimer()
for (var i=0; i < MAX; i++)
{
        num = Math.floor(MAX) - Math.ceil(MAX)
}
t1.text = "Always lookup: " + (getTimer() - t)

is not as good as:

t = getTimer()
var floor = Math.floor
var ceil  = Math.ceil
for (var i=0; i < MAX; i++)
{
        num = floor(MAX) - ceil(MAX)
}

6) Short vs. Long variable names
Variable names should always be kept as short as possible.
In this test you can see how long named variables can negatively affect speed.
We suggest to use very short names (1 or 2 chars) when optimizing performance critical part of your code.

7) Declaring var in loops vs. declaring before loops
Before running this benchmark we thought that declaring a local var before a loop
structure could save some xtra time, but tests proved the exact contrary.

// Inside
t = getTimer()
for (var i=0; i < MAX; i++)
{
        var test1 = i
}
t1.text = "Inside:" + (getTimer() - t)
// Outside
t = getTimer()
var test2
for (var i=0; i < MAX; i++)
{
        test2 = i
}

8) Using nested if
Whenever using complex conditional expressions you can optimize the code by breaking them into single nested conditions.
This way you don’t have to evaluate all the expressions all the times.
The following code is what we used for the benchmark: even if the conditional expressions are pretty simple the speed increse is significant.
Also you can notice that the expression that evaluates as false is in 3rd position, so you may even get better performance when it is placed in 2nd or 1st position.

MAX = 20000
a = 1
b = 2
c = -3
d = 4
var i=MAX
while(--i > -1)
{
        if (a == 1 && b == 2 && c == 3 && d == 4)
        {
                 var k = d * c * b * a
        }
}
var i=MAX
while(--i > -1)
{
        if (a == 1)
        {
                 if (b == 2)
                 {
                          if (c == 3)
                          {
                                   if (d == 4)
                                   {
                                           var k = d * c * b * a
                                   }
                          }
                 }
        }
}

9) Nested loops (for vs. while)
Nested loops are a common programming technique to access 2 dimensional data, like map arrays in a tile based game, etc…
As you may expect from the previous tests the while loop performs better.

10). Accessing local vars (This vs. With vs. Reference)
Local variables and objects can be referenced in more than one way.
We’ve tested two ways to do it and found out that the usage of the keyword this produces the worst results.
More speed can be achieved using with operator.
The following code was used as a test, running a 10000 iteration loop

obj = {}
obj.a = 1
obj.b = 2
obj.c = 3
obj.d = 4
obj.e = 5
obj.f = 6
obj.g = 7
obj.h = 8
obj.test1 = useThis
obj.test2 = useWith
MAX = 10000
function useThis()
{
        var i = MAX
        while(--i > -1)
        {
                 this.a = 1
                 this.b = 2
                 this.c = 3
                 this.d = 4
                 this.e = 5
                 this.f = 6
                 this.g = 7
                 this.h = 8
        }
}
function useWith()
{
        var i = MAX
        while(--i > -1)
        {
                 with(this)
                 {
                          a = 1
                          b = 2
                          c = 3
                          d = 4
                          e = 5
                          f = 6
                          g = 7
                          h = 8
                 }
        }
}

Array indexing

Let’s start with a simple loop through the items of an array:

private function method1() : void

{

var tmpVar:int;

for(var i:Number=0; i<testArray.length; i++)

{

tmpVar = testArray[i];

}

}

Looping through this method 50 times gives an average time of 53.34 milliseconds. Now let’s change the type of iterator variable i from Number to int:

for(var i:int=0; i<testArray.length; i++)

This results in an average time of 35.58 milliseconds. This is because array indexing is faster with ints. We can also speed up the loop by storing the array’s length in a variable outside of the loop:

var l:int = testArray.length;

for(var i:int=0; i<l; i++)

Time taken: 21.6 milliseconds!

Constants from other classes

Another optimization that I found is in the way you use constants from another class. Take for instance this piece of code:

var tmpVar:int;

for(var i:Number=0; i<100000; i++)

{

tmpVar = SomeClass.SOME_CONSTANT;

}

This takes 34.08 milliseconds to execute. If we move the constant lookup outside of the iteration, like this:

var tmpVar:int;

var myConstant:int = SomeClass.SOME_CONSTANT;

for(var i:Number=0; i<100000; i++)

{

tmpVar = myConstant;

}

Now it only takes 15.8 milliseconds

Variable instantiation

Variable instantation in this fashion:

for(var i:int=0; i<100000; i++)

{

var v1:Number=10;

var v2:Number=10;

var v3:Number=10;

var v4:Number=10;

var v5:Number=10;

}

takes 46.52 millis. This can be speeded up if you use the “var” keyword one time and then declare the variables on a single line, like this:

for(var i:int=0; i<100000; i++)

{

var v1:Number=10, v2:Number=10, v3:Number=10, v4:Number=10, v5:Number=10;

}

which results in an average time of 19.74 milliseconds.

Bitwise operators

Bitwise operators can also increase performance. Take for instance multiplication and division:

for(var i:int=0; i<100000; i++)

{

var val1:int = 4 * 2;

var val2:int = 4 * 4;

var val3:int = 4 / 2;

var val4:int = 4 / 4;

}

Average time: 49.12 ms, using bitwise operators it is taken down to 35.56 ms:

for(var i:int=0; i<100000; i++)

{

var val1:int = 4 << 1;

var val2:int = 4 << 2;

var val3:int = 4 >> 1;

var val4:int = 4 >> 2;

}

Unnecessary import statements

Not the biggest time saver unless you are generating many instances of the class or the class has a large number of function calls made to it. However, it is a very easy way to improve performance.

Sprites and MovieClips

You only need to use the MovieClip type if the object has multiple frames, you can export for ActionScript Library objects extending the Sprite class instead of the MovieClip class.

Avoid using masks

If you need to mask a square area use the display object’s ’scrollRect’ property instead. If you need a shape that is not a square, place that shape over the object with the scrollRect property.

Disable events that you do not need

Dispatching events is one of the more expensive function calls that you can make. Every class that extends InteractiveObject (which encompasses every display object) generates a host of events that you most likely do not need. Take the time to set MouseEnabled and MouseChildren to false to keep your event system as clean as possible. Also, make sure to remove event listeners and onEnterFrame events when you no longer need them.

Limit your art assets attached to the stage

No sense in traversing render nodes if they are not actively being used. If it is an object that is not frequently visible I will completely destroy it and recreate it when it is needed again. The archetype to employ this strategy is menu systems

Resource management strategies in Flash Player 9

  • A game sprite subscribes to its own enterFrame event. In every frame it moves, the application performs some calculations to determine its proximity to other game elements. In ActionScript 3.0, even after you remove the sprite from the display list and null all references to it, the application continues to run that code in every frame until it is removed by garbage collection. You must remember to explicitly remove the enterFrame listener when the sprite is removed.
  • Consider a movie clip that follows the mouse by subscribing to the Stage’s mouseMove event—which is the only way to achieve this effect in the new event model. Unless you remember to remove the listener, the clip will continue to execute code every time the mouse is moved, even after the clip is “deleted.” By default, the clip executes forever because a reference to it exists from the Stage for event dispatch. I will discuss how to avoid this issue in a future article.

import flash.system.System;

import flash.net.navigateToURL;

import flash.net.URLRequest;

// check our memory every 1 second:

var checkMemoryIntervalID:uint = setInterval(checkMemoryUsage,1000);

var showWarning:Boolean = true;

var warningMemory:uint = 1000*1000*500;

var abortMemory:uint = 1000*1000*625;

function checkMemoryUsage() {

if (System.totalMemory > warningMemory && showWarning) {

// show an error to the user warning them that we’re running out of memory and might quit

// try to free up memory if possible

showWarning = false; // so we don’t show an error every second

} else if (System.totalMemory > abortMemory) {

// save current user data to an LSO for recovery later?

abort();

}

}

function abort() {

// send the user to a page explaining what happpened:

navigateToURL(new URLRequest(“memoryError.html”));

}

Array & Object constructing

new Array() and new Object() are about 3 times slower than [] and {}.

Index Number type for Arrays

list[int(0)] is now faster than list[0]!

Nulling Array vs. Splicing Array

When working with large Arrays splicing is obviously an expensive operation, you can avoid this by nulling the index and skipping it in a null scenario. If you need to splice in order to keep the Array length low. Then store these nulled indexes in another trash Array once the garbage count has reached a limit you’ve defined loop through the numerically sorted trash indexes deleting splices in bulk. This concept is demonstrated in Tweensy.

Array push vs. Array index

Don’t use the push function on an Array instead use the Array length property and set on the Array like so list[list.length] = data; Or if that’s not enough for the best performance (about 600% faster) than using push don’t use the Array length property at all. To do this keep the Array length as an external variable and increment/decrement it as you add and remove items from the Array.

Array emptying – length 0 vs. A new Array

If you need to empty an Array there is a handy option to do this via setting the Arrays property length to 0. You would think this would be the better option as you are avoiding creating a new Array and ultimately saving memory. Though it’s interesting to know as a trade off using length to clear an Array is not faster in performance (in most cases). Using length is more efficient when you might need to clear more than 510 Arrays in a single execution, otherwise creating a new Array via [] is the faster option again.

Var declarations on multiple lines vs. Var declarations on a single line

If you need to declare a few variables it’s slightly more efficient to do so on a single line i.e.
var a:int=0, b:int=0, c:int=0;
vs.
var a:int=0;
var b:int=0;
var c:int=0;

Using Xor to swap variables

Using Xor is very handy if you want to swap variables but don’t want to create a third variable i.e.

a = a^b;
b = a^b;
a = a^b;
Like most people I thought this would be more efficient but it’s not compared to creating a third variable and then doing the swap. In fact it’s about 300% more efficient to do the swap this way. Though honestly I still have a soft spot for the Xor method.

var oldB:int = b;
b = a;
a = oldB;

Multiplication vs. Division

When working with Math in Actionscript multiplications seem to always run faster than divisions so instead of 5000/1000 use 5000*0.001 it’s about 130% faster.

Type casting comparison

When type casting the keyword as is 250% more efficient than casting by Type(item); Though surprisingly not using either is about 1400% more efficient.

Long vs Short variable names

Though this one is debatable because it results in illegible code. Shortened variable names do give a millisecond or so improvement if iterating many 1,000’s of times in a single loop. Though I think this is a last resort in code optimization as the differences are really marginal.


Tags: , , , , , , , , ,