clean up dead code and improve stats

This commit is contained in:
Jeffrey C. Ollie 2024-02-10 20:14:16 -06:00
parent bd361e40ee
commit e0c2a5c95e
Signed by: jeff
GPG key ID: 6F86035A6D97044E

View file

@ -8,43 +8,6 @@ fn signal(_: c_int) callconv(.C) void {
done = true;
}
var column: u8 = 0;
var line: u8 = 0;
fn nextColumn() u8 {
const c = column;
column = (column + 7) % 80;
return c + 1;
}
fn nextLine() u8 {
const l = line;
line = (line + 27) % 24;
return l + 1;
}
var red: u8 = 0;
var green: u8 = 0;
var blue: u8 = 0;
inline fn nextRed() u8 {
const r = red;
red +%= 31;
return r;
}
inline fn nextGreen() u8 {
const g = green;
green +%= 43;
return g;
}
inline fn nextBlue() u8 {
const b = blue;
blue +%= 67;
return b;
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
@ -160,33 +123,39 @@ pub fn main() !void {
std.debug.print("finished sending data...\n", .{});
}
const units = [_]struct {
name: []const u8,
factor: u64,
}{
.{ .name = "y", .factor = 365 * std.time.ns_per_day },
.{ .name = "w", .factor = std.time.ns_per_week },
.{ .name = "d", .factor = std.time.ns_per_day },
.{ .name = "h", .factor = std.time.ns_per_hour },
.{ .name = "m", .factor = std.time.ns_per_min },
.{ .name = "s", .factor = std.time.ns_per_s },
.{ .name = "ms", .factor = std.time.ns_per_ms },
.{ .name = "µs", .factor = std.time.ns_per_us },
.{ .name = "ns", .factor = 1 },
};
std.debug.print("time to send data: ", .{});
var i: usize = 0;
for (units) |unit| {
if (elapsed > unit.factor) {
if (i > 0) std.debug.print(" ", .{});
const r = elapsed % unit.factor;
const x = (elapsed - r) / unit.factor;
std.debug.print("{d}{s}", .{ x, unit.name });
elapsed = r;
i += 1;
{
var value = elapsed;
const units = [_]struct {
name: []const u8,
factor: u64,
}{
.{ .name = "y", .factor = 365 * std.time.ns_per_day },
.{ .name = "w", .factor = std.time.ns_per_week },
.{ .name = "d", .factor = std.time.ns_per_day },
.{ .name = "h", .factor = std.time.ns_per_hour },
.{ .name = "m", .factor = std.time.ns_per_min },
.{ .name = "s", .factor = std.time.ns_per_s },
.{ .name = "ms", .factor = std.time.ns_per_ms },
.{ .name = "µs", .factor = std.time.ns_per_us },
.{ .name = "ns", .factor = 1 },
};
var i: usize = 0;
for (units) |unit| {
if (value > unit.factor) {
if (i > 0) std.debug.print(" ", .{});
const r = value % unit.factor;
const x = (value - r) / unit.factor;
std.debug.print("{d}{s}", .{ x, unit.name });
value = r;
i += 1;
}
}
}
std.debug.print("\n", .{});
std.debug.print("{d}\n", .{written.len});
std.debug.print("bytes written {d}\n", .{written.len});
std.debug.print("{d:>6.2} MiB/s\n", .{(@as(f64, @floatFromInt(written.len)) / (1024.0 * 1024.0)) / (@as(f64, @floatFromInt(elapsed)) / std.time.ns_per_s)});
}