From 0ec3f9e4255cd04b68e50dba7b59bd817aca4247 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 23 Dec 2002 20:32:28 +0000 Subject: [PATCH] Old program for testing our image loading speed. We will want to investigate the possibility in the future of uncompressing our images into a local cache on the client and loading from there because it is about 10 times faster to load uncompressed images. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2089 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/media/ImageLoadingSpeed.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/src/java/com/threerings/media/ImageLoadingSpeed.java diff --git a/tests/src/java/com/threerings/media/ImageLoadingSpeed.java b/tests/src/java/com/threerings/media/ImageLoadingSpeed.java new file mode 100644 index 000000000..ee0f8213f --- /dev/null +++ b/tests/src/java/com/threerings/media/ImageLoadingSpeed.java @@ -0,0 +1,78 @@ +// +// $Id: ImageLoadingSpeed.java,v 1.1 2002/12/23 20:32:28 mdb Exp $ + +package com.threerings.media; + +import java.awt.Image; +import java.io.*; +import com.threerings.resource.ResourceManager; + +/** + * Tests our image loading speed. + */ +public class ImageLoadingSpeed +{ + public static void main (String[] args) + { + if (args.length < 1) { + System.err.println("Usage: ImageLoadingTest image [image ...]"); + System.exit(-1); + } + + ResourceManager rmgr = new ResourceManager("rsrc"); + rmgr.initBundles(null, "config/resource/manager.properties", null); + ImageManager imgr = new ImageManager(rmgr, null); + long start = System.currentTimeMillis(); + +// // serialize our image +// try { +// FileOutputStream fout = new FileOutputStream("image.dat"); +// ObjectOutputStream oout = new ObjectOutputStream(fout); +// oout.writeObject(image); +// oout.close(); + +// } catch (IOException ioe) { +// ioe.printStackTrace(System.err); +// System.exit(-1); +// } + + for (int iter = 0; iter < IMAGE_LOAD_ITERS; iter++) { + String path = args[iter%args.length]; + if (path.startsWith("rsrc/")) { + path = path.substring(5); + } + Image image = null; + try { + image = imgr.loadImage(path); + } catch (IOException ioe) { + ioe.printStackTrace(System.err); + System.exit(-1); + } + } + +// try { +// FileInputStream fin = new FileInputStream("image.dat"); +// BufferedInputStream bin = new BufferedInputStream(fin); +// ObjectInputStream oin = new ObjectInputStream(bin); +// image = (Image)oin.readObject(); +// System.out.println(image); + +// } catch (ClassNotFoundException cnfe) { +// cnfe.printStackTrace(System.err); +// System.exit(-1); + +// } catch (IOException ioe) { +// ioe.printStackTrace(System.err); +// System.exit(-1); +// } + + long elapsed = System.currentTimeMillis() - start; + + System.err.println("Loaded " + args.length + " images a total of " + + IMAGE_LOAD_ITERS + " times in " + elapsed + "ms."); + System.err.println("An average of " + (elapsed/IMAGE_LOAD_ITERS) + + "ms per image."); + } + + protected static final int IMAGE_LOAD_ITERS = 100; +}