FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jruby/bench/BenchParser.java at parallel_boot · MSNexploder/jruby · GitHub
MSNexploder
/
jruby
Public
forked from
jruby/jruby
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
jruby
/
bench
/
BenchParser.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (75 loc) · 3.13 KB
Breadcrumbs
jruby
/
bench
/
BenchParser.java
Copy path
File metadata and controls
84 lines (75 loc) · 3.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import
java
.
io
.
ByteArrayInputStream
;
import
java
.
io
.
ByteArrayOutputStream
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStream
;
import
org
.
jruby
.
Ruby
;
import
org
.
jruby
.
RubyInstanceConfig
;
import
org
.
jruby
.
common
.
NullWarnings
;
import
org
.
jruby
.
lexer
.
yacc
.
LexerSource
;
import
org
.
jruby
.
parser
.
DefaultRubyParser
;
import
org
.
jruby
.
parser
.
ParserConfiguration
;
public
class
BenchParser
{
public
static
final
int
N
=
1000
;
public
static
void
main
(
String
[]
args
) {
try
{
byte
[]
bytes
=
getContents
(
args
);
int
iterations
=
getIterations
(
args
);
int
[]
parsers
=
getParsers
(
args
);
System
.
out
.
println
(
"Parsing "
+
args
[
0
] +
" "
+
iterations
+
" times"
);
DefaultRubyParser
parser
=
new
DefaultRubyParser
();
parser
.
setWarnings
(
new
NullWarnings
(
null
));
Ruby
runtime
=
Ruby
.
getGlobalRuntime
();
RubyInstanceConfig
rconfig
=
new
RubyInstanceConfig
();
ParserConfiguration
config
=
new
ParserConfiguration
(
runtime
,
0
,
false
,
false
,
true
,
rconfig
);
for
(
int
x
=
0
;
x
<
parsers
.
length
;
x
++) {
System
.
out
.
println
(
"Benching parse with "
+ (
parsers
[
x
] ==
0
?
"InputStream"
:
"ByteArray"
) +
"LexerSource"
);
long
start
=
System
.
nanoTime
();
for
(
int
i
=
0
;
i
<
iterations
;
i
++) {
parser
.
parse
(
config
,
getLexerSource
(
args
[
0
],
bytes
,
config
,
parsers
[
x
] ==
0
));
}
System
.
out
.
println
(
"Parse took: "
+ ((
System
.
nanoTime
() -
start
) *
1.0
/
1000000.0
) +
"ms"
);
}
}
catch
(
Exception
e
) {
System
.
err
.
println
(
"Parse bench failed: "
+
e
.
getMessage
());
e
.
printStackTrace
(
System
.
err
);
}
}
private
static
final
LexerSource
getLexerSource
(
String
filename
,
byte
[]
bytes
,
ParserConfiguration
config
,
boolean
useStream
) {
if
(
useStream
) {
return
LexerSource
.
getSource
(
filename
,
new
ByteArrayInputStream
(
bytes
),
null
,
config
);
}
else
{
return
LexerSource
.
getSource
(
filename
,
bytes
,
null
,
config
);
}
}
private
static
int
getIterations
(
String
[]
args
) {
if
(
args
.
length
>
1
) {
return
Integer
.
valueOf
(
args
[
1
]);
}
else
{
return
N
;
}
}
private
static
int
[]
getParsers
(
String
[]
args
) {
if
(
args
.
length
>
2
) {
String
[]
strs
=
args
[
2
].
split
(
","
);
int
[]
parsers
=
new
int
[
strs
.
length
>
2
?
2
:
strs
.
length
];
for
(
int
i
=
0
;
i
<
parsers
.
length
;
i
++) {
parsers
[
i
] =
Integer
.
valueOf
(
strs
[
i
]) -
1
;
}
return
parsers
;
}
else
{
return
new
int
[] {
0
,
1
};
}
}
private
static
byte
[]
getContents
(
String
[]
args
)
throws
IOException
{
InputStream
contents
=
new
FileInputStream
(
args
[
0
]);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
int
bytesRead
=
0
;
byte
[]
buf
=
new
byte
[
16384
];
while
((
bytesRead
=
contents
.
read
(
buf
)) >
0
) {
out
.
write
(
buf
,
0
,
bytesRead
);
}
contents
.
close
();
return
out
.
toByteArray
();
}
}
Back
|
FazBrowse Home
|
New Git URL