FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GeoIP2-java/sample/Benchmark.java at main · whilein/GeoIP2-java · GitHub
whilein
/
GeoIP2-java
Public
forked from
maxmind/GeoIP2-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
GeoIP2-java
/
sample
/
Benchmark.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (64 loc) · 2.54 KB
Breadcrumbs
GeoIP2-java
/
sample
/
Benchmark.java
Copy path
File metadata and controls
72 lines (64 loc) · 2.54 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
import
java
.
io
.
File
;
import
java
.
io
.
IOException
;
import
java
.
net
.
InetAddress
;
import
java
.
net
.
UnknownHostException
;
import
java
.
util
.
Random
;
import
com
.
maxmind
.
db
.
CHMCache
;
import
com
.
maxmind
.
db
.
NoCache
;
import
com
.
maxmind
.
db
.
NodeCache
;
import
com
.
maxmind
.
db
.
Reader
.
FileMode
;
import
com
.
maxmind
.
geoip2
.
DatabaseReader
;
import
com
.
maxmind
.
geoip2
.
exception
.
AddressNotFoundException
;
import
com
.
maxmind
.
geoip2
.
exception
.
GeoIp2Exception
;
import
com
.
maxmind
.
geoip2
.
model
.
CityResponse
;
public
class
Benchmark
{
private
final
static
int
COUNT
=
1000000
;
private
final
static
int
WARMUPS
=
3
;
private
final
static
int
BENCHMARKS
=
5
;
private
final
static
boolean
TRACE
=
false
;
public
static
void
main
(
String
[]
args
)
throws
GeoIp2Exception
,
IOException
{
File
file
=
new
File
(
args
.
length
>
0
?
args
[
0
] :
"GeoLite2-City.mmdb"
);
System
.
out
.
println
(
"No caching"
);
loop
(
"Warming up"
,
file
,
WARMUPS
,
NoCache
.
getInstance
());
loop
(
"Benchmarking"
,
file
,
BENCHMARKS
,
NoCache
.
getInstance
());
System
.
out
.
println
(
"With caching"
);
loop
(
"Warming up"
,
file
,
WARMUPS
,
new
CHMCache
());
loop
(
"Benchmarking"
,
file
,
BENCHMARKS
,
new
CHMCache
());
}
private
static
void
loop
(
String
msg
,
File
file
,
int
loops
,
NodeCache
cache
)
throws
GeoIp2Exception
,
IOException
{
System
.
out
.
println
(
msg
);
for
(
int
i
=
0
;
i
<
loops
;
i
++) {
DatabaseReader
r
=
new
DatabaseReader
.
Builder
(
file
).
fileMode
(
FileMode
.
MEMORY_MAPPED
).
withCache
(
cache
)
.
build
();
bench
(
r
,
COUNT
,
i
);
}
System
.
out
.
println
();
}
private
static
void
bench
(
DatabaseReader
r
,
int
count
,
int
seed
)
throws
GeoIp2Exception
,
UnknownHostException
{
Random
random
=
new
Random
(
seed
);
long
startTime
=
System
.
nanoTime
();
byte
[]
address
=
new
byte
[
4
];
for
(
int
i
=
0
;
i
<
count
;
i
++) {
random
.
nextBytes
(
address
);
InetAddress
ip
=
InetAddress
.
getByAddress
(
address
);
CityResponse
t
;
try
{
t
=
r
.
city
(
ip
);
}
catch
(
AddressNotFoundException
|
IOException
e
) {
}
if
(
TRACE
) {
if
(
i
%
50000
==
0
) {
System
.
out
.
println
(
i
+
" "
+
ip
);
System
.
out
.
println
(
t
);
}
}
}
long
endTime
=
System
.
nanoTime
();
long
duration
=
endTime
-
startTime
;
long
qps
=
count
*
1000000000L
/
duration
;
System
.
out
.
println
(
"Requests per second: "
+
qps
);
}
}
Back
|
FazBrowse Home
|
New Git URL