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


Java Benchmark类代码示例

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


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

示例1: joinerInlined

import com.google.caliper.Benchmark; //导入依赖的package包/类
/**
 * Mimics what the {@link Joiner} class does internally when no extra options like
 * ignoring {@code null} values are used.
 */
@Benchmark int joinerInlined(int reps) {
  int dummy = 0;
  for (int i = 0; i < reps; i++) {
    StringBuilder sb = new StringBuilder();
    Iterator<String> iterator = components.iterator();
    if (iterator.hasNext()) {
      sb.append(iterator.next().toString());
      while (iterator.hasNext()) {
        sb.append(DELIMITER_STRING);
        sb.append(iterator.next());
      }
    }
    dummy ^= sb.toString().length();
  }
  return dummy;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:JoinerBenchmark.java

示例2: executeThenAdd_multiThreaded

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int executeThenAdd_multiThreaded(final int reps) throws InterruptedException {
  Runnable addTask = new Runnable() {
    @Override public void run() {
      for (int i = 0; i < numListeners; i++) {
        list.add(listener, directExecutor());
      }
    }
  };
  int returnValue = 0;
  for (int i = 0; i < reps; i++) {
    list = impl.newExecutionList();
    listenerLatch = new CountDownLatch(numListeners * NUM_THREADS);
    @SuppressWarnings("unused") // go/futurereturn-lsc
    Future<?> possiblyIgnoredError = executorService.submit(executeTask);
    for (int j = 0; j < NUM_THREADS; j++) {
      @SuppressWarnings("unused") // go/futurereturn-lsc
      Future<?> possiblyIgnoredError1 = executorService.submit(addTask);
    }
    returnValue += (int) listenerLatch.getCount();
    listenerLatch.await();
  }
  return returnValue;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:24,代码来源:ExecutionListBenchmark.java

示例3: futuresGetChecked

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark
void futuresGetChecked(int n) {
  IOException exception = new IOException();
  CompletableFuture<?> future = new CompletableFuture<>();
  future.completeExceptionally(exception);
  for (int i = 0; i < n; i++) {
    try {
      Futures.getChecked(future, IOException.class);
      throw new AssertionError();
    } catch (IOException expected) {}
  }
}
 
开发者ID:google,项目名称:mug,代码行数:13,代码来源:ExceptionWrappingBenchmark.java

示例4: ternaryLtLongAddOutsideTernary

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int ternaryLtLongAddOutsideTernary(int reps) {
  int tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & SAMPLE_MASK;
    long x = xLongs[j];
    long y = yLongs[j];
    int z = constant[j];
    tmp += z + ((x < y) ? 1 : 0);
  }
  return tmp;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:LessThanBenchmark.java

示例5: createAndPopulate

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int createAndPopulate(int reps) {
  int dummy = 0;
  for (int i = 0; i < reps; i++) {
    dummy += impl.create(values).size();
  }
  return dummy;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:MapBenchmark.java

示例6: builderAdd

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int builderAdd(int reps) {
  int size = this.size;
  int dummy = 0;
  for (int rep = 0; rep < reps; rep++) {
    ImmutableList.Builder<Object> builder = ImmutableList.builder();
    for (int i = 0; i < size; i++) {
      builder.add(OBJECT);
    }
    dummy += builder.build().size();
  }
  return dummy;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:13,代码来源:ImmutableListCreationBenchmark.java

示例7: add

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark long add(final int reps) throws ExecutionException, InterruptedException {
  return doMultithreadedLoop(
      new Callable<Long>() {
        @Override public Long call() {
          return runAddSingleThread(reps);
        }
      });
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:ConcurrentHashMultisetBenchmark.java

示例8: arrayListFor

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int arrayListFor(int reps) {
  int sum = 0;
  for (int i = 0; i < reps; i++) {
    for (Object value : arrayList) {
      sum += value.hashCode();
    }
  }
  return sum;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:IteratorBenchmark.java

示例9: roundToLong

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark long roundToLong(int reps) {
  long tmp = 0;
  for (int i = 0; i < reps; i++) {
    int j = i & ARRAY_MASK;
    tmp += DoubleMath.roundToLong(doubleInLongRange[j], mode);
  }
  return tmp;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:DoubleMathRoundingBenchmark.java

示例10: hashString_4

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int hashString_4(int reps) {
  int dummy = 0;
  for (int i = 0; i < reps; i++) {
    dummy += Objects.hashCode(S0, S1, S2, S3);
  }
  return dummy;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ObjectsBenchmark.java

示例11: hashString_5

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int hashString_5(int reps) {
  int dummy = 0;
  for (int i = 0; i < reps; i++) {
    dummy += Objects.hashCode(S0, S1, S2, S3, S4);
  }
  return dummy;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:ObjectsBenchmark.java

示例12: timeBulkGet

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark long timeBulkGet(long reps) {
  long rvalue = 0;
  List<Integer> bulkGetSetLocal = bulkGetSet;
  Striped<Lock> stripedLocal = striped;
  for (long i = 0; i < reps; i++) {
    rvalue += stripedLocal.bulkGet(bulkGetSetLocal).hashCode();
  }
  return rvalue;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:10,代码来源:StripedBenchmark.java

示例13: linkedListForEach

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark
int linkedListForEach(int reps) {
  int[] sumHolder = {0};
  for (int i = 0; i < reps; i++) {
    linkedList.forEach(value -> sumHolder[0] += value.hashCode());
  }
  return sumHolder[0];
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:IteratorBenchmark.java

示例14: manual

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark long manual(int reps) {
  long total = 0;
  for (int i = 0; i < reps; i++) {
    long start = System.nanoTime();
    // here is where you would do something
    total += (System.nanoTime() - start);
  }
  return total;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:10,代码来源:StopwatchBenchmark.java

示例15: asciiStringToUpperCase

import com.google.caliper.Benchmark; //导入依赖的package包/类
@Benchmark int asciiStringToUpperCase(int reps) {
  String string = noWorkToDo
      ? Ascii.toUpperCase(testString)
      : testString;

  int dummy = 0;
  for (int i = 0; i < reps; i++) {
    dummy += Ascii.toUpperCase(string).length();
  }
  return dummy;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:AsciiBenchmark.java


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