From e7e1efbd57544f57d95fe8a731cf2f8f67fa7201 Mon Sep 17 00:00:00 2001 From: mikkelam Date: Thu, 19 Jun 2025 14:01:54 +0200 Subject: [PATCH] clean unused code --- src/cli/root.zig | 2 +- src/lib/bandwidth.zig | 11 ++----- src/lib/http_speed_tester_v2.zig | 50 ++++++++++---------------------- src/lib/progress.zig | 5 ---- 4 files changed, 20 insertions(+), 48 deletions(-) diff --git a/src/cli/root.zig b/src/cli/root.zig index 329debc..55ae95b 100644 --- a/src/cli/root.zig +++ b/src/cli/root.zig @@ -58,7 +58,7 @@ pub fn build(allocator: std.mem.Allocator) !*zli.Command { const root = try zli.Command.init(allocator, .{ .name = "fast-cli", .description = "Estimate connection speed using fast.com", - version = null, + .version = null, }, run); try root.addFlag(https_flag); diff --git a/src/lib/bandwidth.zig b/src/lib/bandwidth.zig index c09e506..a9bf601 100644 --- a/src/lib/bandwidth.zig +++ b/src/lib/bandwidth.zig @@ -41,11 +41,6 @@ pub const BandwidthMeter = struct { self._bytes_transferred = total_bytes; } - pub fn record_bytes(self: *BandwidthMeter, byte_count: usize) void { - assert(self._started); - self._bytes_transferred += byte_count; - } - pub fn bandwidth(self: *BandwidthMeter) f64 { if (!self._started) return 0; @@ -97,8 +92,8 @@ test "BandwidthMeter record_bytes" { var meter = BandwidthMeter.init(); try meter.start(); - meter.record_bytes(1000); - meter.record_bytes(500); + meter.update_total(1000); + meter.update_total(1500); // Just test that bandwidth calculation works const bw = meter.bandwidth(); @@ -109,7 +104,7 @@ test "BandwidthMeter bandwidth calculation" { var meter = BandwidthMeter.init(); try meter.start(); - meter.record_bytes(1000); // 1000 bytes + meter.update_total(1000); // 1000 bytes // Sleep briefly to ensure time passes std.time.sleep(std.time.ns_per_ms * 10); // 10ms diff --git a/src/lib/http_speed_tester_v2.zig b/src/lib/http_speed_tester_v2.zig index 1aea587..b5242cc 100644 --- a/src/lib/http_speed_tester_v2.zig +++ b/src/lib/http_speed_tester_v2.zig @@ -15,9 +15,9 @@ pub const SpeedTestResult = struct { speed: SpeedMeasurement, /// Convert bytes per second to optimal unit for display (in bits per second) - pub fn fromBytesPerSecond(speed_bytes_per_sec: f64) SpeedTestResult { + pub fn fromBytesPerSecond(bytes_per_second: f64) SpeedTestResult { // Convert bytes/s to bits/s - const speed_bits_per_sec = speed_bytes_per_sec * 8.0; + const speed_bits_per_sec = bytes_per_second * 8.0; const abs_speed = @abs(speed_bits_per_sec); const speed_measurement = if (abs_speed >= 1_000_000_000) @@ -50,20 +50,6 @@ pub const HTTPSpeedTester = struct { _ = self; } - pub fn set_concurrent_connections(self: *HTTPSpeedTester, count: u32) void { - self.concurrent_connections = @min(count, 8); // Max 8 connections - } - - pub fn set_progress_update_interval_ms(self: *HTTPSpeedTester, interval_ms: u32) void { - self.progress_update_interval_ms = interval_ms; - } - - // Clean duration-based download with optional progress callback - pub fn measure_download_speed_duration(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { - const strategy = measurement_strategy.createDurationStrategy(duration_seconds, self.progress_update_interval_ms); - return self.measureDownloadSpeedWithDuration(urls, strategy, ProgressType, progress_callback); - } - // Fast.com-style stability-based download with optional progress callback pub fn measure_download_speed_fast_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { var strategy = measurement_strategy.createStabilityStrategy(self.allocator, criteria); @@ -76,16 +62,6 @@ pub const HTTPSpeedTester = struct { return self.measure_download_speed_fast_stability_duration(urls, criteria, null, {}); } - // Clean duration-based upload with optional progress callback - pub fn measure_upload_speed_duration(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { - const upload_data = try self.allocator.alloc(u8, 4 * 1024 * 1024); - defer self.allocator.free(upload_data); - @memset(upload_data, 'A'); - - const strategy = measurement_strategy.createDurationStrategy(duration_seconds, self.progress_update_interval_ms); - return self.measureUploadSpeedWithDuration(urls, strategy, upload_data, ProgressType, progress_callback); - } - // Fast.com-style stability-based upload with optional progress callback pub fn measure_upload_speed_fast_stability_duration(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { const upload_data = try self.allocator.alloc(u8, 4 * 1024 * 1024); @@ -104,14 +80,25 @@ pub const HTTPSpeedTester = struct { // Convenience helpers for cleaner API usage + // Clean duration-based download with optional progress callback + pub fn measure_download_speed_duration(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { + const strategy = measurement_strategy.createDurationStrategy(duration_seconds, self.progress_update_interval_ms); + return self.measureDownloadSpeedWithDuration(urls, strategy, ProgressType, progress_callback); + } + /// Simple download speed measurement without progress callback pub fn measureDownloadSpeed(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32) !SpeedTestResult { return self.measure_download_speed_duration(urls, duration_seconds, null, {}); } - /// Download speed measurement with progress callback (type inferred) - pub fn measureDownloadSpeedWithProgress(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, progress_callback: anytype) !SpeedTestResult { - return self.measure_download_speed_duration(urls, duration_seconds, @TypeOf(progress_callback), progress_callback); + // Clean duration-based upload with optional progress callback + pub fn measure_upload_speed_duration(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, comptime ProgressType: ?type, progress_callback: if (ProgressType) |T| T else void) !SpeedTestResult { + const upload_data = try self.allocator.alloc(u8, 4 * 1024 * 1024); + defer self.allocator.free(upload_data); + @memset(upload_data, 'A'); + + const strategy = measurement_strategy.createDurationStrategy(duration_seconds, self.progress_update_interval_ms); + return self.measureUploadSpeedWithDuration(urls, strategy, upload_data, ProgressType, progress_callback); } /// Simple upload speed measurement without progress callback @@ -119,11 +106,6 @@ pub const HTTPSpeedTester = struct { return self.measure_upload_speed_duration(urls, duration_seconds, null, {}); } - /// Upload speed measurement with progress callback (type inferred) - pub fn measureUploadSpeedWithProgress(self: *HTTPSpeedTester, urls: []const []const u8, duration_seconds: u32, progress_callback: anytype) !SpeedTestResult { - return self.measure_upload_speed_duration(urls, duration_seconds, @TypeOf(progress_callback), progress_callback); - } - /// Fast stability download speed measurement with progress callback (type inferred) pub fn measureDownloadSpeedWithFastStabilityProgress(self: *HTTPSpeedTester, urls: []const []const u8, criteria: StabilityCriteria, progress_callback: anytype) !SpeedTestResult { return self.measure_download_speed_fast_stability_duration(urls, criteria, @TypeOf(progress_callback), progress_callback); diff --git a/src/lib/progress.zig b/src/lib/progress.zig index 15dfd10..062404b 100644 --- a/src/lib/progress.zig +++ b/src/lib/progress.zig @@ -29,8 +29,3 @@ pub fn createCallback(context: anytype, comptime updateFn: anytype) ProgressCall .updateFn = wrapper.call, }; } - -/// Check if a value is a valid progress callback at comptime -pub fn isProgressCallback(comptime T: type) bool { - return @hasDecl(T, "call") and @hasField(T, "context"); -}