@@ -203,3 +203,80 @@ Lookups Per Second (avg):1315986.2950186788
203203```
204204
205205</details >
206+
207+ Use ` within() ` to iterate over all networks in the database using
208+ a cache to avoid re-decoding adjacent networks that share the same record.
209+
210+ ``` zig
211+ var cache: maxminddb.Cache(maxminddb.any.Value) = .{};
212+ defer cache.deinit();
213+
214+ var it = try db.within(
215+ allocator,
216+ maxminddb.any.Value,
217+ maxminddb.Network.all_ipv6,
218+ .{ .cache = &cache },
219+ );
220+ defer it.deinit();
221+
222+ while (try it.next()) |item| {
223+ std.debug.print("{f} {f}\n", .{item.network, item.value});
224+ }
225+ ```
226+
227+ Without a cache each result owns its memory and must be freed with ` item.deinit() ` .
228+
229+ Here are reference results on Apple M2 Pro (full GeoLite2-City scan using ` any.Value ` ):
230+
231+ | Benchmark | Records/sec |
232+ | --- | --- |
233+ | No cache | ~ 1,235,000 |
234+ | Cache (16) | ~ 2,900,000 |
235+
236+ <details >
237+
238+ <summary >no cache (any.Value)</summary >
239+
240+ ``` sh
241+ $ for i in $( seq 1 10) ; do
242+ zig build benchmark_within -Doptimize=ReleaseFast -- GeoLite2-City.mmdb \
243+ 2>&1 | grep ' Records Per Second'
244+ done
245+
246+ Records Per Second: 1216758.945145436
247+ Records Per Second: 1238440.9772222256
248+ Records Per Second: 1234710.6362391203
249+ Records Per Second: 1229527.4688849829
250+ Records Per Second: 1243478.3908140333
251+ Records Per Second: 1226863.3718734735
252+ Records Per Second: 1240073.3248202254
253+ Records Per Second: 1247541.1528026997
254+ Records Per Second: 1230510.441029532
255+ Records Per Second: 1246311.587919839
256+ ```
257+
258+ </details >
259+
260+ <details >
261+
262+ <summary >cache (any.Value)</summary >
263+
264+ ``` sh
265+ $ for i in $( seq 1 10) ; do
266+ zig build benchmark_within_cache -Doptimize=ReleaseFast -- GeoLite2-City.mmdb \
267+ 2>&1 | grep ' Records Per Second'
268+ done
269+
270+ Records Per Second: 2847560.3756875996
271+ Records Per Second: 2925388.867798729
272+ Records Per Second: 2919203.9046571665
273+ Records Per Second: 2814410.555872645
274+ Records Per Second: 2933972.04386147
275+ Records Per Second: 2900700.06160036
276+ Records Per Second: 2922279.338699886
277+ Records Per Second: 2862525.847598088
278+ Records Per Second: 2916760.542913819
279+ Records Per Second: 2908245.98918392
280+ ```
281+
282+ </details >
0 commit comments