Skip to content

Instantly share code, notes, and snippets.

@mitallast
Created April 24, 2015 09:25
Show Gist options
  • Save mitallast/37aa1c65874faf1b1c79 to your computer and use it in GitHub Desktop.
Save mitallast/37aa1c65874faf1b1c79 to your computer and use it in GitHub Desktop.
test iterate large directory
$ time ls -f -1 | wc -l
474919
real 0m2.527s
user 0m0.333s
sys 0m0.333s
474917
time: 2758ms
package granat.dp.components.image;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
public class TestIterate {
public static void main(String[] arg) throws Exception {
DirectoryStream<Path> paths = Files.newDirectoryStream(Paths.get("/Users/mitallast/Sites/test"));
Iterator<Path> iterator = paths.iterator();
int i=0;
long start = System.currentTimeMillis();
while (iterator.hasNext()) {
iterator.next();
i++;
}
long end = System.currentTimeMillis();
System.out.println(i);
System.out.println("time: "+(end - start)+ "ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment