Skip to content

Instantly share code, notes, and snippets.

@shannah
Created December 7, 2012 01:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/4229924 to your computer and use it in GitHub Desktop.
Save shannah/4229924 to your computer and use it in GitHub Desktop.
Benchmark after changing to object methods.
protected void onMain_BtnTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
public void run() {
final TowersOfHanoi h = new TowersOfHanoi();
long start = System.currentTimeMillis();
h.move(30, 1, 3);
long end = System.currentTimeMillis();
calculationTime = end - start;
isCalculatingHanoi = false;
Display.getInstance().callSerially(new Runnable(){
public void run() {
towerOfHanoiLabel.setText("Calculation took "+calculationTime+"ms (counter "+h.counter+")");
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment