JFreeSVG vs Apache Batik


JFreeSVG is a lightweight SVG generator for the Java platform, that is growing in popularity with Java developers who are seemingly attracted by its compact size---the JFreeSVG jar file weighs in at just 44Kb (and you could make it smaller with pack200).

In addition to being lightweight, we also make the claim that JFreeSVG is fast. To back that up, we've done some performance testing to compare JFreeSVG against the Apache Batik toolkit which, amongst many other things, also provides an SVGGraphics2D implementation. Bear in mind that the comparison is only looking at the Graphics2D implementations provided by these libraries. Apache Batik provides a *lot* of other SVG-related functions that are outside the scope of JFreeSVG.

The Benchmark

The benchmark program creates the following chart of the quarterly revenues for some well-known technology companies, using Orson Charts, and then exports it to SVG (if you can't see the chart below, your browser is not rendering SVG correctly). The chart itself is quite interesting because it puts into perspective how much larger Apple's revenues are compared to those of other technology companies (when you get a chance, download Orson Charts and try out the interactive version):

Q2/11Q3/11Q4/11Q1/12Q2/12Q3/12Q4/12Q1/13Q2/13Q3/13Q4/13Quarter0102030405060$billion RevenuesOracleGoogleMicrosoftAppleOracleGoogleMicrosoftAppleOrson Charts (evaluation) (c) 2013, 2014, by Object Refinery LimitedQuarterly RevenuesFor some large IT companies

The two source files are here: PerformanceJFreeSVG.java and PerformanceBatik.java. Both programs generate the chart in SVG format 1,000 times during a "warm-up" phase, then a further 1,000 times during the testing phase. The warm-up phase is intended to give the JVM a chance to perform optimisations on the running code.

Accurate benchmarking is notoriously difficult and we certainly don't have a lot of benchmarking experience. We've strived to make the tests transparent and reproducable and welcome any feedback on our results. Bear in mind that we've tested only one use case and this cannot be representative of all use cases. It's just intended to be indicative. If performance is important for your application, you should test with your own benchmarks, using a work load that is relevant for your application.


Both benchmark programs require the orsoncharts-1.3-eval.jar file that you can download from the Orson Charts home page. For the test we require some code that produces output via Java2D's Graphics2D API, and Orson Charts fills this need. There are, of course, many other libraries that generate output via Graphics2D, because it has been a standard part of the Java runtime since version 1.2 (which was released in 1998!).

For the JFreeSVG version, we included the following jar file on the classpath:

  • jfreesvg-1.8.jar (45,462 bytes).

For the Batik version, we included the following jar files on the classpath (to our knowledge, this is the minimum set required to use the SVGGraphics2D class):

  • batik-dom.jar (173,750 bytes);
  • batik-svggen.jar (215,802 bytes);
  • batik-awt-util.jar (403,287 bytes);
  • batik-util.jar (128,334 bytes);
  • batik-ext.jar (10,261 bytes);
  • batik-xml.jar (30,862 bytes);

The six Batik jars add up to 962,296 bytes, which is a factor of ~20 times larger than the 45,462 bytes for the JFreeSVG jar file.

The Results

There are two aspects of the results that we are interested in. First, the size of the SVG output that is generated and, second, the time it takes to generate the SVG.

We ran the benchmark programs using Java 1.8.0 update 5, on a MacBook Air.

Output Size

Batik creates an SVG file with size 72,996 bytes while JFreeSVG creates an SVG file with size 81,452 bytes. The Batik-generated file is approximately 10% smaller, so Batik does better on this metric.

Processing Time

For the processing time, the following table shows the results:

Warm-up Phase (1,000 repetitions)7,445 milliseconds24,448 milliseconds
Testing Phase (1,000 repetitions)4,297 milliseconds21,022 milliseconds

JFreeSVG is converting the chart to SVG approximately five times faster than Batik. That surprised us a little, it has to be said, but it is a nice backup to our claim that JFreeSVG is fast.

We used JFreeChart with JFreeSVG to visualise these results:

Performance: JFreeSVG vs Apache BatikWarm-upTestTime to generate 1,000 charts in SVG (lower bars = better performance)JFreeSVGBatik02,0004,0006,0008,00010,00012,00014,00016,00018,00020,00022,00024,000


JFreeSVG is certainly compact relative to Batik as a dependency for Java programs that need to generate SVG output via the Graphics2D API. This analysis has shown that JFreeSVG can have a small output size penalty relative to Batik, but compensates for this by being many times faster.

If you'd like to give feedback, please feel free to post your thoughts in the JFreeSVG forum.