FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/ConvertStringToInputStreamBenchmark.java at main · Eggy115/Java · GitHub
Eggy115
/
Java
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5
Star
3
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
ConvertStringToInputStreamBenchmark.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
62 lines (52 loc) · 2.24 KB
Breadcrumbs
Java
/
ConvertStringToInputStreamBenchmark.java
Copy path
File metadata and controls
62 lines (52 loc) · 2.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
other_examples
;
import
com
.
google
.
common
.
io
.
CharSource
;
import
org
.
apache
.
commons
.
io
.
IOUtils
;
import
org
.
apache
.
commons
.
io
.
input
.
ReaderInputStream
;
import
org
.
openjdk
.
jmh
.
annotations
.*;
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
.
io
.
ByteArrayInputStream
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStream
;
import
java
.
nio
.
charset
.
StandardCharsets
;
import
java
.
util
.
concurrent
.
TimeUnit
;
/**
* Created by vvedenin on 2/15/2016.
*/
@
BenchmarkMode
(
Mode
.
AverageTime
)
@
OutputTimeUnit
(
TimeUnit
.
MICROSECONDS
)
@
Warmup
(
iterations
=
5
,
time
=
1
,
timeUnit
=
TimeUnit
.
SECONDS
)
@
Measurement
(
iterations
=
5
,
time
=
1
,
timeUnit
=
TimeUnit
.
SECONDS
)
@
Fork
(
1
)
@
State
(
Scope
.
Benchmark
)
public
class
ConvertStringToInputStreamBenchmark
{
private
static
final
String
test1
=
"test184768612876481276487612876417826487216478216784621784672816478216784621784621786478216478216784261784621782178647281647821647821697421687126784621874621786478216478216874"
;
/* 1. Using ToInputStream of Apache Utils */
@
Benchmark
public
InputStream
apacheToInputStream
()
throws
IOException
{
return
IOUtils
.
toInputStream
(
test1
,
StandardCharsets
.
UTF_8
);
}
/* 2. Using JDK */
@
Benchmark
public
InputStream
jdkByteArrayInputStream
()
throws
IOException
{
return
new
ByteArrayInputStream
(
test1
.
getBytes
(
StandardCharsets
.
UTF_8
));
}
/* 3. Using ReaderInputStream of Apache Utils */
@
Benchmark
public
InputStream
apacheReaderInputStream
()
throws
IOException
{
return
new
ReaderInputStream
(
CharSource
.
wrap
(
test1
).
openStream
());
}
/* 4. Using Apache Utils and InputStreamReader*/
@
Benchmark
public
InputStream
apacheInputStreamReader
()
throws
IOException
{
return
IOUtils
.
toInputStream
(
test1
);
}
public
static
void
main
(
String
[]
args
)
throws
RunnerException
{
Options
opt
=
new
OptionsBuilder
()
.
include
(
ConvertStringToInputStreamBenchmark
.
class
.
getSimpleName
())
.
build
();
new
Runner
(
opt
).
run
();
}
}
Back
|
FazBrowse Home
|
New Git URL