File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments