@@ -6,33 +6,33 @@ const default_db_path: []const u8 = "GeoLite2-City.mmdb";
66const default_num_lookups : u64 = 1_000_000 ;
77const max_mmdb_fields = 32 ;
88
9- pub fn main () ! void {
10- const allocator = std .heap .smp_allocator ;
9+ pub fn main (init : std.process.Init ) ! void {
10+ const allocator = init .gpa ;
11+ const io = init .io ;
1112
12- const args = try std .process .argsAlloc (allocator );
13- defer std .process .argsFree (allocator , args );
14-
15- var db_path : []const u8 = default_db_path ;
13+ var args = try std .process .Args .Iterator .initAllocator (init .minimal .args , allocator );
14+ _ = args .skip ();
15+ const db_path = args .next () orelse default_db_path ;
1616 var num_lookups = default_num_lookups ;
1717 var fields : ? []const []const u8 = null ;
1818 var index_bits : u8 = 16 ;
19- if (args .len > 1 ) db_path = args [1 ];
20- if (args .len > 2 ) num_lookups = try std .fmt .parseUnsigned (u64 , args [2 ], 10 );
21- if (args .len > 3 ) {
22- const f = try maxminddb .Fields (max_mmdb_fields ).parse (args [3 ], ',' );
19+ if (args .next ()) | arg | num_lookups = try std .fmt .parseUnsigned (u64 , arg , 10 );
20+ if (args .next ()) | arg | {
21+ const f = try maxminddb .Fields (max_mmdb_fields ).parse (arg , ',' );
2322 fields = f .only ();
2423 }
25- if (args .len > 4 ) index_bits = try std .fmt .parseUnsigned (u8 , args [ 4 ] , 10 );
24+ if (args .next ()) | arg | index_bits = try std .fmt .parseUnsigned (u8 , arg , 10 );
2625
2726 std .debug .print ("Benchmarking with:\n " , .{});
2827 std .debug .print (" Database: {s}\n " , .{db_path });
2928 std .debug .print (" Lookups: {d}\n " , .{num_lookups });
3029 std .debug .print ("Opening database...\n " , .{});
3130
32- var open_timer = try std .time . Timer . start ( );
33- var db = try maxminddb .Reader .mmap (allocator , db_path , .{ .ipv4_index_first_n_bits = index_bits });
31+ const open_start = std .Io . Clock . Timestamp . now ( io , .awake );
32+ var db = try maxminddb .Reader .mmap (allocator , io , db_path , .{ .ipv4_index_first_n_bits = index_bits });
3433 defer db .close ();
35- const open_time_ms = @as (f64 , @floatFromInt (open_timer .read ())) /
34+ const open_elapsed_ns : i64 = @intCast (open_start .untilNow (io ).raw .nanoseconds );
35+ const open_time_ms = @as (f64 , @floatFromInt (open_elapsed_ns )) /
3636 @as (f64 , @floatFromInt (std .time .ns_per_ms ));
3737 std .debug .print ("Database opened successfully in {d} ms. Type: {s}\n " , .{
3838 open_time_ms ,
@@ -44,14 +44,14 @@ pub fn main() !void {
4444 const arena_allocator = arena .allocator ();
4545
4646 std .debug .print ("Starting benchmark...\n " , .{});
47- var timer = try std .time . Timer . start ( );
47+ const timer_start = std .Io . Clock . Timestamp . now ( io , .awake );
4848 var not_found_count : u64 = 0 ;
4949 var lookup_errors : u64 = 0 ;
5050 var ip_bytes : [4 ]u8 = undefined ;
5151
5252 for (0.. num_lookups ) | _ | {
53- std . crypto . random . bytes (& ip_bytes );
54- const ip = std .net .Address . initIp4 ( ip_bytes , 0 ) ;
53+ io . random (& ip_bytes );
54+ const ip : std.Io. net.IpAddress = .{ . ip4 = .{ . bytes = ip_bytes , . port = 0 } } ;
5555
5656 const result = db .lookup (
5757 maxminddb .geolite2 .City ,
@@ -71,7 +71,7 @@ pub fn main() !void {
7171 _ = arena .reset (.retain_capacity );
7272 }
7373
74- const elapsed_ns = timer . read ( );
74+ const elapsed_ns : i64 = @intCast ( timer_start . untilNow ( io ). raw . nanoseconds );
7575 const elapsed_s = @as (f64 , @floatFromInt (elapsed_ns )) /
7676 @as (f64 , @floatFromInt (std .time .ns_per_s ));
7777 const lookups_per_second = if (elapsed_s > 0 )
0 commit comments