diff options
author | Marvin Borner | 2024-01-21 13:17:54 +0100 |
---|---|---|
committer | Marvin Borner | 2024-01-21 14:52:05 +0100 |
commit | d1813a10c682afca756250fbb6133bb0853e0054 (patch) | |
tree | 6f6c7bc21cf1e8d0f4ce07ec69607fdb268a271c | |
parent | 2e46b5875586dd4f7f69b7f6e708d55235ce29a1 (diff) |
-rw-r--r-- | makefile | 1 | ||||
-rwxr-xr-x | optimize | 36 | ||||
-rw-r--r-- | readme.md | 16 | ||||
-rw-r--r-- | src/log.c | 4 |
4 files changed, 54 insertions, 3 deletions
@@ -30,6 +30,7 @@ compile: $(BUILD) $(OBJS) $(BUILD)/blocade clean: @rm -rf $(BUILD)/* + @rm -f $(SRC)/cmdline.* install: @install -m 755 $(BUILD)/blocade $(DESTDIR)$(PREFIX)/bin/ diff --git a/optimize b/optimize new file mode 100755 index 0000000..a70b936 --- /dev/null +++ b/optimize @@ -0,0 +1,36 @@ +#!/bin/bash + +# finds optimal --min-size value for bloc + +target="blc" + +# remove files on exit +trap 'rm -f "$file".bloc "$file".bloc."$target"; exit 0' EXIT SIGINT SIGTERM + +if [ $# -eq 0 ]; then + echo "Usage: $0 <file>" + exit 1 +fi + +file=$1 + +function try { + bloc --from-blc -i "$file" -o "$file".bloc -m "$1" + blocade -i "$file".bloc -t "$target" -o "$file".bloc."$target" + size="$(stat -c %s "$file".bloc."$target")" +} + +low=5 +high=100000 +best=100000000000000000 +while [ $low -lt $high ]; do + mid=$(((low + high) / 2)) + try $mid + echo "$mid: $size" + if [ "$size" -le $best ]; then + best=$size + high=$((mid - 1)) + else + low=$((mid + 1)) + fi +done @@ -22,7 +22,7 @@ benchmarking, or general term optimization. ## Benchmarks Some deliberately unoptimized test cases from `test/`, evaluated using -`./run` and measured in bits: +`./run` and measured in bits (using `bloc -m 10 ...`): | file | bloc | unbblc/orig | bblc | |:--------------|:-----|:------------|:------| @@ -54,3 +54,17 @@ resolving the dependencies would also help. | file | bloc | unbblc/orig | bblc | |:-----------|:-----|:------------|:--------| | lambda-8cc | 5.13 | 40.72 | 3267.88 | + +## Optimization + +You can use BLoC’s minimum tree size deduplication parameter +`--min-size`/`-m` to generate even smaller files. The `optimize` bash +script tries to find the optimal parameter for your target file using a +binary search. + +For example, 8cc’s optimal parameter for the bblc target is `-m 4587`, +only marginally reducing the original size: + +| file | bloc | unbblc/orig | bblc | +|:-----------|:-----|:------------|:------| +| lambda-8cc | 5.8 | 40.72 | 40.65 | @@ -14,7 +14,7 @@ void debug(const char *format, ...) if (!debug_enabled) return; - fprintf(stderr, "[DEBUG] "); + fprintf(stderr, "[DEBUG] BLoCade: "); va_list ap; va_start(ap, format); @@ -29,7 +29,7 @@ void debug_enable(int enable) void fatal(const char *format, ...) { - fprintf(stderr, "[FATAL] "); + fprintf(stderr, "[FATAL] BloCade: "); va_list ap; va_start(ap, format); |