//
// $Id: ImageLoadingSpeed.java,v 1.2 2003/01/13 22:57:45 mdb Exp $

package com.threerings.media;

import java.awt.Image;
import java.io.*;

import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ImageManager;

/**
 * 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);
//         }

        int iter = 0;
        while (true) {
//         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;
//             image = imgr.getImage(path);
            image = imgr.getImage("components", path);

            if (++iter == 100) {
                long now = System.currentTimeMillis();
                long elapsed = now - start;
                System.err.println("Loaded " + args.length +
                                   " images a total of " + iter +
                                   " times in " + elapsed + "ms.");
                System.err.println("An average of " + (elapsed/iter) +
                                   "ms per image.");
                start = now;
                iter = 0;

                System.gc();
                try { Thread.sleep(5000); } catch (Throwable t) {}
            }
        }

//         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;
}

@@ -35,29 +35,29 @@
 v 1.
-2
+3
  2003/0
-1/13 22:57:45
+4/25 15:52:39
  mdb
@@ -118,16 +118,134 @@
 .Image;%0A
+import java.awt.image.BufferedImage;%0Aimport javax.imageio.ImageIO;%0Aimport javax.imageio.stream.FileImageInputStream;%0A%0A
 import j
@@ -637,280 +637,148 @@
     
-ResourceManager rmgr = new ResourceManager(%22rsrc%22);%0A        rmgr.initBundles(null, %22config/resource/manager.properties%22, null);%0A        ImageManager imgr = new ImageManager(rmgr, null);%0A        long start = System.currentTimeMillis()
+long start = System.currentTimeMillis();%0A        int iter = 0;%0A        while (true) %7B%0A            String path = args%5Biter%25args.length%5D
 ;%0A%0A
-//
    
-      // serialize our image%0A//
     
@@ -780,34 +780,35 @@
           try %7B%0A
-//
+   
              Fil
@@ -804,27 +804,31 @@
         File
-Out
+ImageIn
 putStream fo
@@ -826,21 +826,40 @@
 Stream f
-out =
+is =%0A                   
  new Fil
@@ -859,19 +859,23 @@
 new File
-Out
+ImageIn
 putStrea
@@ -876,32 +876,33 @@
 tStream(
-%22image.dat%22
+new File(path)
 );%0A
-//
         
@@ -910,66 +910,56 @@
     
-ObjectOutputStream oout = new ObjectOutputStream(fout);%0A//
+   BufferedImage image =  ImageIO.read(fis);%0A   
     
@@ -971,65 +971,41 @@
     
-oout.writeObject(image);%0A//             oout.close
+int width = image.getWidth
 ();%0A
-%0A//
+   
     
@@ -1029,34 +1029,35 @@
 xception ioe) %7B%0A
-//
+   
              ioe
@@ -1078,34 +1078,35 @@
 ce(System.err);%0A
-//
+   
              Sys
@@ -1123,412 +1123,21 @@
 1);%0A
-//         %7D%0A%0A        int iter = 0;%0A        while (true) %7B%0A//         for (int iter = 0; iter %3C IMAGE_LOAD_ITERS; iter++) %7B%0A            String path = args%5Biter%25args.length%5D;%0A            if (path.startsWith(%22rsrc/%22)) %7B%0A                path = path.substring(5);%0A            %7D%0A            Image image = null;%0A//             image = imgr.getImage(path);%0A            image = imgr.getImage(%22components%22, path);
+            %7D
 %0A%0A  
@@ -1588,63 +1588,8 @@
 .%22);
-%0A                start = now;%0A                iter = 0;
 %0A%0A  
@@ -1650,17 +1650,17 @@
 d.sleep(
-5
+1
 000); %7D 
@@ -1682,29 +1682,16 @@
 e t) %7B%7D%0A
-            %7D
 %0A       
@@ -1695,21 +1695,16 @@
     
-%7D%0A%0A//
         
  try
@@ -1703,1000 +1703,75 @@
     
- try %7B%0A//             FileInputStream fin = new FileInputStream(%22image.dat%22);%0A//             BufferedInputStream bin = new BufferedInputStream(fin);%0A//             ObjectInputStream oin = new ObjectInputStream(bin);%0A//             image = (Image)oin.readObject();%0A//             System.out.println(image);%0A%0A//         %7D catch (ClassNotFoundException cnfe) %7B%0A//             cnfe.printStackTrace(System.err);%0A//             System.exit(-1);%0A%0A//         %7D catch (IOException ioe) %7B%0A//             ioe.printStackTrace(System.err);%0A//             System.exit(-1);%0A//         %7D%0A        %0A//         long elapsed = System.currentTimeMillis() - start;%0A%0A//         System.err.println(%22Loaded %22 + args.length + %22 images a total of %22 +%0A//                            IMAGE_LOAD_ITERS + %22 times in %22 + elapsed + %22ms.%22);%0A//         System.err.println(%22An average of %22 + (elapsed/IMAGE_LOAD_ITERS) +%0A//                            %22ms per image.%22);%0A    %7D%0A%0A    protected static final int IMAGE_LOAD_ITERS = 100;
+start = now;%0A                iter = 0;%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

Cleaned up the image loading speed test.