@@ -14,28 +14,22 @@ pub fn main() !void {
1414
1515 var db_path : []const u8 = default_db_path ;
1616 var num_lookups = default_num_lookups ;
17- var fields : ? [] const [] const u8 = null ;
17+ var index_bits : u8 = 16 ;
1818 if (args .len > 1 ) db_path = args [1 ];
1919 if (args .len > 2 ) num_lookups = try std .fmt .parseUnsigned (u64 , args [2 ], 10 );
20- if (args .len > 3 ) {
21- var items : [max_mmdb_fields ][]const u8 = undefined ;
22-
23- var it = std .mem .splitScalar (u8 , args [3 ], ',' );
24- var i : usize = 0 ;
25- while (it .next ()) | part | : (i += 1 ) {
26- items [i ] = part ;
27- }
28-
29- fields = items [0.. i ];
30- }
20+ var field_names = if (args .len > 3 )
21+ try maxminddb .Fields (max_mmdb_fields ).parse (args [3 ], ',' )
22+ else
23+ maxminddb .Fields (max_mmdb_fields ){};
24+ if (args .len > 4 ) index_bits = try std .fmt .parseUnsigned (u8 , args [4 ], 10 );
3125
3226 std .debug .print ("Benchmarking with:\n " , .{});
3327 std .debug .print (" Database: {s}\n " , .{db_path });
3428 std .debug .print (" Lookups: {d}\n " , .{num_lookups });
3529 std .debug .print ("Opening database...\n " , .{});
3630
3731 var open_timer = try std .time .Timer .start ();
38- var db = try maxminddb .Reader .mmap (allocator , db_path , .{ .ipv4_index_first_n_bits = 16 });
32+ var db = try maxminddb .Reader .mmap (allocator , db_path , .{ .ipv4_index_first_n_bits = index_bits });
3933 defer db .close ();
4034 const open_time_ms = @as (f64 , @floatFromInt (open_timer .read ())) /
4135 @as (f64 , @floatFromInt (std .time .ns_per_ms ));
@@ -62,7 +56,7 @@ pub fn main() !void {
6256 maxminddb .geolite2 .City ,
6357 arena_allocator ,
6458 ip ,
65- .{ .only = fields },
59+ .{ .only = field_names . only () },
6660 ) catch | err | {
6761 std .debug .print ("! Lookup error for IP {any}: {any}\n " , .{ ip , err });
6862 lookup_errors += 1 ;
0 commit comments