mirror of
https://github.com/correl/mage.git
synced 2025-04-14 01:01:08 -09:00
Some performance measurement. Game state copying performance is good.
This commit is contained in:
parent
9a7d158a20
commit
c02d453a4b
3 changed files with 50 additions and 0 deletions
Mage.Tests/src/test/java/org/mage/test
Mage/src/mage/game
|
@ -4,6 +4,7 @@ import junit.framework.Assert;
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.counters.Counter;
|
import mage.counters.Counter;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
|
import mage.game.GameImpl;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mage.test.serverside.base.CardTestBase;
|
import org.mage.test.serverside.base.CardTestBase;
|
||||||
|
@ -36,5 +37,8 @@ public class LevelUpAbilityTest extends CardTestBase {
|
||||||
Assert.assertNotNull(master.getCounters());
|
Assert.assertNotNull(master.getCounters());
|
||||||
Assert.assertFalse(master.getCounters().isEmpty());
|
Assert.assertFalse(master.getCounters().isEmpty());
|
||||||
Assert.assertEquals(12, master.getCounters().getCount(CounterType.LEVEL));
|
Assert.assertEquals(12, master.getCounters().getCount(CounterType.LEVEL));
|
||||||
|
|
||||||
|
System.out.println("Copy count: " + GameImpl.copyCount);
|
||||||
|
System.out.println("Copy time: " + GameImpl.copyTime + " ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package org.mage.test.serverside.performance;
|
||||||
|
|
||||||
|
import mage.game.Game;
|
||||||
|
import org.mage.test.serverside.base.CardTestBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for copying game state.
|
||||||
|
*
|
||||||
|
* @ayratn
|
||||||
|
*/
|
||||||
|
public class CopyGameStatePerformanceTest extends CardTestBase {
|
||||||
|
|
||||||
|
public void run() throws Exception {
|
||||||
|
init();
|
||||||
|
reset();
|
||||||
|
System.out.println("Started copying...");
|
||||||
|
long t1 = System.currentTimeMillis();
|
||||||
|
for (int i = 0; i < 2000; i++) {
|
||||||
|
Game game = currentGame.copy();
|
||||||
|
Game game2 = game.copy();
|
||||||
|
}
|
||||||
|
long t2 = System.currentTimeMillis();
|
||||||
|
System.out.println("Test took: " + (t2-t1) + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
CopyGameStatePerformanceTest test = new CopyGameStatePerformanceTest();
|
||||||
|
try {
|
||||||
|
test.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -105,6 +105,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
protected MultiplayerAttackOption attackOption;
|
protected MultiplayerAttackOption attackOption;
|
||||||
protected GameOptions gameOptions;
|
protected GameOptions gameOptions;
|
||||||
|
|
||||||
|
public static volatile int copyCount = 0;
|
||||||
|
public static volatile long copyTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract T copy();
|
public abstract T copy();
|
||||||
|
|
||||||
|
@ -116,6 +119,10 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameImpl(final GameImpl<T> game) {
|
public GameImpl(final GameImpl<T> game) {
|
||||||
|
long t1 = 0;
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
t1 = System.currentTimeMillis();
|
||||||
|
}
|
||||||
this.id = game.id;
|
this.id = game.id;
|
||||||
this.ready = game.ready;
|
this.ready = game.ready;
|
||||||
this.startingPlayerId = game.startingPlayerId;
|
this.startingPlayerId = game.startingPlayerId;
|
||||||
|
@ -131,6 +138,10 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
this.simulation = game.simulation;
|
this.simulation = game.simulation;
|
||||||
this.gameOptions = game.gameOptions;
|
this.gameOptions = game.gameOptions;
|
||||||
this.lki.putAll(game.lki);
|
this.lki.putAll(game.lki);
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
copyCount++;
|
||||||
|
copyTime += (System.currentTimeMillis() - t1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue