aboutsummaryrefslogtreecommitdiffstats
path: root/microbenchmark-template/src/main/java/org
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-06-02 21:58:25 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-06-06 09:41:01 +0200
commitc6dd2a5e2a5db5e61015f33c5666e3a2332b3c63 (patch)
tree8d28c77e3b5652c3d333484a2a4cee86d0398890 /microbenchmark-template/src/main/java/org
parent3d8e2ef425b063aa74a811b736606dad858fdcac (diff)
downloadsonarqube-c6dd2a5e2a5db5e61015f33c5666e3a2332b3c63.tar.gz
sonarqube-c6dd2a5e2a5db5e61015f33c5666e3a2332b3c63.zip
Remove unused module microbenchmark-template
Diffstat (limited to 'microbenchmark-template/src/main/java/org')
-rw-r--r--microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java150
-rw-r--r--microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java137
-rw-r--r--microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java203
3 files changed, 0 insertions, 490 deletions
diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java
deleted file mode 100644
index 94110d436cc..00000000000
--- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/FileSourceDbBenchmark.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.microbenchmark;
-
-import com.google.protobuf.CodedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.apache.commons.lang.RandomStringUtils;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Param;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.OptionsBuilder;
-import org.sonar.server.source.db.FileSourceDb;
-
-/**
- *
- * See https://code.google.com/p/xxhash/ and https://github.com/jpountz/lz4-java
- *
- */
-@OutputTimeUnit(TimeUnit.MILLISECONDS)
-@State(Scope.Thread)
-@Fork(1)
-@Warmup(iterations = 5)
-@Measurement(iterations = 5)
-@BenchmarkMode(Mode.Throughput)
-public class FileSourceDbBenchmark {
-
- @Param({"10", "100", "1000", "100000"})
- public int linesNumber;
-
- List<FileSourceDb.Line> lines = new ArrayList<>();
- FileSourceDb.Data data;
-
- @Setup
- public void setup() throws Exception {
- FileSourceDb.Data.Builder builder = FileSourceDb.Data.newBuilder();
- for (int i = 0; i < linesNumber; i++) {
- FileSourceDb.Line.Builder lineBuilder = builder.addLinesBuilder();
- lines.add(lineBuilder
- .setLine(i + 1)
- .setScmAuthor("charlie")
- .setScmRevision("ABCDE")
- .setScmDate(15000000000L)
- .setUtLineHits(5)
- .setUtConditions(2)
- .setUtCoveredConditions(1)
- .setSource(RandomStringUtils.randomAlphanumeric(10))
- .setHighlighting(RandomStringUtils.randomAlphanumeric(20))
- .setSymbols(RandomStringUtils.randomAlphanumeric(20))
- .addAllDuplication(Arrays.asList(12, 13, 15))
- .build());
- }
- data = builder.build();
- }
-
- @Benchmark
- public int container() throws Exception {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- data.writeTo(byteOutput);
- byteOutput.close();
- return byteOutput.toByteArray().length;
- }
-
- @Benchmark
- public int delimiters() throws Exception {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- for (FileSourceDb.Line line : lines) {
- line.writeDelimitedTo(byteOutput);
- }
- byteOutput.close();
- return byteOutput.toByteArray().length;
- }
-
- @Benchmark
- public int codedstream_container() throws Exception {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- CodedOutputStream writer = CodedOutputStream.newInstance(byteOutput);
- writer.writeRawVarint32(data.getSerializedSize());
- writer.writeRawBytes(data.toByteArray());
- writer.flush();
- byteOutput.close();
- return byteOutput.toByteArray().length;
- }
-
- @Benchmark
- public int codedstream_container_known_size() throws Exception {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(data.getSerializedSize());
- CodedOutputStream writer = CodedOutputStream.newInstance(byteOutput);
- writer.writeRawVarint32(data.getSerializedSize());
- writer.writeRawBytes(data.toByteArray());
- writer.flush();
- byteOutput.close();
- return byteOutput.toByteArray().length;
- }
-
- @Benchmark
- public int codedstream_delimiters() throws Exception {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- CodedOutputStream writer = CodedOutputStream.newInstance(byteOutput);
- for (FileSourceDb.Line line : lines) {
- writer.writeRawVarint32(line.getSerializedSize());
- writer.writeRawBytes(line.toByteArray());
- }
- writer.flush();
- byteOutput.close();
- return byteOutput.toByteArray().length;
- }
-
- /**
- * You can this benchmark with maven command-line (see run.sh) or by executing this method
- * in IDE
- */
- public static void main(String[] args) throws RunnerException {
- Options opt = new OptionsBuilder()
- .include(FileSourceDbBenchmark.class.getSimpleName())
- .build();
- new Runner(opt).run();
- }
-}
diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java
deleted file mode 100644
index 11bc14293b9..00000000000
--- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/HashBenchmark.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.microbenchmark;
-
-import net.jpountz.xxhash.XXHash32;
-import net.jpountz.xxhash.XXHash64;
-import net.jpountz.xxhash.XXHashFactory;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang.StringUtils;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Param;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.OptionsBuilder;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- *
- * See https://code.google.com/p/xxhash/ and https://github.com/jpountz/lz4-java
- *
- */
-@OutputTimeUnit(TimeUnit.MILLISECONDS)
-@State(Scope.Thread)
-@Fork(1)
-@Warmup(iterations = 3)
-@Measurement(iterations = 3)
-@BenchmarkMode(Mode.Throughput)
-public class HashBenchmark {
-
- @Param({"1", "100", "1000", "10000", "100000", "1000000"})
- public int size;
-
- XXHash32 xxHash32Jni = XXHashFactory.fastestInstance().hash32();
- XXHash64 xxHash64Jni = XXHashFactory.fastestInstance().hash64();
- XXHash32 xxHash32Unsafe = XXHashFactory.fastestJavaInstance().hash32();
- XXHash64 xxHash64Unsafe = XXHashFactory.fastestJavaInstance().hash64();
- XXHash32 xxHash32 = XXHashFactory.safeInstance().hash32();
- XXHash64 xxHash64 = XXHashFactory.safeInstance().hash64();
-
- byte[] bytes;
-
- @Setup
- public void setup() throws Exception {
- bytes = StringUtils.repeat("3", size).getBytes();
- }
-
- @Benchmark
- public String commonsCodecMd5() throws Exception {
- return DigestUtils.md5Hex(bytes);
- }
-
- @Benchmark
- public String commonsCodecSha1() throws Exception {
- return DigestUtils.sha1Hex(bytes);
- }
-
- @Benchmark
- public int xxhash32() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash32.hash(bytes, 0, bytes.length, seed);
- }
-
- @Benchmark
- public int xxhash32Jni() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash32Jni.hash(bytes, 0, bytes.length, seed);
- }
-
- @Benchmark
- public int xxhash32Unsafe() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash32Unsafe.hash(bytes, 0, bytes.length, seed);
- }
-
- @Benchmark
- public long xxhash64() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash64.hash(bytes, 0, bytes.length, seed);
- }
-
- @Benchmark
- public long xxhash64Jni() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash64Jni.hash(bytes, 0, bytes.length, seed);
- }
-
- @Benchmark
- public long xxhash64Unsafe() throws Exception {
- int seed = 0x9747b28c; // used to initialize the hash value, use whatever
- // value you want, but always the same
- return xxHash64Unsafe.hash(bytes, 0, bytes.length, seed);
- }
-
- /**
- * You can this benchmark with maven command-line (see run.sh) or by executing this method
- * in IDE
- */
- public static void main(String[] args) throws RunnerException {
- Options opt = new OptionsBuilder()
- .include(HashBenchmark.class.getSimpleName())
- .build();
- new Runner(opt).run();
- }
-}
diff --git a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java b/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java
deleted file mode 100644
index ff9361d7a0c..00000000000
--- a/microbenchmark-template/src/main/java/org/sonar/microbenchmark/SerializationBenchmark.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.microbenchmark;
-
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.io.Output;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.stream.JsonWriter;
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
-import java.io.Externalizable;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.openjdk.jmh.annotations.Benchmark;
-import org.openjdk.jmh.annotations.BenchmarkMode;
-import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Measurement;
-import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.annotations.OutputTimeUnit;
-import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
-import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.Warmup;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
-import org.openjdk.jmh.runner.options.Options;
-import org.openjdk.jmh.runner.options.OptionsBuilder;
-import org.sonar.batch.protocol.Constants;
-import org.sonar.batch.protocol.output.BatchReport;
-
-@OutputTimeUnit(TimeUnit.MILLISECONDS)
-@State(Scope.Thread)
-@Fork(1)
-@Warmup(iterations = 5)
-@Measurement(iterations = 5)
-@BenchmarkMode(Mode.Throughput)
-public class SerializationBenchmark {
-
- File outputFile;
- private final Gson gson = new GsonBuilder().create();
-
- @Setup
- public void setup() throws Exception {
- outputFile = File.createTempFile("microbenchmark", ".out");
- }
-
- @Benchmark
- public void write_gson() throws Exception {
- JsonWriter writer = new JsonWriter(new BufferedWriter(new FileWriter(outputFile, false)));
- writer.beginArray();
- for (int i = 0; i < 10000; i++) {
- Issue issue = new Issue();
- issue.uuid = "UUID_" + i;
- issue.severity = "BLOCKER";
- issue.message = "this is the message of issue " + i;
- issue.line = i;
- issue.author = "someone";
- issue.tags = Arrays.asList("tag" + i, "othertag" + i);
- gson.toJson(issue, Issue.class, writer);
- }
- writer.endArray();
- writer.close();
- }
-
- @Benchmark
- public void write_protobuf() throws Exception {
- // Write stream of objects with delimiter
- // An alternative can be http://stackoverflow.com/a/21870564/229031
- try (OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile, false))) {
- for (int i = 0; i < 10000; i++) {
- BatchReport.Issue.Builder issueBuilder = BatchReport.Issue.newBuilder();
- issueBuilder.setUuid("UUID_" + i);
- issueBuilder.setSeverity(Constants.Severity.BLOCKER);
- issueBuilder.setMsg("this is the message of issue " + i);
- issueBuilder.setLine(i);
- issueBuilder.setAuthorLogin("someone");
- issueBuilder.addAllTag(Arrays.asList("tag" + i, "othertag" + i));
- issueBuilder.build().writeDelimitedTo(out);
- }
- }
- }
-
- @Benchmark
- public void write_serializable() throws Exception {
- try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile, false)))) {
- for (int i = 0; i < 10000; i++) {
- Issue issue = new Issue();
- issue.uuid = "UUID_" + i;
- issue.severity = "BLOCKER";
- issue.message = "this is the message of issue " + i;
- issue.line = i;
- issue.author = "someone";
- issue.tags = Arrays.asList("tag" + i, "othertag" + i);
- out.writeObject(issue);
- }
- }
- }
-
- @Benchmark
- public void write_externalizable() throws Exception {
- try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile, false)))) {
- for (int i = 0; i < 10000; i++) {
- ExternalizableIssue issue = new ExternalizableIssue();
- issue.uuid = "UUID_" + i;
- issue.severity = "BLOCKER";
- issue.message = "this is the message of issue " + i;
- issue.line = i;
- issue.author = "someone";
- issue.tags = Arrays.asList("tag" + i, "othertag" + i);
- out.writeObject(issue);
- }
- }
- }
-
- @Benchmark
- public void write_kryo() throws Exception {
- Kryo kryo = new Kryo();
- OutputStream stream = new BufferedOutputStream(new FileOutputStream(outputFile, false));
- Output output = new Output(stream);
- for (int i = 0; i < 10000; i++) {
- Issue issue = new Issue();
- issue.uuid = "UUID_" + i;
- issue.severity = "BLOCKER";
- issue.message = "this is the message of issue " + i;
- issue.line = i;
- issue.author = "someone";
- issue.tags = Arrays.asList("tag" + i, "othertag" + i);
- kryo.writeObject(output, issue);
- }
- output.close();
- }
-
- public static class Issue implements Serializable {
- String uuid, severity, message, author;
- int line;
- List<String> tags;
- }
-
- public static class ExternalizableIssue implements Externalizable {
- String uuid, severity, message, author;
- int line;
- List<String> tags;
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeUTF(uuid);
- out.writeUTF(severity);
- out.writeUTF(message);
- out.writeUTF(author);
- out.writeInt(line);
-
- // write number of tags then tags
- out.writeByte(tags.size());
- for (String tag : tags) {
- out.writeUTF(tag);
- }
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * You can this benchmark with maven command-line (see run.sh) or by executing this method
- * in IDE
- */
- public static void main(String[] args) throws RunnerException {
- Options opt = new OptionsBuilder()
- .include(SerializationBenchmark.class.getSimpleName())
- .build();
- new Runner(opt).run();
- }
-}