From ed13442c8af11507f8ef02166630921687fbb4d5 Mon Sep 17 00:00:00 2001 From: salyh Date: Mon, 14 Jul 2014 16:51:27 +0200 Subject: [PATCH 22/22] benchmark suite overhauled Signed-off-by: salyh --- fleece-benchmark/execute_benchmarks.sh | 2 + .../fleece/core/jmh/benchmark/BenchmarkMain.java | 38 +++--- .../jmh/benchmark/BenchmarkNumberConversion.java | 130 +++++++++++++++++++++ .../core/jmh/benchmark/BenchmarkStreamParser.java | 56 ++++----- .../apache/fleece/core/jmh/benchmark/Buffers.java | 5 + .../core/jmh/benchmark/CreateJsonTestFiles.java | 4 + 6 files changed, 189 insertions(+), 46 deletions(-) create mode 100755 fleece-benchmark/execute_benchmarks.sh create mode 100644 fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkNumberConversion.java diff --git a/fleece-benchmark/execute_benchmarks.sh b/fleece-benchmark/execute_benchmarks.sh new file mode 100755 index 0000000..72f37ad --- /dev/null +++ b/fleece-benchmark/execute_benchmarks.sh @@ -0,0 +1,2 @@ +#!/bin/bash +mvn -U clean verify exec:exec diff --git a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkMain.java b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkMain.java index 9754bc1..8d3e756 100644 --- a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkMain.java +++ b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkMain.java @@ -41,12 +41,16 @@ public class BenchmarkMain { Buffers.init(); } + private BenchmarkMain() { + + } + private static final String REGEX = ".*"; private static final String MEMORY = "4096m"; public static void main(final String[] args) throws Exception { - //run(1,1,1,3); - run(1, 2, 3, 5); //1 fork, 2 threads, 3 warmup, 5 measurement + run(1, 1, 3, 3); + //run(1, 2, 3, 5); //1 fork, 2 threads, 3 warmup, 5 measurement //run(1, 4, 3, 5); //run(2,8,5,10); //run(2,16,3,5); @@ -54,32 +58,30 @@ public class BenchmarkMain { public static void run(final int forks, final int threads, final int warmupit, final int measureit) throws Exception { - long start = System.currentTimeMillis(); + final long start = System.currentTimeMillis(); Options opt = new OptionsBuilder().include(REGEX).forks(forks).warmupIterations(warmupit).measurementIterations(measureit) - .threads(threads).mode(Mode.AverageTime).timeUnit(TimeUnit.MICROSECONDS).verbosity(VerboseMode.EXTRA) - .jvmArgs("-Xmx"+MEMORY, "-Dfile.encoding=utf-8") - .resultFormat(ResultFormatType.TEXT) - .result(String.format("avg_benchmark_jmh_result_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) - .output(String.format("avg_benchmark_jmh_log_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) + .threads(threads).mode(Mode.Throughput).timeUnit(TimeUnit.SECONDS).verbosity(VerboseMode.EXTRA) + .jvmArgs("-Xmx" + MEMORY, "-Dfile.encoding=utf-8").resultFormat(ResultFormatType.TEXT) + .result(String.format("0_v2_thr_benchmark_jmh_result_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) + .output(String.format("0_v2_thr_benchmark_jmh_log_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) .build(); new Runner(opt).run(); - opt = new OptionsBuilder().include(REGEX).forks(forks).warmupIterations(warmupit).measurementIterations(measureit) - .threads(threads).mode(Mode.Throughput).timeUnit(TimeUnit.SECONDS).verbosity(VerboseMode.EXTRA) - .jvmArgs("-Xmx" + MEMORY, "-Dfile.encoding=utf-8") - .resultFormat(ResultFormatType.TEXT) - .result(String.format("thr_benchmark_jmh_result_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) - .output(String.format("thr_benchmark_jmh_log_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) + opt = new OptionsBuilder().include(REGEX).forks(forks).warmupIterations(warmupit).measurementIterations(measureit).threads(threads) + .mode(Mode.Throughput).timeUnit(TimeUnit.SECONDS).verbosity(VerboseMode.EXTRA) + .jvmArgs("-Xmx" + MEMORY, "-Dfile.encoding=utf-8").resultFormat(ResultFormatType.TEXT) + .result(String.format("1_v2_thr_benchmark_jmh_result_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) + .output(String.format("1_v2_thr_benchmark_jmh_log_f%d_t%d_w%d_i%d.txt", forks, threads, warmupit, measureit)) .build(); new Runner(opt).run(); - long end = System.currentTimeMillis(); - - System.out.println("End. Runtime was "+((end-start)/(60*1000))+" min."); - + final long end = System.currentTimeMillis(); + + System.out.println("End. Runtime was " + ((end - start) / (60 * 1000)) + " min."); + } } diff --git a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkNumberConversion.java b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkNumberConversion.java new file mode 100644 index 0000000..ee18395 --- /dev/null +++ b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkNumberConversion.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.fleece.core.jmh.benchmark; + +import java.math.BigInteger; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.infra.Blackhole; + +@State(Scope.Benchmark) +public class BenchmarkNumberConversion { + + //integral + private final char[] C_0 = new char[] { '0' }; + private final char[] C_9 = new char[] { '9' }; + private final char[] C_99 = new char[] { '9', '9' }; + private final char[] C__99 = new char[] { '-', '9', '9' }; + private final char[] C_999 = new char[] { '9', '9', '9' }; + private final char[] C_9999 = new char[] { '9', '9', '9', '9' }; + private final char[] C__9999 = new char[] { '-', '9', '9', '9', '9' }; + + @Benchmark + public void convertIntegralJdkparseInt(final Blackhole bh) throws Exception { + bh.consume(Integer.parseInt(new String(C_0))); + bh.consume(Integer.parseInt(new String(C_9))); + bh.consume(Integer.parseInt(new String(C_99))); + bh.consume(Integer.parseInt(new String(C__99))); + bh.consume(Integer.parseInt(new String(C_999))); + bh.consume(Integer.parseInt(new String(C_9999))); + bh.consume(Integer.parseInt(new String(C__9999))); + } + + @Benchmark + public void convertIntegralJdkparseLong(final Blackhole bh) throws Exception { + bh.consume(Long.parseLong(new String(C_0))); + bh.consume(Long.parseLong(new String(C_9))); + bh.consume(Long.parseLong(new String(C_99))); + bh.consume(Long.parseLong(new String(C__99))); + bh.consume(Long.parseLong(new String(C_999))); + bh.consume(Long.parseLong(new String(C_9999))); + bh.consume(Long.parseLong(new String(C__9999))); + } + + @Benchmark + public void convertIntegralBiparseInt(final Blackhole bh) throws Exception { + bh.consume(new BigInteger(new String(C_0)).intValue()); + bh.consume(new BigInteger(new String(C_9)).intValue()); + bh.consume(new BigInteger(new String(C_99)).intValue()); + bh.consume(new BigInteger(new String(C__99)).intValue()); + bh.consume(new BigInteger(new String(C_999)).intValue()); + bh.consume(new BigInteger(new String(C_9999)).intValue()); + bh.consume(new BigInteger(new String(C__9999)).intValue()); + } + + @Benchmark + public void convertIntegralBiparseLong(final Blackhole bh) throws Exception { + bh.consume(new BigInteger(new String(C_0)).longValue()); + bh.consume(new BigInteger(new String(C_9)).longValue()); + bh.consume(new BigInteger(new String(C_99)).longValue()); + bh.consume(new BigInteger(new String(C__99)).longValue()); + bh.consume(new BigInteger(new String(C_999)).longValue()); + bh.consume(new BigInteger(new String(C_9999)).longValue()); + bh.consume(new BigInteger(new String(C__9999)).longValue()); + } + + @Benchmark + public void convertIntegralSelfparseInt(final Blackhole bh) throws Exception { + bh.consume((int) parseLongFromChars((C_0))); + bh.consume((int) parseLongFromChars((C_9))); + bh.consume((int) parseLongFromChars((C_99))); + bh.consume((int) parseLongFromChars((C__99))); + bh.consume((int) parseLongFromChars((C_999))); + bh.consume((int) parseLongFromChars((C_9999))); + bh.consume((int) parseLongFromChars((C__9999))); + } + + @Benchmark + public void convertIntegralSelfparseLong(final Blackhole bh) throws Exception { + bh.consume(parseLongFromChars((C_0))); + bh.consume(parseLongFromChars((C_9))); + bh.consume(parseLongFromChars((C_99))); + bh.consume(parseLongFromChars((C__99))); + bh.consume(parseLongFromChars((C_999))); + bh.consume(parseLongFromChars((C_9999))); + bh.consume(parseLongFromChars((C__9999))); + } + + private static long parseLongFromChars(final char[] chars) { + return parseLongFromChars(chars, 0, chars.length - 1); + } + + private static long parseLongFromChars(final char[] chars, final int start, final int end) { + + if (chars == null || chars.length == 0 || start < 0 || end < start || end > chars.length - 1 || start > chars.length - 1) { + throw new IllegalArgumentException(chars.length + "/" + start + "/" + end); + } + + long retVal = 0; + final boolean negative = chars[start] == '-'; + for (int i = negative ? start + 1 : start; i < end; i++) { + + //int this context we know its an integral number, so skip this due to perf reasons + /*if (chars[i] < ZERO || chars[i] > NINE) { + throw new IllegalArgumentException("Not a integral number"); + }*/ + retVal = retVal * 10 + (chars[i] - '-'); + } + + return negative ? -retVal : retVal; + } + +} diff --git a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkStreamParser.java b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkStreamParser.java index 21444f0..a297b8d 100644 --- a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkStreamParser.java +++ b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/BenchmarkStreamParser.java @@ -102,133 +102,133 @@ public class BenchmarkStreamParser { //-- parse bytes /* @Benchmark - public void parse_only_1k_bytes(final Blackhole bh) throws Exception { + public void parseOnly1kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_1K), bh)); } @Benchmark - public void parse_only_3k_bytes(final Blackhole bh) throws Exception { + public void parseOnly3kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_3K), bh)); } @Benchmark - public void parse_only_10k_bytes(final Blackhole bh) throws Exception { + public void parseOnly10kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_10K), bh)); } @Benchmark - public void parse_only_100k_bytes(final Blackhole bh) throws Exception { + public void parseOnly100kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_100K), bh)); } @Benchmark - public void parse_only_1000k_bytes(final Blackhole bh) throws Exception { + public void parseOnly1000kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_1000K), bh)); } @Benchmark - public void parse_only_100000k_bytes(final Blackhole bh) throws Exception { + public void parseOnly100000kBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_100000K), bh)); } */ //-- parse chars @Benchmark - public void parse_only_1k_chars(final Blackhole bh) throws Exception { + public void parseOnly1kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_1K), bh)); } @Benchmark - public void parse_only_3k_chars(final Blackhole bh) throws Exception { + public void parseOnly3kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_3K), bh)); } @Benchmark - public void parse_only_10k_chars(final Blackhole bh) throws Exception { + public void parseOnly10kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_10K), bh)); } @Benchmark - public void parse_only_100k_chars(final Blackhole bh) throws Exception { + public void parseOnly100kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_100K), bh)); } @Benchmark - public void parse_only_1000k_chars(final Blackhole bh) throws Exception { + public void parseOnly1000kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_1000K), bh)); } @Benchmark - public void parse_only_100000k_chars(final Blackhole bh) throws Exception { + public void parseOnly100000kChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_100000K), bh)); } //-- read bytes to structure /* @Benchmark - public void read_1k_bytes(final Blackhole bh) throws Exception { + public void read1kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_1K), bh)); } @Benchmark - public void read_3k_bytes(final Blackhole bh) throws Exception { + public void read_3kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_3K), bh)); } @Benchmark - public void read_10k_bytes(final Blackhole bh) throws Exception { + public void read10kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_10K), bh)); } @Benchmark - public void read_100k_bytes(final Blackhole bh) throws Exception { + public void read100kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_100K), bh)); } @Benchmark - public void read_1000k_bytes(final Blackhole bh) throws Exception { + public void read1000kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_1000K), bh)); } @Benchmark - public void read_100000k_bytes(final Blackhole bh) throws Exception { + public void read100000kBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_100000K), bh)); } //-- read chars to structure @Benchmark - public void read_1k_chars(final Blackhole bh) throws Exception { + public void read1kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_1K), bh)); } */ @Benchmark - public void read_3k_chars(final Blackhole bh) throws Exception { + public void read3kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_3K), bh)); } @Benchmark - public void read_10k_chars(final Blackhole bh) throws Exception { + public void read10kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_10K), bh)); } @Benchmark - public void read_100k_chars(final Blackhole bh) throws Exception { + public void read100kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_100K), bh)); } @Benchmark - public void read_1000k_chars(final Blackhole bh) throws Exception { + public void read1000kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_1000K), bh)); } @Benchmark - public void read_100000k_chars(final Blackhole bh) throws Exception { + public void read100000kChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_100000K), bh)); } @Benchmark - public void parse_only_combined_chars(final Blackhole bh) throws Exception { + public void parseOnlyCombinedChars(final Blackhole bh) throws Exception { bh.consume(parse(new CharArrayReader(Buffers.C_100K), bh)); bh.consume(parse(new CharArrayReader(Buffers.C_100K), bh)); bh.consume(parse(new CharArrayReader(Buffers.C_100K), bh)); @@ -238,7 +238,7 @@ public class BenchmarkStreamParser { } /* @Benchmark - public void parse_only_combined_bytes(final Blackhole bh) throws Exception { + public void parseOnlyCombinedBytes(final Blackhole bh) throws Exception { bh.consume(parse(new ByteArrayInputStream(Buffers.B_100K), bh)); bh.consume(parse(new ByteArrayInputStream(Buffers.B_100K), bh)); bh.consume(parse(new ByteArrayInputStream(Buffers.B_100K), bh)); @@ -248,7 +248,7 @@ public class BenchmarkStreamParser { } */ @Benchmark - public void read_combined_chars(final Blackhole bh) throws Exception { + public void readCombinedChars(final Blackhole bh) throws Exception { bh.consume(read(new CharArrayReader(Buffers.C_100K), bh)); bh.consume(read(new CharArrayReader(Buffers.C_100K), bh)); bh.consume(read(new CharArrayReader(Buffers.C_100K), bh)); @@ -258,7 +258,7 @@ public class BenchmarkStreamParser { } /* @Benchmark - public void read_combined_bytes(final Blackhole bh) throws Exception { + public void readCombinedBytes(final Blackhole bh) throws Exception { bh.consume(read(new ByteArrayInputStream(Buffers.B_100K), bh)); bh.consume(read(new ByteArrayInputStream(Buffers.B_100K), bh)); bh.consume(read(new ByteArrayInputStream(Buffers.B_100K), bh)); diff --git a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/Buffers.java b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/Buffers.java index 1658cbd..6b2dfde 100644 --- a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/Buffers.java +++ b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/Buffers.java @@ -26,6 +26,10 @@ import org.apache.commons.io.IOUtils; public class Buffers { + private Buffers() { + + } + public static final byte[] B_1K = readBytes(1); public static final byte[] B_3K = readBytes(3); public static final byte[] B_10K = readBytes(10); @@ -69,4 +73,5 @@ public class Buffers { public static void init() { } + } diff --git a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/CreateJsonTestFiles.java b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/CreateJsonTestFiles.java index 380d8c7..da988ae 100644 --- a/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/CreateJsonTestFiles.java +++ b/fleece-benchmark/src/test/java/org/apache/fleece/core/jmh/benchmark/CreateJsonTestFiles.java @@ -27,6 +27,10 @@ import org.apache.commons.io.output.FileWriterWithEncoding; public class CreateJsonTestFiles { + private CreateJsonTestFiles() { + + } + public static void main(final String[] args) throws Exception { create(); -- 1.8.5.2 (Apple Git-48)