本文整理汇总了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;
}
示例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;
}
示例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) {}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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];
}
示例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;
}
示例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;
}