summaryrefslogtreecommitdiffstats
path: root/benchmarks/regression/StringBuilderBenchmark.java
diff options
context:
space:
mode:
authorTsu Chiang Chuang <tsu@google.com>2013-03-26 17:38:46 -0700
committerTsu Chiang Chuang <tsu@google.com>2013-03-28 14:47:03 -0700
commit5a7833b406bb2716b057d3ed923f22f1f86b2a20 (patch)
tree7d0e79a91c627918879d379bc6362d20f79b512f /benchmarks/regression/StringBuilderBenchmark.java
parent0b2e0fc3b8b8886cfebd27d279383d8cae61102d (diff)
downloadlibcore-5a7833b406bb2716b057d3ed923f22f1f86b2a20.zip
libcore-5a7833b406bb2716b057d3ed923f22f1f86b2a20.tar.gz
libcore-5a7833b406bb2716b057d3ed923f22f1f86b2a20.tar.bz2
Build Caliper microbenchmark tests.Also fix the URLConnectionBenchmark tests to use the external/mockwebserver.
Change-Id: I48ec32e94f992fe570a6d729bb38971b3f211188
Diffstat (limited to 'benchmarks/regression/StringBuilderBenchmark.java')
-rw-r--r--benchmarks/regression/StringBuilderBenchmark.java132
1 files changed, 0 insertions, 132 deletions
diff --git a/benchmarks/regression/StringBuilderBenchmark.java b/benchmarks/regression/StringBuilderBenchmark.java
deleted file mode 100644
index 79eff2a..0000000
--- a/benchmarks/regression/StringBuilderBenchmark.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package benchmarks.regression;
-
-import com.google.caliper.Param;
-import com.google.caliper.Runner;
-import com.google.caliper.SimpleBenchmark;
-
-/**
- * Tests the performance of various StringBuilder methods.
- */
-public class StringBuilderBenchmark extends SimpleBenchmark {
-
- @Param({"1", "10", "100"}) private int length;
-
- public void timeAppendBoolean(int reps) {
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(true);
- }
- }
- }
-
- public void timeAppendChar(int reps) {
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append('c');
- }
- }
- }
-
- public void timeAppendCharArray(int reps) {
- char[] chars = "chars".toCharArray();
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(chars);
- }
- }
- }
-
- public void timeAppendCharSequence(int reps) {
- CharSequence cs = "chars";
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(cs);
- }
- }
- }
-
- public void timeAppendDouble(int reps) {
- double d = 1.2;
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(d);
- }
- }
- }
-
- public void timeAppendFloat(int reps) {
- float f = 1.2f;
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(f);
- }
- }
- }
-
- public void timeAppendInt(int reps) {
- int n = 123;
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(n);
- }
- }
- }
-
- public void timeAppendLong(int reps) {
- long l = 123;
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(l);
- }
- }
- }
-
- public void timeAppendObject(int reps) {
- // We don't want to time the toString, so ensure we're calling a trivial one...
- Object o = new Object() {
- @Override public String toString() {
- return "constant";
- }
- };
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(o);
- }
- }
- }
-
- public void timeAppendString(int reps) {
- String s = "chars";
- for (int i = 0; i < reps; ++i) {
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < length; ++j) {
- sb.append(s);
- }
- }
- }
-}