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);
}
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();
}
});
}
}
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);
}
}
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));
}
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);
}
Aggregations