Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1797 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Member




Java forever


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

Shocked

/me was experimenting with the NIO package few minutes ago

/me picks up his jaw
/me leaves
Offline shawnkendall

Senior Member





« Reply #1 - Posted 2004-02-13 19: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
Cosmic Interactive, LLC
http://www.facebook.com/BermudaDash
Offline Java Cool Dude

Senior Member




Java forever


« Reply #2 - Posted 2004-02-13 19: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!
Legends of Yore - The Casual Retro Roguelike
Offline Java Cool Dude

Senior Member




Java forever


« Reply #3 - Posted 2004-02-13 19: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 22: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 00: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 01: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 05: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 05: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.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (28 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (73 views)
2014-09-10 06:39:09

Tekkerue (37 views)
2014-09-09 02:24:56

mitcheeb (57 views)
2014-09-08 06:06:29

BurntPizza (44 views)
2014-09-07 01:13:42

Longarmx (27 views)
2014-09-07 01:12:14

Longarmx (34 views)
2014-09-07 01:11:22

Longarmx (34 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!