diff options
author | Jesse Wilson <jessewilson@google.com> | 2009-12-10 15:45:23 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2009-12-10 16:01:12 -0800 |
commit | e95457f2149d4f5a4e7552ca244018106b667f39 (patch) | |
tree | ceee1d691e5169667774242d0958000d1f379254 | |
parent | 109c128644fdd598b9e71301424ff4fa11f4bcd2 (diff) | |
download | caliper-e95457f2149d4f5a4e7552ca244018106b667f39.tar.gz |
Updating caliper to current SVN as of 20091210
A test
A test/com
A test/com/google
A test/com/google/caliper
A test/com/google/caliper/DefaultBenchmarkSuiteTest.java
A test/com/google/caliper/AllTests.java
A test/com/google/caliper/examples
A test/com/google/caliper/examples/ListIterationBenchmarkSuite.java
A test/com/google/caliper/examples/EnumSetContainsBenchmarkSuite.java
A test/com/google/caliper/examples/FormatterBenchmarkSuite.java
A test/com/google/caliper/examples/DoubleToStringBenchmarkSuite.java
A test/com/google/caliper/examples/SortBenchmarkSuite.java
A lib
A lib/junit.jar
A lib/google-collect-1.0-rc4.jar
A src
A src/com
A src/com/google
A src/com/google/caliper
A src/com/google/caliper/Caliper.java
A src/com/google/caliper/Param.java
A src/com/google/caliper/Parameter.java
A src/com/google/caliper/ExecutionException.java
A src/com/google/caliper/BenchmarkSuite.java
A src/com/google/caliper/Run.java
A src/com/google/caliper/ConfigurationException.java
A src/com/google/caliper/DefaultBenchmarkSuite.java
A src/com/google/caliper/Runner.java
A src/com/google/caliper/TypeConverter.java
A src/com/google/caliper/Benchmark.java
A src/com/google/caliper/ConsoleReport.java
A src/com/google/caliper/Result.java
A caliper.ipr
A core.iml
A COPYING
A build.xml
Checked out revision 18.
-rw-r--r-- | Android.mk | 8 | ||||
-rw-r--r-- | src/com/google/caliper/ConsoleReport.java | 4 | ||||
-rw-r--r-- | src/com/google/caliper/Runner.java | 8 | ||||
-rw-r--r-- | test/com/google/caliper/examples/EnumSetContainsBenchmarkSuite.java | 103 | ||||
-rw-r--r-- | test/com/google/caliper/examples/FormatterBenchmarkSuite.java | 98 | ||||
-rw-r--r-- | test/com/google/caliper/examples/ListIterationBenchmarkSuite.java | 82 |
6 files changed, 295 insertions, 8 deletions
@@ -21,11 +21,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_MODULE := caliper -LOCAL_STATIC_JAVA_LIBRARIES := google-collect +LOCAL_JAVA_LIBRARIES := guava -include $(BUILD_HOST_JAVA_LIBRARY) +include $(BUILD_JAVA_LIBRARY) -# prebuilt google-collect-1.0-rc4.jar -include $(CLEAR_VARS) -LOCAL_PREBUILT_JAVA_LIBRARIES := google-collect:lib/google-collect-1.0-rc4.jar -include $(BUILD_HOST_PREBUILT) diff --git a/src/com/google/caliper/ConsoleReport.java b/src/com/google/caliper/ConsoleReport.java index 537d56a..790ffe0 100644 --- a/src/com/google/caliper/ConsoleReport.java +++ b/src/com/google/caliper/ConsoleReport.java @@ -129,7 +129,9 @@ final class ConsoleReport { decimalDigits = 0; units = "ns"; } - measurementColumnLength = (int) Math.ceil(Math.log10(maxValue / divideBy)) + decimalDigits + 1; + measurementColumnLength = maxValue > 0 + ? (int) Math.ceil(Math.log10(maxValue / divideBy)) + decimalDigits + 1 + : 1; } /** diff --git a/src/com/google/caliper/Runner.java b/src/com/google/caliper/Runner.java index c575af1..68f26f1 100644 --- a/src/com/google/caliper/Runner.java +++ b/src/com/google/caliper/Runner.java @@ -108,6 +108,12 @@ public final class Runner { } } + private ImmutableSet<String> defaultVms() { + return "Dalvik".equals(System.getProperty("java.vm.name")) + ? ImmutableSet.of("dalvikvm") + : ImmutableSet.of("java"); + } + /** * Returns a complete set of runs with every combination of values and * benchmark classes. @@ -127,7 +133,7 @@ public final class Runner { // multiply the runs by the number of VMs Set<String> vms = userVms.isEmpty() - ? ImmutableSet.of("java") + ? defaultVms() : userVms; Iterator<String> vmIterator = vms.iterator(); String firstVm = vmIterator.next(); diff --git a/test/com/google/caliper/examples/EnumSetContainsBenchmarkSuite.java b/test/com/google/caliper/examples/EnumSetContainsBenchmarkSuite.java new file mode 100644 index 0000000..da8f0f5 --- /dev/null +++ b/test/com/google/caliper/examples/EnumSetContainsBenchmarkSuite.java @@ -0,0 +1,103 @@ +/* + * 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 com.google.caliper.examples; + +import com.google.caliper.Benchmark; +import com.google.caliper.DefaultBenchmarkSuite; +import com.google.caliper.Param; +import com.google.caliper.Runner; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.Set; + +/** + * Measures EnumSet#contains(). + */ +public class EnumSetContainsBenchmarkSuite extends DefaultBenchmarkSuite { + + @Param private SetMaker setMaker; + + private static Collection<SetMaker> setMakerValues = EnumSet.allOf(SetMaker.class); + + enum SetMaker { + ENUM_SET { + @Override Set<?> newSet() { + return EnumSet.allOf(RegularSize.class); + } + @Override Object[] testValues() { + return new Object[] { RegularSize.E1, RegularSize.E2, RegularSize.E20, + RegularSize.E39, RegularSize.E40, "A", LargeSize.E40, null }; + } + }, + LARGE_ENUM_SET { + @Override Set<?> newSet() { + return EnumSet.allOf(LargeSize.class); + } + @Override Object[] testValues() { + return new Object[] { LargeSize.E1, LargeSize.E63, LargeSize.E64, + LargeSize.E65, LargeSize.E140, "A", RegularSize.E40, null }; + } + }; + + abstract Set<?> newSet(); + abstract Object[] testValues(); + } + + enum RegularSize { + E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, + E18, E19, E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E30, E31, E32, + E33, E34, E35, E36, E37, E38, E39, E40, + } + + enum LargeSize { + E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, + E18, E19, E20, E21, E22, E23, E24, E25, E26, E27, E28, E29, E30, E31, E32, + E33, E34, E35, E36, E37, E38, E39, E40, E41, E42, E43, E44, E45, E46, E47, + E48, E49, E50, E51, E52, E53, E54, E55, E56, E57, E58, E59, E60, E61, E62, + E63, E64, E65, E66, E67, E68, E69, E70, E71, E72, E73, E74, E75, E76, E77, + E78, E79, E80, E81, E82, E83, E84, E85, E86, E87, E88, E89, E90, E91, E92, + E93, E94, E95, E96, E97, E98, E99, E100, E101, E102, E103, E104, E105, E106, + E107, E108, E109, E110, E111, E112, E113, E114, E115, E116, E117, E118, + E119, E120, E121, E122, E123, E124, E125, E126, E127, E128, E129, E130, + E131, E132, E133, E134, E135, E136, E137, E138, E139, E140, + } + + private Set<?> set; + private Object[] testValues; + + @Override protected void setUp() throws Exception { + this.set = setMaker.newSet(); + this.testValues = setMaker.testValues(); + } + + class ContainsBenchmark extends Benchmark { + @Override public Object run(int trials) throws Exception { + int count = 0; + for (int i = 0; i < trials; i++) { + for (Object value : testValues) { + count ^= (set.contains(value) ? i : 0); + } + } + return count > 0; + } + } + + public static void main(String[] args) { + Runner.main(EnumSetContainsBenchmarkSuite.class, args); + } +}
\ No newline at end of file diff --git a/test/com/google/caliper/examples/FormatterBenchmarkSuite.java b/test/com/google/caliper/examples/FormatterBenchmarkSuite.java new file mode 100644 index 0000000..53dff71 --- /dev/null +++ b/test/com/google/caliper/examples/FormatterBenchmarkSuite.java @@ -0,0 +1,98 @@ +/* + * 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 com.google.caliper.examples; + +import com.google.caliper.Benchmark; +import com.google.caliper.DefaultBenchmarkSuite; +import com.google.caliper.Param; +import com.google.caliper.Runner; + +import java.util.Formatter; + +/** + * Compares Formatter against hand-written StringBuilder code. + */ +public class FormatterBenchmarkSuite extends DefaultBenchmarkSuite { + + class Formatter_NoFormatting extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + Formatter f = new Formatter(); + f.format("this is a reasonably short string that doesn't actually need any formatting"); + } + return null; + } + } + + class StringBuilder_NoFormatting extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + StringBuilder sb = new StringBuilder(); + sb.append("this is a reasonably short string that doesn't actually need any formatting"); + } + return null; + } + } + + class Formatter_OneInt extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + Formatter f = new Formatter(); + f.format("this is a reasonably short string that has an int %d in it", i); + } + return null; + } + } + + class StringBuilder_OneInt extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + StringBuilder sb = new StringBuilder(); + sb.append("this is a reasonably short string that has an int "); + sb.append(i); + sb.append(" in it"); + } + return null; + } + } + + class Formatter_OneString extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + Formatter f = new Formatter(); + f.format("this is a reasonably short string that has a string %s in it", "hello"); + } + return null; + } + } + + class StringBuilder_OneString extends Benchmark { + public Object run(int trials) { + for (int i = 0; i < trials; i++) { + StringBuilder sb = new StringBuilder(); + sb.append("this is a reasonably short string that has a string "); + sb.append("hello"); + sb.append(" in it"); + } + return null; + } + } + + public static void main(String[] args) { + Runner.main(FormatterBenchmarkSuite.class, args); + } +} diff --git a/test/com/google/caliper/examples/ListIterationBenchmarkSuite.java b/test/com/google/caliper/examples/ListIterationBenchmarkSuite.java new file mode 100644 index 0000000..0ed7197 --- /dev/null +++ b/test/com/google/caliper/examples/ListIterationBenchmarkSuite.java @@ -0,0 +1,82 @@ +/* + * 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 com.google.caliper.examples; + +import com.google.caliper.Benchmark; +import com.google.caliper.DefaultBenchmarkSuite; +import com.google.caliper.Param; +import com.google.caliper.Runner; + +import java.util.*; + +/** + * Measures iterating through list elements. + */ +public class ListIterationBenchmarkSuite extends DefaultBenchmarkSuite { + + @Param private int length; + + private static Collection<Integer> lengthValues = Arrays.asList(0, 10, 100, 1000); + + private List<Object> list; + private Object[] array; + + @Override protected void setUp() throws Exception { + array = new Object[length]; + for (int i = 0; i < length; i++) { + array[i] = new Object(); + } + + list = new AbstractList<Object>() { + @Override public int size() { + return length; + } + + @Override public Object get(int i) { + return array[i]; + } + }; + } + + class ListIterateBenchmark extends Benchmark { + @Override public Object run(int trials) throws Exception { + int count = 0; + for (int i = 0; i < trials; i++) { + for (Object value : list) { + count ^= (value == Boolean.TRUE) ? i : 0; + } + } + return count > 0; + } + } + + class ArrayIterateBenchmark extends Benchmark { + @Override public Object run(int trials) throws Exception { + int count = 0; + for (int i = 0; i < trials; i++) { + for (Object value : array) { + count ^= (value == Boolean.TRUE) ? i : 0; + } + } + return count > 0; + } + } + + public static void main(String[] args) { + Runner.main(ListIterationBenchmarkSuite.class, args); + } +}
\ No newline at end of file |