Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  NIO performance  (Read 1540 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Member




Java forever


« Posted 2004-02-13 19:23:59 »

Shocked

/me was experimenting with the NIO package few minutes ago

/me picks up his jaw
/me leaves
Offline shawnkendall

Senior Member




Apathy Error: Don't bother striking any key.


« Reply #1 - Posted 2004-02-13 20:14:50 »

Which JDK/RE dist?
What were ya moving?
Our tests for our game book showed some interesting results for certain buffer sizes....

Shawn Kendall
Full Sail Real World Education
Immediate Mode Interactive, LLC
<A HREF="http://cosmic-game-engine.blogspot.com/">Cosmic Game Engine Dev Journal</a>
Offline Java Cool Dude

Senior Member




Java forever


« Reply #2 - Posted 2004-02-13 20:33:37 »

I'm using the newly released Beta, the 1.5.
I was loading and saving files of ~1mb in size and they took a little less than .01 sec each to save/load.
Very impressive in my book Smiley
Games published by our own members! Check 'em out!
Try the Free Demo of Droid Assault
Offline Java Cool Dude

Senior Member




Java forever


« Reply #3 - Posted 2004-02-13 20:47:20 »

Well I'll take that back, loading ain't .01 s for sure, it's more likely .04 s for .5 meg file.
Still pretty decent Smiley
Offline Java Cool Dude

Senior Member




Java forever


« Reply #4 - Posted 2004-02-13 23:27:09 »

12 meg BMP file loaded into a Buffered image 30 times.
Used nanoTime() for time measurements
0.5513015
0.43309337
0.4326227
0.42480677
0.44826984
0.4392897
0.4407508
0.45602912
0.422791
0.41829714
0.42564127
0.46178436
0.44194937
0.4183817
0.42540553
0.41966453
0.5335501
0.4897753
0.4385598
0.43106866
0.429915
0.45493767
0.44871792
0.4765585
0.41891822
0.43527684
0.45020917
0.45965165
0.4203453
0.4176206
0.4338188
0.42069072
0.42639792
0.43123522
0.44919837
0.43107706
0.4326319
0.45190325
0.42833588
0.44125915

Mean (40 iterations) 0.4427933
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #5 - Posted 2004-02-14 01:51:44 »

With this sort of test it is NOT valid to repeat it many times and take the average.  After the first load the file is likely cached in RAM by the OS anyway...   But come to think of it, in this case that eliminates the disk overhead so you only test transferring the data to the java buffer... hmm maybe it is valid for something, but just know what you are measuring.

Offline Java Cool Dude

Senior Member




Java forever


« Reply #6 - Posted 2004-02-14 02:18:51 »

0.14044498
0.07139052
0.076452695
0.07659108
0.07640024
0.08001636
0.07646246
0.07608609

Mean (8 Iterations)0.08423056

8 different files loaded of size 17.2 mb Smiley
Offline mattocks

Senior Newbie




Java games rock!


« Reply #7 - Posted 2004-02-14 06:41:37 »

Here's another example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
/**
 * Program: FastCopyFile.java
 * Author : Craig Mattocks
 * Date   : April, 2003
 * Description: Test Java 1.4 NIO channels and buffers.
 * Based on Listing 1.2 from:
 * "JDK 1.4 Tutorial" by Gregory M. Travis, Manning
 * Note:  Direct buffers allocate their data directly in the
 * runtime environment memory, bypassing the JVM|OS boundary,
 * usually doubling file copy speed. However, they generally
 * cost more to allocate.
 */


import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.text.NumberFormat;

public class FastCopyFile
{
      public static void main( String args[] )
      {
            if (args.length != 2)
            {
                  System.out.println("Usage:  java FastCopyFile src_file dest_file");
                  System.exit(1);
            }

            System.out.println("Copying file " + args[0] + " to file " + args[1] + "...");

            long before = System.currentTimeMillis();            // Start timing
                 copyFile(args[0], outfile);
            long after  = System.currentTimeMillis();            // End timing

            double cputime = .001 * (after - before);

            NumberFormat digits = NumberFormat.getInstance();
            digits.setMaximumFractionDigits(3);

            System.out.println("Execution required " + digits.format(cputime) + " seconds.");
      }

      private static void copyFile(String infile, String outfile)
      {
            final boolean DIRECT   = true;      // Direct buffer?
           final boolean TRANSFER = true;      // Use fast transfer method?
           final int BUFFSIZE = 1024;
            ByteBuffer buffer;

            FileChannel in  = null;
            FileChannel out = null;

            try
            {
                  in  = (new FileInputStream (infile )).getChannel();
                  out = (new FileOutputStream(outfile)).getChannel();

                  if (DIRECT)
                        buffer = ByteBuffer.allocateDirect( BUFFSIZE );
                  else
                        buffer = ByteBuffer.allocate( BUFFSIZE );

                  if (TRANSFER)
                  {
                        /**
                         * transferTo is potentially much more efficient than a simple
                         * loop that reads from a source channel and writes to a target
                         * channel. Many operating systems can transfer bytes directly
                         * from the filesystem cache to the target channel without
                         * actually copying them by using special operating system
                         * features that support very fast file transfers. - Sun docs
                         */


                        in.transferTo(0, in.size(), out);
                  }
                  else
                  {
                        int ret;
                        while ((ret = in.read(buffer)) > -1) // Read from input channel, write to buffer
                       {
                              buffer.flip();                              // Flip buffer's read/write mode
                             out.write(buffer);                        // Read from buffer, write to output channel
                             buffer.clear();                              // Make room for the next read
                       }
                  }
            }
            catch (FileNotFoundException fnfx)
            {
                  System.err.println("File not found: " + fnfx);
            }
            catch (IOException iox)
            {
                  System.err.println("I/O problems: " + iox);
            }
            finally
            {
                  if (in != null)
                  {
                        try
                        {
                              in.close();
                        }
                        catch (IOException ignored) {}
                  }
                  if (out != null)
                  {
                        try
                        {
                              out.close();
                        }
                        catch (IOException ignored) {}
                  }
            }
      }
}
Offline mattocks

Senior Newbie




Java games rock!


« Reply #8 - Posted 2004-02-14 06:47:53 »

Oops! Error in above FastCopyFile.java code in main():

1  
copyFile(args[0], outfile);


should be:

1  
copyFile(args[0], args[1]);


Sorry 'bout that!

Craig
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (91 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (123 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (196 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.28 seconds with 20 queries.