use of suite.sample.Profiler in project suite by stupidsing.
the class UctTest method testUctGame.
@Test
public void testUctGame() {
new Profiler().profile(() -> {
DecimalFormat df = new DecimalFormat("0.000");
// 20000
int nSimulations = 5000;
int boundedTime = 300000;
int seed = new Random().nextInt();
System.out.println("RANDOM SEED = " + seed);
ShuffleUtil.setSeed(seed);
Board board = new Board();
GameSet gameSet = new GameSet(board, Occupation.BLACK);
while (true) {
GameSet gameSet1 = new GameSet(gameSet);
UctVisitor<Coordinate> visitor = UctWeiqi.newVisitor(gameSet1);
UctSearch<Coordinate> search = new UctSearch<>(visitor);
search.setNumberOfThreads(Constants.nThreads);
search.setNumberOfSimulations(nSimulations);
search.setBoundedTime(boundedTime);
Stopwatch<Coordinate> timed = Stopwatch.of(search::search);
Coordinate move = timed.result;
if (move == null)
break;
Occupation player = gameSet.getNextPlayer();
search.dumpPrincipalVariation();
System.out.println(//
player + " " + //
move + " " + //
df.format(search.getWinningChance()) + " " + timed.duration + "ms");
gameSet.play(move);
UserInterface.display(gameSet);
}
});
}
use of suite.sample.Profiler in project suite by stupidsing.
the class RunUtil method run.
public static void run(Class<? extends ExecutableProgram> clazz, String[] args, RunOption runOption) {
LogUtil.initLog4j(Level.INFO);
IntMutable mutableCode = IntMutable.nil();
IntSource source = () -> {
try {
try (ExecutableProgram main_ = Object_.new_(clazz)) {
return main_.run(args) ? 0 : 1;
}
} catch (Throwable ex) {
ex.printStackTrace();
LogUtil.fatal(ex);
return 2;
}
};
Runnable runnable = () -> mutableCode.set(source.source());
switch(runOption) {
case PROFILE:
new Profiler().profile(runnable);
break;
case RUN____:
runnable.run();
break;
case TIME___:
LogUtil.duration(clazz.getSimpleName(), () -> {
runnable.run();
return Boolean.TRUE;
});
}
int code = mutableCode.get();
if (code != 0)
System.exit(code);
}
use of suite.sample.Profiler in project suite by stupidsing.
the class B_TreeTest method testInsertPerformance.
@Test
public void testInsertPerformance() throws IOException {
int nKeys = 16384;
keys = Ints_.toArray(nKeys, i -> i);
int pageSize = 4096;
Path path = Constants.tmp("b_tree-file");
for (int i = 0; i < nKeys; i++) {
int j = random.nextInt(nKeys);
Integer temp = keys[i];
keys[i] = keys[j];
keys[j] = temp;
}
Files.deleteIfExists(path);
B_TreeBuilder<Integer, Bytes> builder = new B_TreeBuilder<>(serialize.int_, serialize.bytes(64));
try (JournalledPageFile jpf = JournalledFileFactory.journalled(path, pageSize);
B_Tree<Integer, Bytes> b_tree = builder.build(jpf, comparator, 9999)) {
new Profiler().profile(() -> {
b_tree.create();
for (int i = 0; i < nKeys; i++) {
int key = keys[i];
b_tree.put(key, To.bytes(Integer.toString(key)));
}
jpf.commit();
jpf.sync();
});
}
}
Aggregations