Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22952
| From | Wojtek <nowhere@a.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: The first 10 files |
| Date | 2013-03-14 03:07 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <mn.70bb7dd3ff682a5b.70216@a.com> (permalink) |
| References | <mn.d04a7dd156c148ef.70216@a.com> <ke23sm$afb$1@dont-email.me> |
Knute Johnson wrote :
>
> 300003 files in the directory, almost 1.7GB of files, Windows XP, Java 7 and
> it takes 16 ms to run. Somebody else should try this out on their computer
> to see if it works as fast.
Ok, I'm back :-)
I am using WinXP and Java 7, and the directory holds 30,001 32K files,
920MBytes
The Code:
----------------------------------------------------
package tester;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
public class NewsGroup
{
public static void main( String[] args ) throws IOException
{
int maxFiles = 10;
System.out.println( "Large File Number Tester" );
if (args[0].equals( "nio" ))
nioRun( "C:\\apps\\test", maxFiles );
else if (args[0].equals( "io" ))
ioRun( "C:\\apps\\test", maxFiles );
else
System.out.println( "NewsGroup io|nio" );
}
private static void ioRun( String filePath, int maxFiles ) throws
IOException
{
int i = 1;
System.out.println( "IO run" );
long start = System.currentTimeMillis();
File folder = new File( filePath );
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles)
{
System.out.println( "" + i + ": " + file.getName() );
if (++i > maxFiles)
break;
}
long stop = System.currentTimeMillis();
System.out.println( "Elapsed: " + (stop - start) + " ms" );
}
private static void nioRun( String filePath, int maxFiles ) throws
IOException
{
int i = 1;
System.out.println( "NIO run" );
long start = System.currentTimeMillis();
Path dir = FileSystems.getDefault().getPath( filePath );
DirectoryStream<Path> stream = Files.newDirectoryStream( dir );
for (Path path : stream)
{
System.out.println( "" + i + ": " + path.getFileName() );
if (++i > maxFiles)
break;
}
long stop = System.currentTimeMillis();
System.out.println( "Elapsed: " + (stop - start) + " ms" );
}
}
----------------------------------------------------
A batch file to run it:
----------------------------------------------------
@echo off
java -jar NewsGroup.jar %1
----------------------------------------------------
And the results:
----------------------------------------------------
C:\apps>run io
Large File Number Tester
IO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 156 ms
C:\apps>run io
Large File Number Tester
IO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 140 ms
C:\apps>run io
Large File Number Tester
IO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 156 ms
C:\apps>run nio
Large File Number Tester
NIO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 219 ms
C:\apps>run nio
Large File Number Tester
NIO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 31 ms
C:\apps>run nio
Large File Number Tester
NIO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 31 ms
C:\apps>run nio
Large File Number Tester
NIO run
1: F_000000.jpg
2: F_000001.jpg
3: F_000002.jpg
4: F_000003.jpg
5: F_000004.jpg
6: F_000005.jpg
7: F_000006.jpg
8: F_000007.jpg
9: F_000008.jpg
10: F_000009.jpg
Elapsed: 78 ms
C:\apps>
----------------------------------------------------
So NIO is about 4-5 times faster than IO. The first NIO run looks like
an anomoly, might be some JRE loading happening.
All the runs produce different timings, might be a Windows caching
effect. However the NIO is consistently much faster overall.
--
Wojtek :-)
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The first 10 files Wojtek <nowhere@a.com> - 2013-01-26 01:14 -0800
Re: The first 10 files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-26 02:44 -0800
Re: The first 10 files Lew <lewbloch@gmail.com> - 2013-01-26 10:20 -0800
Re: The first 10 files "John B. Matthews" <nospam@nospam.invalid> - 2013-01-26 06:31 -0500
Re: The first 10 files Wojtek <nowhere@a.com> - 2013-01-26 15:42 -0800
Re: The first 10 files Jim Janney <jjanney@shell.xmission.com> - 2013-01-26 17:13 -0700
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 21:21 -0500
Re: The first 10 files "John B. Matthews" <nospam@nospam.invalid> - 2013-01-26 22:05 -0500
Re: The first 10 files Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-26 08:24 -0400
Re: The first 10 files Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-26 08:25 -0400
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 13:26 -0500
Re: The first 10 files Robert Klemme <shortcutter@googlemail.com> - 2013-01-26 22:15 +0100
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 16:25 -0500
Re: The first 10 files Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-26 17:06 -0500
Re: The first 10 files Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-01-26 15:21 -0800
Re: The first 10 files Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-26 20:42 -0500
Re: The first 10 files Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2013-01-26 17:56 -0800
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 21:29 -0500
Re: The first 10 files Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-01-26 21:56 -0500
Re: The first 10 files Jim Janney <jjanney@shell.xmission.com> - 2013-01-26 20:51 -0700
Re: The first 10 files Jim Janney <jjanney@shell.xmission.com> - 2013-01-26 20:47 -0700
Re: The first 10 files Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-26 22:02 -0400
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 21:35 -0500
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 21:43 -0500
Re: The first 10 files Robert Klemme <shortcutter@googlemail.com> - 2013-01-27 13:55 +0100
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-02-24 17:50 -0500
Re: The first 10 files Robert Klemme <shortcutter@googlemail.com> - 2013-02-25 21:53 +0100
Re: The first 10 files Jim Janney <jjanney@shell.xmission.com> - 2013-01-26 20:57 -0700
Re: The first 10 files Wojtek <nowhere@a.com> - 2013-01-26 21:20 -0800
Re: The first 10 files Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-27 07:23 -0400
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-27 20:36 -0500
Re: The first 10 files Wojtek <nowhere@a.com> - 2013-01-28 16:28 -0800
Re: The first 10 files Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 21:23 -0500
Re: The first 10 files Roedy Green <see_website@mindprod.com.invalid> - 2013-01-26 19:09 -0800
Re: The first 10 files Jim Janney <jjanney@shell.xmission.com> - 2013-01-26 16:00 -0700
Re: The first 10 files Knute Johnson <nospam@knutejohnson.com> - 2013-01-26 18:37 -0800
Re: The first 10 files Wojtek <nowhere@a.com> - 2013-03-14 03:07 -0700
Re: The first 10 files lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-03-14 12:49 +0000
Re: The first 10 files Robert Klemme <shortcutter@googlemail.com> - 2013-03-15 11:38 +0100
Re: The first 10 files Wojtek <nowhere@a.com> - 2013-03-15 10:31 -0700
csiph-web