com.google.caliper.BeforeExperiment Java Examples

The following examples show how to use com.google.caliper.BeforeExperiment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoProfilerBenchmark.java    From bazel with Apache License 2.0 6 votes vote down vote up
@BeforeExperiment
void startProfiler() throws Exception {
  Profiler.instance()
      .start(
          ImmutableSet.copyOf(ProfilerTask.values()),
          new InMemoryFileSystem().getPath("/out.dat").getOutputStream(),
          Profiler.Format.JSON_TRACE_FILE_FORMAT,
          "dummy_output_base",
          UUID.randomUUID(),
          false,
          BlazeClock.instance(),
          BlazeClock.instance().nanoTime(),
          /* enabledCpuUsageProfiling= */ false,
          /* slimProfile= */ false,
          /* includePrimaryOutput= */ false,
          /* includeTargetLabel= */ false);
}
 
Example #2
Source File: CacheBenchmark.java    From buck with Apache License 2.0 6 votes vote down vote up
@BeforeExperiment
public void setUpBenchmark() {
  while (leaves.size() < leavesCount) {
    String path = folders.get(random.nextInt(folders.size()));
    // create a folder? 25% chance of doing so.
    if (random.nextInt(4) == 0) {
      path += generateRandomString() + "/";
      // is it a leaf?
      if (random.nextBoolean()) {
        leaves.add(path);
      }
      folders.add(path);
    } else {
      // it's a file.
      path += generateRandomString() + ".txt";
      leaves.add(path);
    }
  }
}
 
Example #3
Source File: CaliperSpiderBenchmark.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@BeforeExperiment
@SuppressWarnings("unused")
void create()
    throws IOException
{
    cx = Context.enter();
    cx.setOptimizationLevel(optLevel);
    cx.setLanguageVersion(Context.VERSION_ES6);
    scope = new Global(cx);

    for (String bn : BENCHMARKS) {
        compileScript(cx, bn);
    }
}
 
Example #4
Source File: CaliperObjectBenchmark.java    From rhino-android with Apache License 2.0 5 votes vote down vote up
@BeforeExperiment
@SuppressWarnings("unused")
void create()
    throws IOException
{
    cx = Context.enter();
    cx.setOptimizationLevel(optLevel);
    cx.setLanguageVersion(Context.VERSION_ES6);

    scope = new Global(cx);
    runCode(cx, scope, "testsrc/benchmarks/caliper/fieldTests.js");

    Object[] sarray = new Object[stringKeys];
    for (int i = 0; i < stringKeys; i++) {
        int len = rand.nextInt(49) + 1;
        char[] c = new char[len];
        for (int cc = 0; cc < len; cc++) {
            c[cc] = (char) ('a' + rand.nextInt(25));
        }
        sarray[i] = new String(c);
    }
    strings = cx.newArray(scope, sarray);

    Object[] iarray = new Object[intKeys];
    for (int i = 0; i < intKeys; i++) {
        iarray[i] = rand.nextInt(10000);
    }
    ints = cx.newArray(scope, iarray);
}
 
Example #5
Source File: SQLiteArtifactCacheBenchmark.java    From buck with Apache License 2.0 5 votes vote down vote up
@BeforeExperiment
private void setUpBenchmark() throws IOException, SQLException {
  artifactCache = cache(Optional.of(1024 * 1024 * 1024L));
  byte[] randomRuleKey = new byte[16];

  ruleKeys = new ArrayList<>(opCount);
  contentHashes = new ArrayList<>(opCount);
  metadataInfo = new ArrayList<>(opCount);
  contentInfo = new ArrayList<>(opCount);

  for (int i = 0; i < opCount; i++) {
    random.nextBytes(randomRuleKey);
    RuleKey ruleKey = new RuleKey(HashCode.fromBytes(randomRuleKey));
    ruleKeys.add(ruleKey);
    metadataInfo.add(
        ArtifactInfo.builder()
            .addRuleKeys(ruleKey)
            .putMetadata(TwoLevelArtifactCacheDecorator.METADATA_KEY, "foo")
            .putMetadata(BuildInfo.MetadataKey.RULE_KEY, ruleKey.toString())
            .putMetadata(BuildInfo.MetadataKey.TARGET, "bar")
            .build());

    random.nextBytes(randomRuleKey);
    RuleKey contentHash = new RuleKey(HashCode.fromBytes(randomRuleKey));
    contentHashes.add(contentHash);
    contentInfo.add(ArtifactInfo.builder().addRuleKeys(contentHash).build());
  }
}
 
Example #6
Source File: XmlParsingBenchmark.java    From tikxml with Apache License 2.0 4 votes vote down vote up
@BeforeExperiment
public void setUp() throws Exception {
    xmlSmall = loadResource("small.xml");
    xmlMedium = loadResource("medium.xml");
}
 
Example #7
Source File: AutoProfilerBenchmark.java    From bazel with Apache License 2.0 4 votes vote down vote up
@BeforeExperiment
void stopProfiler() throws Exception {
  Profiler.instance().stop();
}
 
Example #8
Source File: ParserBenchmark.java    From buck with Apache License 2.0 4 votes vote down vote up
@BeforeExperiment
private void setUpBenchmark() throws Exception {
  tempDir.before();
  Path root = tempDir.getRoot();
  Files.createDirectories(root);
  filesystem = TestProjectFilesystems.createProjectFilesystem(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(StandardCharsets.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(StandardCharsets.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();
  executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount));
  parser = TestParserFactory.create(executor, cell.getRootCell());
}