Created
June 7, 2018 14:07
-
-
Save chalstrick/1407328309efdbe4f1e258e6bc02470a to your computer and use it in GitHub Desktop.
test NFSFile performance
This file contains hidden or 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
import java.io.File; | |
import java.io.IOException; | |
import java.nio.file.FileVisitResult; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.nio.file.SimpleFileVisitor; | |
import java.nio.file.attribute.BasicFileAttributes; | |
import org.eclipse.jgit.api.Git; | |
import org.eclipse.jgit.api.errors.GitAPIException; | |
import org.eclipse.jgit.api.errors.JGitInternalException; | |
import org.eclipse.jgit.errors.ConfigInvalidException; | |
import org.eclipse.jgit.lib.ConfigConstants; | |
import org.eclipse.jgit.lib.StoredConfig; | |
import org.eclipse.jgit.util.FS; | |
public class PerfTest_NFSFile { | |
private static final int NR_OF_FOLDERS = 100; | |
private static final int NR_OF_FILES = 1000; | |
public static void main(String args[]) throws IOException, GitAPIException, JGitInternalException, ConfigInvalidException { | |
long start, end; | |
int found; | |
Path tmp = Files.createDirectory(Paths.get("tmp_" + System.currentTimeMillis())); | |
try (Git git = Git.init().setDirectory(tmp.toFile()).call()) { | |
System.out.println("Repo created in " + tmp.toRealPath()); | |
for (int i = 0; i < NR_OF_FOLDERS; i++) { | |
File d = new File(tmp.toFile(), "test" + i); | |
d.mkdirs(); | |
for (int j = 0; j < NR_OF_FILES; j++) | |
new File(d, "test" + j).createNewFile(); | |
} | |
found = 0; | |
start = System.currentTimeMillis(); | |
for (int i = 0; i < NR_OF_FOLDERS; i++) { | |
File d = new File(tmp.toFile(), "test" + i); | |
for (int j = 0; j < NR_OF_FILES; j++) { | |
if (new File(d, "test" + j).exists()) | |
found++; | |
} | |
} | |
end = System.currentTimeMillis(); | |
System.out.println("Instantiated " + NR_OF_FILES * NR_OF_FOLDERS | |
+ " File objects for existing files and checked explicitly for existence (found " + found | |
+ " files) in " + (end - start) + " ms."); | |
FS fs = git.getRepository().getFS(); | |
found = 0; | |
start = System.currentTimeMillis(); | |
for (int i = 0; i < NR_OF_FOLDERS; i++) { | |
File d = fs.createFile(tmp.toFile(), "test" + i); | |
for (int j = 0; j < NR_OF_FILES; j++) { | |
if (fs.createFile(d, "test" + j).exists()) | |
found++; | |
} | |
} | |
end = System.currentTimeMillis(); | |
System.out.println("Instantiated " + NR_OF_FILES * NR_OF_FOLDERS | |
+ " NFSFile objects for existing files and checked explicitly for existence (found " + found | |
+ " files) in " + (end - start) + " ms."); | |
StoredConfig cfg = git.getRepository().getConfig(); | |
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, | |
ConfigConstants.CONFIG_KEY_REFRESHFOLDERSTAT, true); | |
cfg.save(); | |
git.getRepository().getConfig().load(); | |
found = 0; | |
start = System.currentTimeMillis(); | |
for (int i = 0; i < NR_OF_FOLDERS; i++) { | |
File d = fs.createFile(tmp.toFile(), "test" + i); | |
for (int j = 0; j < NR_OF_FILES; j++) { | |
if (fs.createFile(d, "test" + j).exists()) | |
found++; | |
} | |
} | |
end = System.currentTimeMillis(); | |
System.out.println("Instantiated in a repo with CONFIG_KEY_REFRESHFOLDERSTAT set to true " + NR_OF_FILES * NR_OF_FOLDERS | |
+ " NFSFile objects for existing files and checked explicitly for existence (found " + found | |
+ " files) in " + (end - start) + " ms."); | |
} finally { | |
Files.walkFileTree(tmp, new SimpleFileVisitor<Path>() { | |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | |
Files.delete(file); | |
return FileVisitResult.CONTINUE; | |
} | |
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { | |
Files.delete(dir); | |
return FileVisitResult.CONTINUE; | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment