Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConvertBigStringToInputStreamBenchmark.java
More file actions
Latest commit
72 lines (62 loc) · 2.53 KB
/
Copy pathConvertBigStringToInputStreamBenchmark.java
File metadata and controls
72 lines (62 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
packageother_examples;
importcom.google.common.io.CharSource;
importorg.apache.commons.io.IOUtils;
importorg.apache.commons.io.input.ReaderInputStream;
importorg.openjdk.jmh.annotations.*;
importorg.openjdk.jmh.runner.Runner;
importorg.openjdk.jmh.runner.RunnerException;
importorg.openjdk.jmh.runner.options.Options;
importorg.openjdk.jmh.runner.options.OptionsBuilder;
importjava.io.ByteArrayInputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.nio.charset.StandardCharsets;
importjava.util.concurrent.TimeUnit;
/**
* Created by vvedenin on 2/15/2016.
*/
@State(Scope.Benchmark)
publicclassConvertBigStringToInputStreamBenchmark {
privatestaticStringtest1;
/* 1. Using ToInputStream of Apache Utils */
@Benchmark
publicInputStreamapacheToInputStream() throwsIOException {
returnIOUtils.toInputStream(test1, StandardCharsets.UTF_8);
}
/* 2. Using JDK */
@Benchmark
publicInputStreamjdkByteArrayInputStream() throwsIOException {
returnnewByteArrayInputStream(test1.getBytes(StandardCharsets.UTF_8));
}
/* 3. Using ReaderInputStream of Apache Utils */
@Benchmark
publicInputStreamapacheReaderInputStream() throwsIOException {
returnnewReaderInputStream(CharSource.wrap(test1).openStream());
}
/* 4. Using Apache Utils and InputStreamReader*/
@Benchmark
publicInputStreamapacheInputStreamReader() throwsIOException {
returnIOUtils.toInputStream(test1);
}
@TearDown(Level.Iteration)
publicvoidtearDown() {
Stringtest = "test184768612876481276487612876417826487216478216784621784672816478216784621784621786478216478216784261784621782178647281647821647821697421687126784621874621786478216478216874";
StringBuilderbuilder = newStringBuilder(test);
for(inti = 0; i< 1000; i++) {
builder.append(test);
}
test1 = builder.toString();
System.out.println(test1.length());
}
publicstaticvoidmain(String[] args) throwsRunnerException {
Optionsopt = newOptionsBuilder()
.include(ConvertStringToInputStreamBenchmark.class.getSimpleName())
.timeUnit(TimeUnit.MICROSECONDS)
.warmupIterations(5)
.measurementIterations(50)
.forks(1)
.mode(Mode.AverageTime)
.build();
newRunner(opt).run();
}
}