Created
April 24, 2015 09:25
-
-
Save mitallast/37aa1c65874faf1b1c79 to your computer and use it in GitHub Desktop.
test iterate large directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time ls -f -1 | wc -l | |
474919 | |
real 0m2.527s | |
user 0m0.333s | |
sys 0m0.333s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
474917 | |
time: 2758ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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