private void performTest(final PrintStream fmt, final String name) {
        final File target = new File(name);
        double sumTime = 0;
        int n = 1;
        for (int i = 0; i < 10; i++) {
            try {
                ByteSource byteSource = ByteSource.file(target);
                // This test code allows you to test cases where the
                // input is processed using Apache Imaging's
                // InputStreamByteSource rather than the ByteSourceFile.
                // You might also want to experiment with ByteSourceArray.
                // FileInputStream fins = new FileInputStream(target);
                // BufferedInputStream bins = new BufferedInputStream(fins);
                // InputStreamByteSource byteSource =
                // ByteSource.inputStream(bins, target.getName());
                // ready the parser (you may modify this code block
                // to use your parser of choice)
                TiffImagingParameters params = new TiffImagingParameters();
                TiffImageParser tiffImageParser = new TiffImageParser();
                // load the file and record time needed to do so
                final long time0Nanos = System.nanoTime();
                BufferedImage bImage = tiffImageParser.getBufferedImage(byteSource, params);
                final long time1Nanos = System.nanoTime();
                // tabulate results
                final double testTime = (time1Nanos - time0Nanos) / 1000000.0;
                if (i > 1) {
                    n = i - 1;
                    sumTime += testTime;
                }
                final double avgTime = sumTime / n;
                // tabulate the memory results. Note that the
                // buffered image, the byte source, and the parser
                // are all still in scope. This approach is taken
                // to get some sense of peak memory use, but Java
                // may have already started collecting garbage,
                // so there are limits to the reliability of these
                // statistics
                final Runtime r = Runtime.getRuntime();
                final long freeMemory = r.freeMemory();
                final long totalMemory = r.totalMemory();
                final long usedMemory = totalMemory - freeMemory;
                if (i == 0) {
                    // print header info
                    fmt.format("%n");
                    fmt.format("Processing file: %s%n", target.getName());
                    fmt.format(" image size: %d by %d%n%n", bImage.getWidth(), bImage.getHeight());
                    fmt.format(" time to load image    --         memory%n");
                    fmt.format(" time ms      avg ms   --    used mb   total mb%n");
                }
                fmt.format("%9.3f %9.3f    --  %9.3f %9.3f %n", testTime, avgTime, usedMemory / (1024.0 * 1024.0), totalMemory / (1024.0 * 1024.0));
                bImage = null;
                byteSource = null;
                params = null;
                tiffImageParser = null;
            } catch (final IOException ioex) {
                ioex.printStackTrace();
                System.exit(-1);
            }
            try {
                // sleep between loop iterations allows time
                // for the JVM to clean up memory. The Netbeans IDE
                // doesn't "get" the fact that we're doing this operation
                // deliberately and is apt offer hints
                // suggesting that the code should be modified
                Runtime.getRuntime().gc();
                Thread.sleep(1000);
            } catch (final InterruptedException iex) {
                // this isn't fatal, but shouldn't happen
                iex.printStackTrace();
            }
        }
    }
Loads the input file multiple times, measuring the time and memory use for each iteration.

@param fmt  a valid PrintStream for formatting the output
@param name the path for the input image file to be tested
src/test/java/org/apache/commons/imaging/examples/ApacheImagingSpeedAndMemoryTest.java