Skip to content

Commit 4c47826

Browse files
committed
Added benchmark code
1 parent dd8ee2e commit 4c47826

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

sample/Benchmark.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.File;
2+
import java.io.IOException;
3+
import java.net.InetAddress;
4+
import java.util.Random;
5+
6+
import com.fasterxml.jackson.databind.JsonNode;
7+
import com.google.common.net.InetAddresses;
8+
import com.maxmind.maxminddb.MaxMindDbException;
9+
import com.maxmind.maxminddb.Reader;
10+
import com.maxmind.maxminddb.Reader.FileMode;
11+
12+
public class Benchmark {
13+
14+
public static void main(String[] args) throws IOException,
15+
MaxMindDbException {
16+
File file = new File("GeoIP2-City.mmdb");
17+
18+
Reader r = new Reader(file, FileMode.MEMORY_MAPPED);
19+
Random random = new Random();
20+
int count = 1000000;
21+
long startTime = System.nanoTime();
22+
for (int i = 0; i < count; i++) {
23+
InetAddress ip = InetAddresses.fromInteger(random.nextInt());
24+
if (i % 50000 == 0) {
25+
System.out.println(i + " " + ip);
26+
}
27+
JsonNode t = r.get(ip);
28+
}
29+
long endTime = System.nanoTime();
30+
31+
long duration = endTime - startTime;
32+
System.out.println("Requests per second: " + count * 1000000000.0
33+
/ (duration));
34+
}
35+
}

0 commit comments

Comments
 (0)