iptocc 3.2.2__tar.gz → 3.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {iptocc-3.2.2 → iptocc-3.3.0}/Cargo.lock +7 -7
- {iptocc-3.2.2 → iptocc-3.3.0}/PKG-INFO +17 -6
- iptocc-3.3.0/README.md +66 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/Cargo.toml +1 -1
- iptocc-3.3.0/bindings/python/README.md +66 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/crate/Cargo.toml +1 -1
- iptocc-3.3.0/crate/README.md +60 -0
- iptocc-3.3.0/crate/benches/lookup.rs +127 -0
- iptocc-3.3.0/crate/src/bin/generate-data.rs +731 -0
- iptocc-3.3.0/crate/src/data/v4.bin +0 -0
- iptocc-3.3.0/crate/src/data/v6.bin +1840 -4
- iptocc-3.3.0/crate/src/format.rs +24 -0
- iptocc-3.3.0/crate/src/lib.rs +383 -0
- iptocc-3.2.2/README.md +0 -55
- iptocc-3.2.2/bindings/python/README.md +0 -55
- iptocc-3.2.2/crate/README.md +0 -38
- iptocc-3.2.2/crate/benches/lookup.rs +0 -59
- iptocc-3.2.2/crate/src/bin/generate-data.rs +0 -400
- iptocc-3.2.2/crate/src/data/v4.bin +0 -0
- iptocc-3.2.2/crate/src/data/v6.bin +0 -3752
- iptocc-3.2.2/crate/src/format.rs +0 -5
- iptocc-3.2.2/crate/src/lib.rs +0 -248
- {iptocc-3.2.2 → iptocc-3.3.0}/Cargo.toml +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/LICENSE-APACHE +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/LICENSE-MIT +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/LICENSE-APACHE +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/LICENSE-MIT +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/benchmarks/bench_lookup.py +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/src/lib.rs +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/tests/test_api.py +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/bindings/python/uv.lock +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/crate/LICENSE-APACHE +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/crate/LICENSE-MIT +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/crate/src/main.rs +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/crate/tests/api.rs +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/pyproject.toml +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/python/iptocc/__init__.py +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/python/iptocc/cli.py +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/python/iptocc/iptocc.pyi +0 -0
- {iptocc-3.2.2 → iptocc-3.3.0}/python/iptocc/py.typed +0 -0
|
@@ -350,7 +350,7 @@ dependencies = [
|
|
|
350
350
|
|
|
351
351
|
[[package]]
|
|
352
352
|
name = "iptocc"
|
|
353
|
-
version = "1.
|
|
353
|
+
version = "1.4.0"
|
|
354
354
|
dependencies = [
|
|
355
355
|
"clap",
|
|
356
356
|
"criterion",
|
|
@@ -359,7 +359,7 @@ dependencies = [
|
|
|
359
359
|
|
|
360
360
|
[[package]]
|
|
361
361
|
name = "iptocc-py"
|
|
362
|
-
version = "3.
|
|
362
|
+
version = "3.3.0"
|
|
363
363
|
dependencies = [
|
|
364
364
|
"iptocc",
|
|
365
365
|
"pyo3",
|
|
@@ -367,7 +367,7 @@ dependencies = [
|
|
|
367
367
|
|
|
368
368
|
[[package]]
|
|
369
369
|
name = "iptocc-wasm"
|
|
370
|
-
version = "1.
|
|
370
|
+
version = "1.3.0"
|
|
371
371
|
dependencies = [
|
|
372
372
|
"iptocc",
|
|
373
373
|
"js-sys",
|
|
@@ -407,9 +407,9 @@ dependencies = [
|
|
|
407
407
|
|
|
408
408
|
[[package]]
|
|
409
409
|
name = "libc"
|
|
410
|
-
version = "0.2.
|
|
410
|
+
version = "0.2.186"
|
|
411
411
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
412
|
-
checksum = "
|
|
412
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
413
413
|
|
|
414
414
|
[[package]]
|
|
415
415
|
name = "memchr"
|
|
@@ -936,9 +936,9 @@ dependencies = [
|
|
|
936
936
|
|
|
937
937
|
[[package]]
|
|
938
938
|
name = "winnow"
|
|
939
|
-
version = "1.0.
|
|
939
|
+
version = "1.0.2"
|
|
940
940
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
941
|
-
checksum = "
|
|
941
|
+
checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0"
|
|
942
942
|
dependencies = [
|
|
943
943
|
"memchr",
|
|
944
944
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iptocc
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.3.0
|
|
4
4
|
Classifier: Programming Language :: Python :: 3.10
|
|
5
5
|
Classifier: Programming Language :: Python :: 3.11
|
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -23,10 +23,15 @@ Project-URL: Repository, https://github.com/roniemartinez/IPToCC
|
|
|
23
23
|
|
|
24
24
|
# iptocc
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
[](https://pypi.org/project/iptocc/)
|
|
27
|
+
[](https://pypi.org/project/iptocc/)
|
|
28
|
+

|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
Python bindings for the [`iptocc`](https://crates.io/crates/iptocc) Rust crate. Offline IPv4 and IPv6 to ISO 3166-1 alpha-2 country code lookup.
|
|
31
|
+
|
|
32
|
+
> **Note:** Country codes reflect the country **assigned** by a **Regional Internet Registry (RIR)** to each IP block, not where the block is being used. RIR data agrees with MaxMind for **~95%** of IPv4 addresses and has minimal discrepancies for IPv6 ([Zander, 2012](https://figshare.swinburne.edu.au/articles/report/On_the_accuracy_of_IP_geolocation_based_on_IP_allocation_data/26254751)).
|
|
33
|
+
|
|
34
|
+
> **Important:** iptocc 3.0 is a complete Rust rewrite. Versions 2.x and earlier were pure Python on top of pandas. The public API stays mostly compatible (see migration notes below), single-lookup latency dropped from ~78 ms to ~44-141 ns, and a batch API was added.
|
|
30
35
|
|
|
31
36
|
## Features
|
|
32
37
|
|
|
@@ -34,8 +39,8 @@ Fast, offline IPv4/IPv6 to ISO 3166-1 alpha-2 country code lookup for Python.
|
|
|
34
39
|
- IPv4 and IPv6 in one call
|
|
35
40
|
- Single string OR batch (any iterable of strings)
|
|
36
41
|
- Lookup data embedded in the wheel; no runtime file I/O
|
|
37
|
-
- `iptocc` CLI installed
|
|
38
|
-
-
|
|
42
|
+
- `iptocc` CLI installed with `pip install iptocc`
|
|
43
|
+
- Data refreshed nightly from the five Regional Internet Registries
|
|
39
44
|
|
|
40
45
|
## Install
|
|
41
46
|
|
|
@@ -77,3 +82,9 @@ from iptocc import country_code
|
|
|
77
82
|
cc = country_code("8.8.8.8") # returns None on miss
|
|
78
83
|
```
|
|
79
84
|
|
|
85
|
+
## See also
|
|
86
|
+
|
|
87
|
+
- [iptocc](https://crates.io/crates/iptocc) — the Rust crate this binding is built on
|
|
88
|
+
- [@roniemartinez/iptocc](https://www.npmjs.com/package/@roniemartinez/iptocc) — WASM/JavaScript bindings
|
|
89
|
+
- [GitHub repo](https://github.com/roniemartinez/IPToCC)
|
|
90
|
+
|
iptocc-3.3.0/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# iptocc
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/iptocc/)
|
|
4
|
+
[](https://pypi.org/project/iptocc/)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Python bindings for the [`iptocc`](https://crates.io/crates/iptocc) Rust crate. Offline IPv4 and IPv6 to ISO 3166-1 alpha-2 country code lookup.
|
|
8
|
+
|
|
9
|
+
> **Note:** Country codes reflect the country **assigned** by a **Regional Internet Registry (RIR)** to each IP block, not where the block is being used. RIR data agrees with MaxMind for **~95%** of IPv4 addresses and has minimal discrepancies for IPv6 ([Zander, 2012](https://figshare.swinburne.edu.au/articles/report/On_the_accuracy_of_IP_geolocation_based_on_IP_allocation_data/26254751)).
|
|
10
|
+
|
|
11
|
+
> **Important:** iptocc 3.0 is a complete Rust rewrite. Versions 2.x and earlier were pure Python on top of pandas. The public API stays mostly compatible (see migration notes below), single-lookup latency dropped from ~78 ms to ~44-141 ns, and a batch API was added.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Offline lookup, no API keys, no network calls
|
|
16
|
+
- IPv4 and IPv6 in one call
|
|
17
|
+
- Single string OR batch (any iterable of strings)
|
|
18
|
+
- Lookup data embedded in the wheel; no runtime file I/O
|
|
19
|
+
- `iptocc` CLI installed with `pip install iptocc`
|
|
20
|
+
- Data refreshed nightly from the five Regional Internet Registries
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
Requires Python 3.10 or newer.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install iptocc
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from iptocc import country_code
|
|
34
|
+
|
|
35
|
+
country_code("8.8.8.8") # "US"
|
|
36
|
+
country_code(["8.8.8.8", "1.0.16.1"]) # ["US", "JP"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A CLI is installed alongside the library:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
$ iptocc 8.8.8.8 1.0.16.1
|
|
43
|
+
8.8.8.8 US
|
|
44
|
+
1.0.16.1 JP
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Migrating from 2.x
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# 2.x
|
|
51
|
+
from iptocc import get_country_code, CountryCodeNotFound
|
|
52
|
+
try:
|
|
53
|
+
cc = get_country_code("8.8.8.8")
|
|
54
|
+
except CountryCodeNotFound:
|
|
55
|
+
cc = None
|
|
56
|
+
|
|
57
|
+
# 3.x
|
|
58
|
+
from iptocc import country_code
|
|
59
|
+
cc = country_code("8.8.8.8") # returns None on miss
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## See also
|
|
63
|
+
|
|
64
|
+
- [iptocc](https://crates.io/crates/iptocc) — the Rust crate this binding is built on
|
|
65
|
+
- [@roniemartinez/iptocc](https://www.npmjs.com/package/@roniemartinez/iptocc) — WASM/JavaScript bindings
|
|
66
|
+
- [GitHub repo](https://github.com/roniemartinez/IPToCC)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# iptocc
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/iptocc/)
|
|
4
|
+
[](https://pypi.org/project/iptocc/)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Python bindings for the [`iptocc`](https://crates.io/crates/iptocc) Rust crate. Offline IPv4 and IPv6 to ISO 3166-1 alpha-2 country code lookup.
|
|
8
|
+
|
|
9
|
+
> **Note:** Country codes reflect the country **assigned** by a **Regional Internet Registry (RIR)** to each IP block, not where the block is being used. RIR data agrees with MaxMind for **~95%** of IPv4 addresses and has minimal discrepancies for IPv6 ([Zander, 2012](https://figshare.swinburne.edu.au/articles/report/On_the_accuracy_of_IP_geolocation_based_on_IP_allocation_data/26254751)).
|
|
10
|
+
|
|
11
|
+
> **Important:** iptocc 3.0 is a complete Rust rewrite. Versions 2.x and earlier were pure Python on top of pandas. The public API stays mostly compatible (see migration notes below), single-lookup latency dropped from ~78 ms to ~44-141 ns, and a batch API was added.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Offline lookup, no API keys, no network calls
|
|
16
|
+
- IPv4 and IPv6 in one call
|
|
17
|
+
- Single string OR batch (any iterable of strings)
|
|
18
|
+
- Lookup data embedded in the wheel; no runtime file I/O
|
|
19
|
+
- `iptocc` CLI installed with `pip install iptocc`
|
|
20
|
+
- Data refreshed nightly from the five Regional Internet Registries
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
Requires Python 3.10 or newer.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install iptocc
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from iptocc import country_code
|
|
34
|
+
|
|
35
|
+
country_code("8.8.8.8") # "US"
|
|
36
|
+
country_code(["8.8.8.8", "1.0.16.1"]) # ["US", "JP"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
A CLI is installed alongside the library:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
$ iptocc 8.8.8.8 1.0.16.1
|
|
43
|
+
8.8.8.8 US
|
|
44
|
+
1.0.16.1 JP
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Migrating from 2.x
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# 2.x
|
|
51
|
+
from iptocc import get_country_code, CountryCodeNotFound
|
|
52
|
+
try:
|
|
53
|
+
cc = get_country_code("8.8.8.8")
|
|
54
|
+
except CountryCodeNotFound:
|
|
55
|
+
cc = None
|
|
56
|
+
|
|
57
|
+
# 3.x
|
|
58
|
+
from iptocc import country_code
|
|
59
|
+
cc = country_code("8.8.8.8") # returns None on miss
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## See also
|
|
63
|
+
|
|
64
|
+
- [iptocc](https://crates.io/crates/iptocc) — the Rust crate this binding is built on
|
|
65
|
+
- [@roniemartinez/iptocc](https://www.npmjs.com/package/@roniemartinez/iptocc) — WASM/JavaScript bindings
|
|
66
|
+
- [GitHub repo](https://github.com/roniemartinez/IPToCC)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# iptocc
|
|
2
|
+
|
|
3
|
+
[](https://crates.io/crates/iptocc)
|
|
4
|
+
[](https://github.com/roniemartinez/IPToCC/actions/workflows/ci.yml)
|
|
5
|
+
[](https://www.rust-lang.org/)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Fast, offline IPv4/IPv6 to ISO 3166-1 alpha-2 country code lookup.
|
|
9
|
+
|
|
10
|
+
Python and WASM bindings built on this crate live in the [same repository](https://github.com/roniemartinez/IPToCC).
|
|
11
|
+
|
|
12
|
+
> [!NOTE]
|
|
13
|
+
> Country codes reflect the country **assigned** by a **Regional Internet Registry (RIR)** to each IP block, not where the block is being used. RIR data agrees with MaxMind for **~95%** of IPv4 addresses and has minimal discrepancies for IPv6 ([Zander, 2012](https://figshare.swinburne.edu.au/articles/report/On_the_accuracy_of_IP_geolocation_based_on_IP_allocation_data/26254751)).
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Offline lookup, no API keys, no network calls
|
|
18
|
+
- IPv4 and IPv6 in one call
|
|
19
|
+
- Generic `country_code<T: IpAddress>(input)` accepts `&str`, `String`, `Ipv4Addr`, `Ipv6Addr`, or `IpAddr`
|
|
20
|
+
- Batch `country_codes` takes any iterable of the above
|
|
21
|
+
- Lookup data embedded via `include_bytes!`; no runtime file I/O
|
|
22
|
+
- Nanosecond-scale lookups: ~1.3 ns typed, ~6 ns string. See [BENCHMARK.md](../BENCHMARK.md).
|
|
23
|
+
- `iptocc` CLI installed with `cargo install iptocc`
|
|
24
|
+
- Data refreshed nightly from the five Regional Internet Registries (RIRs)
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cargo add iptocc
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```rust
|
|
35
|
+
use iptocc::{country_code, country_codes};
|
|
36
|
+
|
|
37
|
+
assert_eq!(country_code("8.8.8.8"), Some("US"));
|
|
38
|
+
assert_eq!(country_code("2001:4860:4860::8888"), Some("US"));
|
|
39
|
+
assert_eq!(country_code("10.0.0.0"), None);
|
|
40
|
+
|
|
41
|
+
let codes = country_codes(["8.8.8.8", "1.0.16.1"]);
|
|
42
|
+
assert_eq!(codes, vec![Some("US"), Some("JP")]);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Typed inputs are also accepted and skip the string parsing step:
|
|
46
|
+
|
|
47
|
+
```rust
|
|
48
|
+
use std::net::Ipv4Addr;
|
|
49
|
+
use iptocc::country_code;
|
|
50
|
+
|
|
51
|
+
assert_eq!(country_code(Ipv4Addr::new(8, 8, 8, 8)), Some("US"));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
A CLI is installed by `cargo install iptocc`:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
$ iptocc 8.8.8.8 1.0.16.1
|
|
58
|
+
8.8.8.8 US
|
|
59
|
+
1.0.16.1 JP
|
|
60
|
+
```
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
use core::net::{Ipv4Addr, Ipv6Addr};
|
|
2
|
+
|
|
3
|
+
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
|
|
4
|
+
use std::hint::black_box;
|
|
5
|
+
|
|
6
|
+
const V4_CASES: &[(&str, &str)] = &[
|
|
7
|
+
("afrinic", "41.0.0.1"),
|
|
8
|
+
("apnic", "1.0.16.1"),
|
|
9
|
+
("arin", "8.8.8.8"),
|
|
10
|
+
("lacnic", "200.160.0.1"),
|
|
11
|
+
("ripencc", "193.0.6.139"),
|
|
12
|
+
("miss_private", "10.0.0.0"),
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const V6_CASES: &[(&str, &str)] = &[
|
|
16
|
+
("afrinic", "2001:4200::1"),
|
|
17
|
+
("apnic", "2001:200::1"),
|
|
18
|
+
("arin", "2001:4860:4860::8888"),
|
|
19
|
+
("lacnic", "2001:1280::1"),
|
|
20
|
+
("ripencc", "2001:67c:18::1"),
|
|
21
|
+
("miss_loopback", "::1"),
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
fn bench_v4(c: &mut Criterion) {
|
|
25
|
+
let mut group = c.benchmark_group("v4");
|
|
26
|
+
for (name, ip) in V4_CASES {
|
|
27
|
+
group.bench_with_input(*name, ip, |b, &ip| b.iter(|| iptocc::country_code(black_box(ip))));
|
|
28
|
+
}
|
|
29
|
+
group.finish();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fn bench_v6(c: &mut Criterion) {
|
|
33
|
+
let mut group = c.benchmark_group("v6");
|
|
34
|
+
for (name, ip) in V6_CASES {
|
|
35
|
+
group.bench_with_input(*name, ip, |b, &ip| b.iter(|| iptocc::country_code(black_box(ip))));
|
|
36
|
+
}
|
|
37
|
+
group.finish();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn bench_v4_typed(c: &mut Criterion) {
|
|
41
|
+
let mut group = c.benchmark_group("v4_typed");
|
|
42
|
+
for (name, ip) in V4_CASES {
|
|
43
|
+
let parsed: Ipv4Addr = ip.parse().unwrap();
|
|
44
|
+
group.bench_with_input(*name, &parsed, |b, &ip| b.iter(|| iptocc::country_code(black_box(ip))));
|
|
45
|
+
}
|
|
46
|
+
group.finish();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn bench_v6_typed(c: &mut Criterion) {
|
|
50
|
+
let mut group = c.benchmark_group("v6_typed");
|
|
51
|
+
for (name, ip) in V6_CASES {
|
|
52
|
+
let parsed: Ipv6Addr = ip.parse().unwrap();
|
|
53
|
+
group.bench_with_input(*name, &parsed, |b, &ip| b.iter(|| iptocc::country_code(black_box(ip))));
|
|
54
|
+
}
|
|
55
|
+
group.finish();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn bench_batch_v4(c: &mut Criterion) {
|
|
59
|
+
let mut group = c.benchmark_group("batch_v4");
|
|
60
|
+
for &n in &[10usize, 100, 1000, 10000] {
|
|
61
|
+
let addrs: Vec<&str> = V4_CASES.iter().map(|(_, ip)| *ip).cycle().take(n).collect();
|
|
62
|
+
group.throughput(Throughput::Elements(n as u64));
|
|
63
|
+
group.bench_with_input(format!("n={n}"), &addrs, |b, addrs| {
|
|
64
|
+
b.iter(|| iptocc::country_codes(black_box(addrs.iter().copied())))
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
group.finish();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fn bench_batch_v4_typed(c: &mut Criterion) {
|
|
71
|
+
let mut group = c.benchmark_group("batch_v4_typed");
|
|
72
|
+
for &n in &[10usize, 100, 1000, 10000] {
|
|
73
|
+
let addrs: Vec<Ipv4Addr> = V4_CASES
|
|
74
|
+
.iter()
|
|
75
|
+
.map(|(_, ip)| ip.parse().unwrap())
|
|
76
|
+
.cycle()
|
|
77
|
+
.take(n)
|
|
78
|
+
.collect();
|
|
79
|
+
group.throughput(Throughput::Elements(n as u64));
|
|
80
|
+
group.bench_with_input(format!("n={n}"), &addrs, |b, addrs| {
|
|
81
|
+
b.iter(|| iptocc::country_codes(black_box(addrs.iter().copied())))
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
group.finish();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn bench_batch_v6(c: &mut Criterion) {
|
|
88
|
+
let mut group = c.benchmark_group("batch_v6");
|
|
89
|
+
for &n in &[10usize, 100, 1000, 10000] {
|
|
90
|
+
let addrs: Vec<&str> = V6_CASES.iter().map(|(_, ip)| *ip).cycle().take(n).collect();
|
|
91
|
+
group.throughput(Throughput::Elements(n as u64));
|
|
92
|
+
group.bench_with_input(format!("n={n}"), &addrs, |b, addrs| {
|
|
93
|
+
b.iter(|| iptocc::country_codes(black_box(addrs.iter().copied())))
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
group.finish();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn bench_batch_v6_typed(c: &mut Criterion) {
|
|
100
|
+
let mut group = c.benchmark_group("batch_v6_typed");
|
|
101
|
+
for &n in &[10usize, 100, 1000, 10000] {
|
|
102
|
+
let addrs: Vec<Ipv6Addr> = V6_CASES
|
|
103
|
+
.iter()
|
|
104
|
+
.map(|(_, ip)| ip.parse().unwrap())
|
|
105
|
+
.cycle()
|
|
106
|
+
.take(n)
|
|
107
|
+
.collect();
|
|
108
|
+
group.throughput(Throughput::Elements(n as u64));
|
|
109
|
+
group.bench_with_input(format!("n={n}"), &addrs, |b, addrs| {
|
|
110
|
+
b.iter(|| iptocc::country_codes(black_box(addrs.iter().copied())))
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
group.finish();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
criterion_group!(
|
|
117
|
+
benches,
|
|
118
|
+
bench_v4,
|
|
119
|
+
bench_v6,
|
|
120
|
+
bench_v4_typed,
|
|
121
|
+
bench_v6_typed,
|
|
122
|
+
bench_batch_v4,
|
|
123
|
+
bench_batch_v4_typed,
|
|
124
|
+
bench_batch_v6,
|
|
125
|
+
bench_batch_v6_typed
|
|
126
|
+
);
|
|
127
|
+
criterion_main!(benches);
|