C# vs Java
Bunnies is currently being developed in Java but that might change. I put together a quick “Lesson 1″ for C# which just renders 320×240 pixels every second. My Dual Core 2.33Ghz system pumped out 170+ frames per second which works out to about 13.5 million pixels per second. Since I don’t have the Java SDK on this system I had to go by the Lesson 1 tutorial for Java posted in the Software Rendering section. At 1.7Ghz I was able to pump out about 4 million pixels per second. Scaled for processing speed it should perform at about 5.5 million pixels per second. So that makes C# about 2.4 times faster than Java.
I was digging around on-line for some tutorials on how to create a main loop in C#. Not a simple task. There’s the C# way to do it which is slow and there’s the “make it act like C++” way which is much better. Anyway, in the code I found there was a
System.Threading.Thread.Sleep(10);
Well, that limited the frame rate to about 64fps. It didn’t matter what resolution I was drawing pixels at. Changing it to
System.Threading.Thread.Sleep(0);
bumped the frame rate up to 172/173. “Sleep” in C++ and C# achieve the same thing, they allow the CPU to do a context switch so the CPU can process other things your computer may be doing. Giving it a number greater than 0 simply causes an artificial delay in your program which limits performance and doesn’t make your computer any more responsive while your program is running.
We’ll see how ambitious I am. My new server will be here later this week. So this weekend I’ll be putting that together and getting the latest Java version of Bunnies on-line along with the Bunnies server. Once that’s done I may call it a day with Java and switch to C# to enhance Bunnies even further.
Leave a comment
You must be logged in to post a comment.