A JMH benchmark comparing two IP-to-country lookup strategies using the IP2Location dataset.
| Strategy | Description |
|---|---|
| Binary Search | Collections.binarySearch on a sorted List<IpLocation> with a custom Comparable<Long> |
| Guava TreeRangeMap | RangeMap.get() on a TreeRangeMap<Long, IpLocation> with closed ranges |
Both load the same IPCountry.csv dataset (IP range start/end, country code, country name) and resolve a random IP address to its country.
- Java 8+
IPCountry.csvin the project root (IP2Location DB1 CSV format)
# Run benchmarks (3 forks, 3 warmup iterations, 3 measurement iterations)
./gradlew jmh
# Run unit tests
./gradlew testsrc/
main/java/com/yuganji/
IpLocation.java # IP range data class (start, end, code, country)
IpLocationData.java # CSV loader -> sorted List + Guava RangeMap
NetUtil.java # Random IP generation & IP-to-long conversion
jmh/java/benchmark/
BenchmarkIpLocation.java # JMH benchmark (Throughput, ops/sec)
test/java/com/yuganji/
BenchmarkIpLocationTest.java # Correctness tests for both strategies
test/resources/
ip2loc_test_dataset.csv # Test sample data
| Parameter | Value |
|---|---|
| Mode | Throughput (ops/sec) |
| Forks | 3 |
| Warmup Iterations | 3 |
| Measurement Iterations | 3 |
- Guava -
TreeRangeMapfor range-based lookup - Univocity Parsers - CSV parsing
- JMH - Microbenchmark harness
- Lombok - Boilerplate reduction
- JUnit 5 - Testing
This project uses the IP2Location dataset. Please refer to IP2Location's terms of use for dataset licensing.