Skip to content

Commit 0539b6b

Browse files
author
vvedenin
committed
Add other_examples to Hello Worlds
1 parent 1e4c7ed commit 0539b6b

9 files changed

+958
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.github.vedenin</groupId>
6+
<artifactId>5.0-other-examples</artifactId>
7+
<version>0.1</version>
8+
<packaging>jar</packaging>
9+
10+
<name>Other Examples</name>
11+
12+
<prerequisites>
13+
<maven>3.0</maven>
14+
</prerequisites>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.openjdk.jmh</groupId>
19+
<artifactId>jmh-core</artifactId>
20+
<version>${jmh.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.openjdk.jmh</groupId>
24+
<artifactId>jmh-generator-annprocess</artifactId>
25+
<version>${jmh.version}</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.eclipse.collections</groupId>
30+
<artifactId>eclipse-collections-api</artifactId>
31+
<version>7.0.1</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.eclipse.collections</groupId>
36+
<artifactId>eclipse-collections</artifactId>
37+
<version>7.0.1</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.eclipse.collections</groupId>
42+
<artifactId>eclipse-collections-testutils</artifactId>
43+
<version>7.0.1</version>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.eclipse.collections</groupId>
49+
<artifactId>eclipse-collections-forkjoin</artifactId>
50+
<version>7.0.1</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>com.google.guava</groupId>
55+
<artifactId>guava</artifactId>
56+
<version>18.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.commons</groupId>
60+
<artifactId>commons-collections4</artifactId>
61+
<version>4.0</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>commons-io</groupId>
65+
<artifactId>commons-io</artifactId>
66+
<version>2.4</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.commons</groupId>
70+
<artifactId>commons-lang3</artifactId>
71+
<version>3.0</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>commons-lang</groupId>
75+
<artifactId>commons-lang</artifactId>
76+
<version>2.6</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.springframework</groupId>
80+
<artifactId>spring-context</artifactId>
81+
<version>4.2.4.RELEASE</version>
82+
</dependency>
83+
</dependencies>
84+
85+
<properties>
86+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
87+
<jmh.version>1.11.3</jmh.version>
88+
<javac.target>1.8</javac.target>
89+
<uberjar.name>benchmarks</uberjar.name>
90+
</properties>
91+
92+
<build>
93+
<plugins>
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-compiler-plugin</artifactId>
97+
<version>3.1</version>
98+
<configuration>
99+
<compilerVersion>${javac.target}</compilerVersion>
100+
<source>${javac.target}</source>
101+
<target>${javac.target}</target>
102+
</configuration>
103+
</plugin>
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-shade-plugin</artifactId>
107+
<version>2.2</version>
108+
<executions>
109+
<execution>
110+
<phase>package</phase>
111+
<goals>
112+
<goal>shade</goal>
113+
</goals>
114+
<configuration>
115+
<finalName>${uberjar.name}</finalName>
116+
<transformers>
117+
<transformer
118+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
119+
<mainClass>org.openjdk.jmh.Main</mainClass>
120+
</transformer>
121+
</transformers>
122+
<filters>
123+
<filter>
124+
<!--
125+
Shading signed JARs will fail without this.
126+
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
127+
-->
128+
<artifact>*:*</artifact>
129+
<excludes>
130+
<exclude>META-INF/*.SF</exclude>
131+
<exclude>META-INF/*.DSA</exclude>
132+
<exclude>META-INF/*.RSA</exclude>
133+
</excludes>
134+
</filter>
135+
</filters>
136+
</configuration>
137+
</execution>
138+
</executions>
139+
</plugin>
140+
</plugins>
141+
<pluginManagement>
142+
<plugins>
143+
<plugin>
144+
<artifactId>maven-clean-plugin</artifactId>
145+
<version>2.5</version>
146+
</plugin>
147+
<plugin>
148+
<artifactId>maven-deploy-plugin</artifactId>
149+
<version>2.8.1</version>
150+
</plugin>
151+
<plugin>
152+
<artifactId>maven-install-plugin</artifactId>
153+
<version>2.5.1</version>
154+
</plugin>
155+
<plugin>
156+
<artifactId>maven-jar-plugin</artifactId>
157+
<version>2.4</version>
158+
</plugin>
159+
<plugin>
160+
<artifactId>maven-javadoc-plugin</artifactId>
161+
<version>2.9.1</version>
162+
</plugin>
163+
<plugin>
164+
<artifactId>maven-resources-plugin</artifactId>
165+
<version>2.6</version>
166+
</plugin>
167+
<plugin>
168+
<artifactId>maven-site-plugin</artifactId>
169+
<version>3.3</version>
170+
</plugin>
171+
<plugin>
172+
<artifactId>maven-source-plugin</artifactId>
173+
<version>2.2.1</version>
174+
</plugin>
175+
<plugin>
176+
<artifactId>maven-surefire-plugin</artifactId>
177+
<version>2.17</version>
178+
</plugin>
179+
</plugins>
180+
</pluginManagement>
181+
</build>
182+
183+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package other_examples;
2+
3+
import com.google.common.io.CharSource;
4+
import org.apache.commons.io.IOUtils;
5+
import org.apache.commons.io.input.ReaderInputStream;
6+
import org.openjdk.jmh.annotations.*;
7+
import org.openjdk.jmh.runner.Runner;
8+
import org.openjdk.jmh.runner.RunnerException;
9+
import org.openjdk.jmh.runner.options.Options;
10+
import org.openjdk.jmh.runner.options.OptionsBuilder;
11+
12+
import java.io.ByteArrayInputStream;
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import java.nio.charset.StandardCharsets;
16+
import java.util.concurrent.TimeUnit;
17+
18+
/**
19+
* Created by vvedenin on 2/15/2016.
20+
*/
21+
@State(Scope.Benchmark)
22+
public class ConvertBigStringToInputStreamBenchmark {
23+
private static String test1;
24+
25+
/* 1. Using ToInputStream of Apache Utils */
26+
@Benchmark
27+
public InputStream apacheToInputStream() throws IOException {
28+
return IOUtils.toInputStream(test1, StandardCharsets.UTF_8);
29+
}
30+
31+
/* 2. Using JDK */
32+
@Benchmark
33+
public InputStream jdkByteArrayInputStream() throws IOException {
34+
return new ByteArrayInputStream(test1.getBytes(StandardCharsets.UTF_8));
35+
}
36+
37+
/* 3. Using ReaderInputStream of Apache Utils */
38+
@Benchmark
39+
public InputStream apacheReaderInputStream() throws IOException {
40+
return new ReaderInputStream(CharSource.wrap(test1).openStream());
41+
}
42+
43+
/* 4. Using Apache Utils and InputStreamReader*/
44+
@Benchmark
45+
public InputStream apacheInputStreamReader() throws IOException {
46+
return IOUtils.toInputStream(test1);
47+
}
48+
49+
@TearDown(Level.Iteration)
50+
public void tearDown() {
51+
String test = "test184768612876481276487612876417826487216478216784621784672816478216784621784621786478216478216784261784621782178647281647821647821697421687126784621874621786478216478216874";
52+
StringBuilder builder = new StringBuilder(test);
53+
for(int i = 0; i< 1000; i++) {
54+
builder.append(test);
55+
}
56+
test1 = builder.toString();
57+
System.out.println(test1.length());
58+
}
59+
60+
public static void main(String[] args) throws RunnerException {
61+
Options opt = new OptionsBuilder()
62+
.include(ConvertStringToInputStreamBenchmark.class.getSimpleName())
63+
.timeUnit(TimeUnit.MICROSECONDS)
64+
.warmupIterations(5)
65+
.measurementIterations(50)
66+
.forks(1)
67+
.mode(Mode.AverageTime)
68+
.build();
69+
70+
new Runner(opt).run();
71+
}
72+
}

0 commit comments

Comments
 (0)