Barcode4j Performance


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”?

The Test

  1. Download barcode4j-2.1.0-bin.tar.gz.
  2. Make sure you have Java and GNU Time installed.
  3. Download this script and run it from the un-tarred barcode4j-2.1.0-bin.

# NOTE: Use GNU Time, NOT bash's built in.
#       I was able to get that with `$ apt install time`
set -e

CP="build/barcode4j.jar:$(echo lib/*.jar | tr ' ' ':')"

# Clean up stuff
[ -d tmp ] || mkdir tmp

# Run the tests
for i in `seq 1 $RUNS`;
    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

The Results

These tests were ran with the following conditions:


filetypedpimean(s)median(s)mode(s)avg size(B)

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.

Further Work

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.