At work we have been using the Java library barcode4j for a performance-sensitive project. I was unable to find any other published performance results for different barcode types.
This script was designed to test the question, “Are SVGs a performance-viable alternative to PNGs”?
- Download barcode4j-2.1.0-bin.tar.gz.
- Make sure you have Java and GNU Time installed.
- Download this script and run it from the un-tarred barcode4j-2.1.0-bin.
#!/bin/bash # NOTE: Use GNU Time, NOT bash's built in. # I was able to get that with `$ apt install time` set -e RUNS=1000 CP="build/barcode4j.jar:$(echo lib/*.jar | tr ' ' ':')" # Clean up stuff [ -d tmp ] || mkdir tmp >svg.csv >svg-size.csv >png.csv >png-size.csv # Run the tests for i in `seq 1 $RUNS`; do N=$(cat /dev/urandom | head -c5 | base64 | tr "/" "z") # If you wanted to test out other formats, you would add them here /usr/bin/time --format="%U" -ao svg.csv -- java -cp "$CP" org.krysalis.barcode4j.cli.Main --dpi 300 -s code128 --format svg -o ./tmp/"$N".svg "$N" stat --printf='%s\n' "$N".png >> png-size.csv /usr/bin/time --format="%U" -ao png.csv -- java -cp "$CP" org.krysalis.barcode4j.cli.Main --dpi 300 -s code128 --format png -o ./tmp/"$N".png "$N" stat --printf='%s\n' "$N".svg >> svg-size.csv done
These tests were ran with the following conditions:
- 2016 Macbook Pro
- 2.7 GHz
- 2000 samples (50% SVG, 50% PNG)
Generating SVGs is roughly 30% faster! But unfortunately the average file size increased nearly 400%! Through other testing, I know that in my use case bandwidth is limited. This test has shown that I should not move to SVGs.
While SVG compressors exist, I was only able to save 12% in the file size. This small of an improvement would not be worth the time, given how long a compressor would take to run.
Given more time I would like to investigate a lot more. I am missing many different types of images (EPS, TIFF, JPEG, GIF, BMP), different formats, and different DPIs. Another change could be writing this test in Java and not in the barcode4j CLI interface. Maybe some other time.