[Home]WritingFastCode

Robo Home | Changes | Preferences | AllPages

This is a collection of tips on how to write fast code so you won't have a SlowBot.

General tips:

Fast code snippets

Methode calls
Modefierswithout JITJIT
public 5650 280
public with 4 parameters 7800 390
public static 5060 110
protected 5770 280
private 5820 50
public synchronized 9500 4660
public final 6260 50

using JDK 1.2Beta 4 on Pentium II-266MHz under Win95

See also


If you dont use multithreading in your bot you should better use ArrayList -Objects instead of LinkedLists? or even Vectors as they dont have synchronized access. --deathcon

Actually LinkedList is not synchronized (at least in java 1.4.2). I use it sometimes when i need a FIFO structure, since i think that the necessary insert- and remove-operations should be very fast there. Never tested whether its truly faster than using an ArrayList though :-) --Mue

David A, can you give a brief description of how to setup the Eclipse profiler for use with robocode? I cant understand how you can profile an external application. Thanks in advance, --wolfman

Try using this: https://sourceforge.net/projects/eclipsecolorer/ Extract to your plugins directory then go to "Run..." and you can configure the profiler. Let me know if you run into problems. -- David Alves

Erm .... but im not running Robocode from inside of eclipse, so how do I profile it? I dont "run" anything from inside eclipse .... I just use it to compile my robot. So how do I profile from within eclipse? --Wolfman

As much as I like FastBots? I get a bit uneasy when reading tips like those above. (Well, the tips about using a profiler is excellent, but the rest...) I think the general advice should be to avoid optimizing for speed. It tends to make the code less fexible and a few months from now the speed optimizations might show to have the opposite result. Like if your general structure changes or the Java distribution comes with surprises. In fact it might be that your JVM and Java environment isn't the same as the one where the most battles are run by RR@H clients.

I don't recommend optimizing your entire bot for speed, only a few lines on the inside of loops that are called thousands of times per turn. --David Alves

David, I do appreciate you've started a page about speeding up our bots. I'm just adding that I think the general approach should be to not optimize for speed. Optimize for clarity and speed will follow in most cases. And when it doesn't, at least it's clear where to apply speed tricks. -- PEZ

Agreed. I've only spent time speeding up 20 lines of code on Phoenix out of a total of 1441. For the vast majority of the code clarity is more important, but for a few critical lines it's worth optimizing. --David Alves

Added a table where u can see the times, different methode-calls use (waste :D). It's quite old but should give a reasonable overview. Perhaps i find a newer version i can add. --deathcon


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited November 4, 2004 13:57 EST by Deathcon (diff)
Search: