aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile1
-rwxr-xr-xoptimize36
-rw-r--r--readme.md16
-rw-r--r--src/log.c4
4 files changed, 54 insertions, 3 deletions
diff --git a/makefile b/makefile
index d5ba639..ab6da6a 100644
--- a/makefile
+++ b/makefile
@@ -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
diff --git a/readme.md b/readme.md
index 44191ea..da514c7 100644
--- a/readme.md
+++ b/readme.md
@@ -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 |
diff --git a/src/log.c b/src/log.c
index e452610..dc57877 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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);