JAVA-12080 Create and delete test files dynamically
This commit is contained in:
parent
bf6c478bb5
commit
2ff0071a65
@ -1,5 +1,6 @@
|
||||
package com.baeldung.streams.parallel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -7,26 +8,51 @@ import java.nio.file.Paths;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Level;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.TearDown;
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
public class FileSearchCost {
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
private final static String FILE_NAME = "src/main/resources/Test";
|
||||
|
||||
@Setup(Level.Trial)
|
||||
public void setup() throws IOException {
|
||||
for (int i = 0; i < 1500; i++) {
|
||||
File targetFile = new File(FILE_NAME + i);
|
||||
FileUtils.writeStringToFile(targetFile, "Test", "UTF8");
|
||||
}
|
||||
}
|
||||
|
||||
@TearDown(Level.Trial)
|
||||
public void tearDown() {
|
||||
for (int i = 0; i < 1500; i++) {
|
||||
File fileToDelete = new File(FILE_NAME + i);
|
||||
fileToDelete.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
public static void textFileSearchSequential() throws IOException {
|
||||
Files.walk(Paths.get("src/main/resources/filesearch/")).map(Path::normalize).filter(Files::isRegularFile)
|
||||
Files.walk(Paths.get("src/main/resources/")).map(Path::normalize).filter(Files::isRegularFile)
|
||||
.filter(path -> path.getFileName().toString().endsWith(".txt")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
public static void textFileSearchParallel() throws IOException {
|
||||
Files.walk(Paths.get("src/main/resources/filesearch/")).parallel().map(Path::normalize).filter(Files::isRegularFile)
|
||||
Files.walk(Paths.get("src/main/resources/")).parallel().map(Path::normalize).filter(Files::isRegularFile)
|
||||
.filter(path -> path.getFileName().toString().endsWith(".txt")).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
Test0
|
@ -1 +0,0 @@
|
||||
Test1
|
@ -1 +0,0 @@
|
||||
Test10
|
@ -1 +0,0 @@
|
||||
Test100
|
@ -1 +0,0 @@
|
||||
Test1000
|
@ -1 +0,0 @@
|
||||
Test1001
|
@ -1 +0,0 @@
|
||||
Test1002
|
@ -1 +0,0 @@
|
||||
Test1003
|
@ -1 +0,0 @@
|
||||
Test1004
|
@ -1 +0,0 @@
|
||||
Test1005
|
@ -1 +0,0 @@
|
||||
Test1006
|
@ -1 +0,0 @@
|
||||
Test1007
|
@ -1 +0,0 @@
|
||||
Test1008
|
@ -1 +0,0 @@
|
||||
Test1009
|
@ -1 +0,0 @@
|
||||
Test101
|
@ -1 +0,0 @@
|
||||
Test1010
|
@ -1 +0,0 @@
|
||||
Test1011
|
@ -1 +0,0 @@
|
||||
Test1012
|
@ -1 +0,0 @@
|
||||
Test1013
|
@ -1 +0,0 @@
|
||||
Test1014
|
@ -1 +0,0 @@
|
||||
Test1015
|
@ -1 +0,0 @@
|
||||
Test1016
|
@ -1 +0,0 @@
|
||||
Test1017
|
@ -1 +0,0 @@
|
||||
Test1018
|
@ -1 +0,0 @@
|
||||
Test1019
|
@ -1 +0,0 @@
|
||||
Test102
|
@ -1 +0,0 @@
|
||||
Test1020
|
@ -1 +0,0 @@
|
||||
Test1021
|
@ -1 +0,0 @@
|
||||
Test1022
|
@ -1 +0,0 @@
|
||||
Test1023
|
@ -1 +0,0 @@
|
||||
Test1024
|
@ -1 +0,0 @@
|
||||
Test1025
|
@ -1 +0,0 @@
|
||||
Test1026
|
@ -1 +0,0 @@
|
||||
Test1027
|
@ -1 +0,0 @@
|
||||
Test1028
|
@ -1 +0,0 @@
|
||||
Test1029
|
@ -1 +0,0 @@
|
||||
Test103
|
@ -1 +0,0 @@
|
||||
Test1030
|
@ -1 +0,0 @@
|
||||
Test1031
|
@ -1 +0,0 @@
|
||||
Test1032
|
@ -1 +0,0 @@
|
||||
Test1033
|
@ -1 +0,0 @@
|
||||
Test1034
|
@ -1 +0,0 @@
|
||||
Test1035
|
@ -1 +0,0 @@
|
||||
Test1036
|
@ -1 +0,0 @@
|
||||
Test1037
|
@ -1 +0,0 @@
|
||||
Test1038
|
@ -1 +0,0 @@
|
||||
Test1039
|
@ -1 +0,0 @@
|
||||
Test104
|
@ -1 +0,0 @@
|
||||
Test1040
|
@ -1 +0,0 @@
|
||||
Test1041
|
@ -1 +0,0 @@
|
||||
Test1042
|
@ -1 +0,0 @@
|
||||
Test1043
|
@ -1 +0,0 @@
|
||||
Test1044
|
@ -1 +0,0 @@
|
||||
Test1045
|
@ -1 +0,0 @@
|
||||
Test1046
|
@ -1 +0,0 @@
|
||||
Test1047
|
@ -1 +0,0 @@
|
||||
Test1048
|
@ -1 +0,0 @@
|
||||
Test1049
|
@ -1 +0,0 @@
|
||||
Test105
|
@ -1 +0,0 @@
|
||||
Test1050
|
@ -1 +0,0 @@
|
||||
Test1051
|
@ -1 +0,0 @@
|
||||
Test1052
|
@ -1 +0,0 @@
|
||||
Test1053
|
@ -1 +0,0 @@
|
||||
Test1054
|
@ -1 +0,0 @@
|
||||
Test1055
|
@ -1 +0,0 @@
|
||||
Test1056
|
@ -1 +0,0 @@
|
||||
Test1057
|
@ -1 +0,0 @@
|
||||
Test1058
|
@ -1 +0,0 @@
|
||||
Test1059
|
@ -1 +0,0 @@
|
||||
Test106
|
@ -1 +0,0 @@
|
||||
Test1060
|
@ -1 +0,0 @@
|
||||
Test1061
|
@ -1 +0,0 @@
|
||||
Test1062
|
@ -1 +0,0 @@
|
||||
Test1063
|
@ -1 +0,0 @@
|
||||
Test1064
|
@ -1 +0,0 @@
|
||||
Test1065
|
@ -1 +0,0 @@
|
||||
Test1066
|
@ -1 +0,0 @@
|
||||
Test1067
|
@ -1 +0,0 @@
|
||||
Test1068
|
@ -1 +0,0 @@
|
||||
Test1069
|
@ -1 +0,0 @@
|
||||
Test107
|
@ -1 +0,0 @@
|
||||
Test1070
|
@ -1 +0,0 @@
|
||||
Test1071
|
@ -1 +0,0 @@
|
||||
Test1072
|
@ -1 +0,0 @@
|
||||
Test1073
|
@ -1 +0,0 @@
|
||||
Test1074
|
@ -1 +0,0 @@
|
||||
Test1075
|
@ -1 +0,0 @@
|
||||
Test1076
|
@ -1 +0,0 @@
|
||||
Test1077
|
@ -1 +0,0 @@
|
||||
Test1078
|
@ -1 +0,0 @@
|
||||
Test1079
|
@ -1 +0,0 @@
|
||||
Test108
|
@ -1 +0,0 @@
|
||||
Test1080
|
@ -1 +0,0 @@
|
||||
Test1081
|
@ -1 +0,0 @@
|
||||
Test1082
|
@ -1 +0,0 @@
|
||||
Test1083
|
@ -1 +0,0 @@
|
||||
Test1084
|
@ -1 +0,0 @@
|
||||
Test1085
|
@ -1 +0,0 @@
|
||||
Test1086
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user