Fixed a couple minor issues
Added benchmark.sh
This commit is contained in:
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
ARCHIVE="testing/LinuxPATest.sfs"
|
||||
|
||||
REF_EXT_LOC="testing/LinuxPAReference"
|
||||
PROG_EXT_LOC="testing/LinuxPABinTest"
|
||||
|
||||
echo "Building with ReleaseFast"
|
||||
echo ""
|
||||
|
||||
zig build -Doptimize=ReleaseFast
|
||||
|
||||
echo "Testing Multi-threaded Performance"
|
||||
echo ""
|
||||
|
||||
hyperfine --warmup 5 --prepare "rm -rf $REF_EXT_LOC && rm -rf $PROG_EXT_LOC" "unsquashfs -d $REF_EXT_LOC $ARCHIVE" "zig-out/bin/unsquashfs -d $PROG_EXT_LOC $ARCHIVE"
|
||||
|
||||
echo ""
|
||||
echo "Testing Single-threaded Performance"
|
||||
echo ""
|
||||
|
||||
hyperfine --warmup 5 --prepare "rm -rf $REF_EXT_LOC && rm -rf $PROG_EXT_LOC" "unsquashfs -p 1 -d $REF_EXT_LOC $ARCHIVE" "zig-out/bin/unsquashfs -p 1 -d $PROG_EXT_LOC $ARCHIVE"
|
||||
@@ -90,24 +90,36 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const mod_tests = b.addTest(.{
|
||||
const lib_tests = b.addTest(.{
|
||||
.root_module = lib.root_module,
|
||||
.use_llvm = debug,
|
||||
});
|
||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||
const run_lib_tests = b.addRunArtifact(lib_tests);
|
||||
const exe_tests = b.addTest(.{
|
||||
.root_module = exe.root_module,
|
||||
.use_llvm = debug,
|
||||
});
|
||||
const run_exe_tests = b.addRunArtifact(exe_tests);
|
||||
|
||||
const test_step = b.step("test", "Run tests");
|
||||
test_step.dependOn(&run_mod_tests.step);
|
||||
test_step.dependOn(&run_lib_tests.step);
|
||||
test_step.dependOn(&run_exe_tests.step);
|
||||
|
||||
// zls build check steps
|
||||
const lib_check = b.addLibrary(.{
|
||||
.name = "squashfs",
|
||||
.root_module = lib.root_module,
|
||||
.use_llvm = debug,
|
||||
});
|
||||
const exe_check = b.addExecutable(.{
|
||||
.name = "unsquashfs",
|
||||
.root_module = exe.root_module,
|
||||
.use_llvm = debug,
|
||||
});
|
||||
const check = b.step("check", "Check if unsquashfs compiles");
|
||||
check.dependOn(&lib_check.step);
|
||||
check.dependOn(&exe_check.step);
|
||||
|
||||
test_step.dependOn(&lib_check.step);
|
||||
test_step.dependOn(&exe_check.step);
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
zig test \
|
||||
-lc \
|
||||
-lz \
|
||||
-llzma \
|
||||
-lminilzo \
|
||||
-llz4 \
|
||||
-lzstd \
|
||||
src/test.zig
|
||||
@@ -2,8 +2,8 @@ const std = @import("std");
|
||||
const Io = std.Io;
|
||||
const Writer = Io.Writer;
|
||||
const builtin = @import("builtin");
|
||||
const build = @import("build");
|
||||
|
||||
const build = @import("build");
|
||||
const squashfs = @import("squashfs");
|
||||
|
||||
//TODO: Add more options
|
||||
@@ -52,14 +52,16 @@ pub fn main(init: std.process.Init) !void {
|
||||
var out = stdout.writer(io, &[0]u8{});
|
||||
defer out.interface.flush() catch {};
|
||||
|
||||
try handleArgs(init.minimal.args, &out.interface);
|
||||
try handleArgs(alloc, init.minimal.args, &out.interface);
|
||||
if (archive.len == 0) {
|
||||
try out.interface.print("You must provide a squashfs archive\n", .{});
|
||||
try out.interface.print(help_mgs, .{});
|
||||
return;
|
||||
}
|
||||
|
||||
var fil = try Io.Dir.cwd().openFile(io, archive, .{}); //TODO: Handle error gracefully.
|
||||
defer fil.close(io);
|
||||
|
||||
var arc: squashfs.Archive = try .init(io, fil, offset); //TODO: Update when memory size matters. //TODO: Handle error gracefully.
|
||||
defer arc.deinit(io);
|
||||
const options: squashfs.ExtractionOptions = .{
|
||||
@@ -89,7 +91,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
defer sfs_fil.deinit();
|
||||
|
||||
const last_ind = std.mem.lastIndexOf(u8, files[i], "/");
|
||||
const file_name = if (last_ind != null) files[i][last_ind..] else files[i];
|
||||
const file_name = if (last_ind != null) files[i][last_ind.?..] else files[i];
|
||||
|
||||
const fil_ext_loc = if (ext_loc.len > 0)
|
||||
try std.mem.concat(alloc, u8, &.{ ext_loc, "/", file_name })
|
||||
@@ -128,7 +130,7 @@ fn handleArgs(alloc: std.mem.Allocator, main_args: std.process.Args, out: *Write
|
||||
return errors.InvalidArguments;
|
||||
}
|
||||
if (!alloc.resize(files, files.len + 1)) {
|
||||
const new_alloc = alloc.alloc([]const u8, files.len + 1);
|
||||
const new_alloc = try alloc.alloc([:0]const u8, files.len + 1);
|
||||
@memcpy(new_alloc[0..files.len], files);
|
||||
alloc.free(files);
|
||||
files = new_alloc;
|
||||
|
||||
@@ -74,11 +74,7 @@ pub fn extract(
|
||||
),
|
||||
}
|
||||
|
||||
// try loop.await(io);
|
||||
loop.await(io) catch |err| {
|
||||
std.debug.print("err: {}\n", .{err});
|
||||
return err;
|
||||
};
|
||||
try loop.await(io);
|
||||
}
|
||||
|
||||
fn dirOrder(_: void, a: PathReturn, b: PathReturn) std.math.Order {
|
||||
|
||||
Reference in New Issue
Block a user