Search in sources :

Example 1 with Profiler

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);
        }
    });
}
Also used : DecimalFormat(java.text.DecimalFormat) UctSearch(suite.uct.UctSearch) Occupation(suite.weiqi.Weiqi.Occupation) Profiler(suite.sample.Profiler) Random(java.util.Random) Test(org.junit.Test)

Example 2 with Profiler

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);
}
Also used : Profiler(suite.sample.Profiler) IntSource(suite.primitive.IntPrimitives.IntSource) IntMutable(suite.primitive.IntMutable)

Example 3 with Profiler

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();
        });
    }
}
Also used : Object_(suite.util.Object_) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) Files(java.nio.file.Files) Constants(suite.Constants) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) IOException(java.io.IOException) Random(java.util.Random) Test(org.junit.Test) To(suite.util.To) Serialize(suite.util.Serialize) JournalledPageFile(suite.file.JournalledPageFile) Pair(suite.adt.pair.Pair) Assert.assertNull(org.junit.Assert.assertNull) Ints_(suite.primitive.Ints_) Comparator(java.util.Comparator) Path(java.nio.file.Path) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) JournalledFileFactory(suite.file.impl.JournalledFileFactory) Path(java.nio.file.Path) Bytes(suite.primitive.Bytes) Profiler(suite.sample.Profiler) B_TreeBuilder(suite.btree.impl.B_TreeBuilder) JournalledPageFile(suite.file.JournalledPageFile) Test(org.junit.Test)

Aggregations

Profiler (suite.sample.Profiler)3 Random (java.util.Random)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 DecimalFormat (java.text.DecimalFormat)1 Comparator (java.util.Comparator)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1 Before (org.junit.Before)1 Constants (suite.Constants)1 Pair (suite.adt.pair.Pair)1 B_TreeBuilder (suite.btree.impl.B_TreeBuilder)1 JournalledPageFile (suite.file.JournalledPageFile)1 JournalledFileFactory (suite.file.impl.JournalledFileFactory)1 Bytes (suite.primitive.Bytes)1 IntMutable (suite.primitive.IntMutable)1 IntSource (suite.primitive.IntPrimitives.IntSource)1 Ints_ (suite.primitive.Ints_)1