当前位置: 首页>>代码示例>>Java>>正文


Java BeforeExperiment类代码示例

本文整理汇总了Java中com.google.caliper.BeforeExperiment的典型用法代码示例。如果您正苦于以下问题:Java BeforeExperiment类的具体用法?Java BeforeExperiment怎么用?Java BeforeExperiment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeforeExperiment类属于com.google.caliper包,在下文中一共展示了BeforeExperiment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@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++) {
    @SuppressWarnings("unused") // go/futurereturn-lsc
    Future<?> possiblyIgnoredError =
        executorService.submit(
            new Runnable() {
              @Override
              public void run() {
                integer.getAndIncrement();
              }
            });
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:ExecutionListBenchmark.java

示例2: addOtherEntries

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
void addOtherEntries() throws Exception {
  GetCheckedTypeValidator validator = this.validator.validator;
  Class<? extends Exception> exceptionType = this.exceptionType.exceptionType;

  for (Class<? extends Exception> exceptionClass :
        OTHER_EXCEPTION_TYPES.asList().subList(0, otherEntriesInDataStructure)) {
    getChecked(validator, immediateFuture(""), exceptionClass);
  }

  for (int i = 0; i < otherEntriesInDataStructure; i++) {
    ClassValue<Boolean> classValue =
        new ClassValue<Boolean>() {
          @Override
          protected Boolean computeValue(Class<?> type) {
            return true;
          }
        };
    classValue.get(exceptionType);
    retainedReferencesToOtherClassValues.add(classValue);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:23,代码来源:FuturesGetCheckedBenchmark.java

示例3: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  random = new Random(0xdeadbeef);  // fix the seed so results are comparable across runs

  int nonAlpha = size / nonAlphaRatio;
  int alpha = size - nonAlpha;

  List<Character> chars = Lists.newArrayListWithCapacity(size);
  for (int i = 0; i < alpha; i++) {
    chars.add(randomAlpha());
  }
  for (int i = 0; i < nonAlpha; i++) {
    chars.add(randomNonAlpha());
  }
  Collections.shuffle(chars, random);
  char[] array = Chars.toArray(chars);
  this.testString = new String(array);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:AsciiBenchmark.java

示例4: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
void setUp() {
  Random random = new Random(randomSeed);
  xInts = new int[SAMPLE_SIZE];
  yInts = new int[SAMPLE_SIZE];
  xLongs = new long[SAMPLE_SIZE];
  yLongs = new long[SAMPLE_SIZE];
  constant = new int[SAMPLE_SIZE];
  for (int i = 0; i < SAMPLE_SIZE; i++) {
    xInts[i] = random.nextInt(Integer.MAX_VALUE);
    yInts[i] = random.nextInt(Integer.MAX_VALUE);
    xLongs[i] = random.nextLong() & NONNEGATIVE_LONG_MASK;
    yLongs[i] = random.nextLong() & NONNEGATIVE_LONG_MASK;
    constant[i] = random.nextInt();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:LessThanBenchmark.java

示例5: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  if (emptySetProportion + singletonSetProportion > 1.01) {
    throw new SkipThisScenarioException();
  }

  Random rng = new Random();
  for (int i = 0; i < 0x1000; i++) {
    double setSize = rng.nextDouble();
    if (setSize < emptySetProportion) {
      sets[i] = ImmutableSet.of();
    } else if (setSize < emptySetProportion + singletonSetProportion) {
      sets[i] = ImmutableSet.of(PRESENT);
    } else {
      sets[i] = ImmutableSet.of(PRESENT, new Object());
    }

    if (rng.nextDouble() < hitRate) {
      queries[i] = PRESENT;
    } else {
      queries[i] = ABSENT;
    }
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:MultipleSetContainsBenchmark.java

示例6: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  hashMultiset = HashMultiset.create(size);
  linkedHashMultiset = LinkedHashMultiset.create(size);
  treeMultiset = TreeMultiset.create();

  Random random = new Random();

  int sizeRemaining = size;

  // TODO(kevinb): generate better test contents for multisets
  for (int i = 0; sizeRemaining > 0; i++) {
    // The JVM will return interned values for small ints.
    Integer value = random.nextInt(1000) + 128;
    int count = Math.min(random.nextInt(10) + 1, sizeRemaining);
    sizeRemaining -= count;
    hashMultiset.add(value, count);
    linkedHashMultiset.add(value, count);
    treeMultiset.add(value, count);
  }

  //TODO(kevinb): convert to assert once benchmark tests enable asserts by default
  Preconditions.checkState(hashMultiset.size() == size);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:MultisetIteratorBenchmark.java

示例7: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
void setUp() throws Exception {
  Random r = new Random();
  ba1 = new byte[length];
  r.nextBytes(ba1);
  ba2 = Arrays.copyOf(ba1, ba1.length);
  // Differ at the last element
  ba3 = Arrays.copyOf(ba1, ba1.length);
  ba4 = Arrays.copyOf(ba1, ba1.length);
  ba3[ba1.length - 1] = (byte) 43;
  ba4[ba1.length - 1] = (byte) 42;

  javaImpl = UnsignedBytes.lexicographicalComparatorJavaImpl();
  unsafeImpl =
      UnsignedBytes.LexicographicalComparatorHolder.UnsafeComparator.INSTANCE;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:UnsignedBytesBenchmark.java

示例8: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  testBytesA = new byte[size];
  random.nextBytes(testBytesA);
  testBytesB = Arrays.copyOf(testBytesA, size);
  int indexToDifferAt = -1;
  switch (whereToDiffer) {
    case ONE_PERCENT_IN:
      indexToDifferAt = (int) (size * 0.01);
      break;
    case LAST_BYTE:
      indexToDifferAt = size - 1;
      break;
    case NOT_AT_ALL:
  }
  if (indexToDifferAt != -1) {
    testBytesA[indexToDifferAt] = (byte) (testBytesB[indexToDifferAt] - 1);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:HashCodeBenchmark.java

示例9: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  // random integers will be generated in this range, then raised to the
  // power of (1/concentration) and floor()ed
  max = Ints.checkedCast((long) Math.pow(distinctKeys, concentration));

  cache = CacheBuilder.newBuilder()
      .concurrencyLevel(segments)
      .maximumSize(maximumSize)
      .build(
          new CacheLoader<Integer, Integer>() {
            @Override public Integer load(Integer from) {
              return (int) misses.incrementAndGet();
            }
          });

  // To start, fill up the cache.
  // Each miss both increments the counter and causes the map to grow by one,
  // so until evictions begin, the size of the map is the greatest return
  // value seen so far
  while (cache.getUnchecked(nextRandomKey()) < maximumSize) {}

  requests.set(0);
  misses.set(0);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:LoadingCacheSingleThreadBenchmark.java

示例10: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@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();
      }
    });
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:18,代码来源:ExecutionListBenchmark.java

示例11: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
void setUp() {
  String component = Strings.repeat("a", componentLength);
  String[] raw = new String[count];
  Arrays.fill(raw, component);
  components = Arrays.asList(raw);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:JoinerBenchmark.java

示例12: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
@SuppressWarnings("unchecked")
void setUp() throws ClassNotFoundException {
  Preconditions.checkArgument(hitRate >= 0 && hitRate <= 1,
      "hitRate must be in the range [0,1]");

  enumType = (Class<? extends Enum>)
      Class.forName(EnumsBenchmark.class.getCanonicalName() + "$" + enumSize + "Enum");

  Enum<?>[] allConstants = enumType.getEnumConstants();
  List<String> hits = new ArrayList<String>();
  for (int i = 0; i < hitRate * 256 / 3; ++i) {
    hits.add(allConstants[0].name());
    hits.add(allConstants[allConstants.length / 2].name());
    hits.add(allConstants[allConstants.length - 1].name());
  }

  List<String> misses = new ArrayList<String>();
  for (int i = 0; i < 256 - hits.size(); ++i) {
    misses.add("INVALID");
  }

  List<String> sampleDataList = new ArrayList<String>();
  sampleDataList.addAll(hits);
  sampleDataList.addAll(misses);
  Collections.shuffle(sampleDataList);
  sampleData = sampleDataList.toArray(new String[sampleDataList.size()]);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:EnumsBenchmark.java

示例13: doBefore

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
public void doBefore() {
  recursionCount = stackDepth - new Throwable().getStackTrace().length - 1;
  if (recursionCount < 0) {
    throw new SkipThisScenarioException();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:LazyStackTraceBenchmark.java

示例14: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment void setUp() {
  this.matcher = precomputed ? config.matcher.precomputed() : config.matcher;
  if (size == Size.SMALL) {
    BitSet tmp = new BitSet();
    matcher.setBits(tmp);
    int matchedCharCount = tmp.cardinality();
    this.matcher = SmallCharMatcher.from(tmp, "");
  }
  this.string = checkString(length, percent, config.matchingChars,
      new Random(), forceSlow, web);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CharMatcherBenchmark.java

示例15: setUp

import com.google.caliper.BeforeExperiment; //导入依赖的package包/类
@BeforeExperiment
protected void setUp() {
  BitSet bitSet = new BitSet();
  for (int i = 0; i < OLD_WHITESPACE_TABLE.length(); i++) {
    bitSet.set(OLD_WHITESPACE_TABLE.charAt(i));
  }
  bitSet.clear(0);
  bitSet.clear(1);
  matcher = useNew ? CharMatcher.whitespace() : OLD_WHITESPACE;
  teststring = newTestString(new Random(1), bitSet, percentMatching);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:WhitespaceMatcherBenchmark.java


注:本文中的com.google.caliper.BeforeExperiment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。