Search in sources :

Example 1 with BeforeExperiment

use of com.google.caliper.BeforeExperiment in project buck by facebook.

the class ParserBenchmark method setUpBenchmark.

@BeforeExperiment
public void setUpBenchmark() throws Exception {
    tempDir.before();
    Path root = tempDir.getRoot();
    Files.createDirectories(root);
    filesystem = new ProjectFilesystem(root);
    Path fbJavaRoot = root.resolve(root.resolve("java/com/facebook"));
    Files.createDirectories(fbJavaRoot);
    for (int i = 0; i < targetCount; i++) {
        Path targetRoot = fbJavaRoot.resolve(String.format("target_%d", i));
        Files.createDirectories(targetRoot);
        Path buckFile = targetRoot.resolve("BUCK");
        Files.createFile(buckFile);
        Files.write(buckFile, ("java_library(name = 'foo', srcs = ['A.java'])\n" + "genrule(name = 'baz', out = '')\n").getBytes("UTF-8"));
        Path javaFile = targetRoot.resolve("A.java");
        Files.createFile(javaFile);
        Files.write(javaFile, String.format("package com.facebook.target_%d; class A {}", i).getBytes("UTF-8"));
    }
    ImmutableMap.Builder<String, ImmutableMap<String, String>> configSectionsBuilder = ImmutableMap.builder();
    if (threadCount > 1) {
        configSectionsBuilder.put("project", ImmutableMap.of("parallel_parsing", "true", "parsing_threads", Integer.toString(threadCount)));
    }
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(configSectionsBuilder.build()).build();
    cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    eventBus = BuckEventBusFactory.newInstance();
    executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
    DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller marshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    parser = new Parser(new BroadcastEventListener(), config.getView(ParserConfig.class), typeCoercerFactory, marshaller);
}
Also used : Path(java.nio.file.Path) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 2 with BeforeExperiment

use of com.google.caliper.BeforeExperiment in project guava by google.

the class ExecutionListBenchmark method setUp.

@BeforeExperiment
void setUp() throws Exception {
    executorService = new ThreadPoolExecutor(NUM_THREADS, NUM_THREADS, Long.MAX_VALUE, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));
    executorService.prestartAllCoreThreads();
    final AtomicInteger integer = new AtomicInteger();
    // Execute a bunch of tasks to ensure that our threads are allocated and hot
    for (int i = 0; i < NUM_THREADS * 10; i++) {
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                integer.getAndIncrement();
            }
        });
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Footprint(com.google.caliper.api.Footprint) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 3 with BeforeExperiment

use of com.google.caliper.BeforeExperiment in project guava by google.

the class MoreExecutorsDirectExecutorBenchmark method before.

@BeforeExperiment
void before() {
    executor = impl.executor();
    for (int i = 0; i < 4; i++) {
        Thread thread = new Thread() {

            @Override
            public void run() {
                CountingRunnable localRunnable = new CountingRunnable();
                while (!isInterrupted()) {
                    executor.execute(localRunnable);
                }
                countingRunnable.integer.addAndGet(localRunnable.integer.get());
            }
        };
        threads.add(thread);
    }
}
Also used : Footprint(com.google.caliper.api.Footprint) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 4 with BeforeExperiment

use of com.google.caliper.BeforeExperiment in project guava by google.

the class StripedBenchmark method setUp.

@BeforeExperiment
void setUp() {
    this.striped = impl.get(numStripes);
    stripes = new int[numStripes];
    for (int i = 0; i < numStripes; i++) {
        stripes[i] = i;
    }
    List<Integer> asList = Ints.asList(stripes);
    Collections.shuffle(asList, new Random(0xdeadbeef));
    // do bulk gets with exactly 10 keys (possibly <10 stripes) (or less if numStripes is smaller)
    bulkGetSet = ImmutableList.copyOf(limit(cycle(asList), 10));
}
Also used : Random(java.util.Random) Footprint(com.google.caliper.api.Footprint) BeforeExperiment(com.google.caliper.BeforeExperiment)

Example 5 with BeforeExperiment

use of com.google.caliper.BeforeExperiment in project guava by google.

the class ChecksumBenchmark method setUp.

@BeforeExperiment
void setUp() {
    testBytes = new byte[size];
    new Random(RANDOM_SEED).nextBytes(testBytes);
}
Also used : Random(java.util.Random) BeforeExperiment(com.google.caliper.BeforeExperiment)

Aggregations

BeforeExperiment (com.google.caliper.BeforeExperiment)28 Random (java.util.Random)13 SpannableString (android.text.SpannableString)5 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 PrintWriter (java.io.PrintWriter)5 Footprint (com.google.caliper.api.Footprint)3 BitSet (java.util.BitSet)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)1 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)1 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 GetCheckedTypeValidator (com.google.common.util.concurrent.FuturesGetChecked.GetCheckedTypeValidator)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1