JAVA-12080 Create and delete test files dynamically
This commit is contained in:
parent
bf6c478bb5
commit
2ff0071a65
core-java-modules/core-java-streams-3/src/main
java/com/baeldung/streams/parallel
resources/filesearch
Test0.txtTest1.txtTest10.txtTest100.txtTest1000.txtTest1001.txtTest1002.txtTest1003.txtTest1004.txtTest1005.txtTest1006.txtTest1007.txtTest1008.txtTest1009.txtTest101.txtTest1010.txtTest1011.txtTest1012.txtTest1013.txtTest1014.txtTest1015.txtTest1016.txtTest1017.txtTest1018.txtTest1019.txtTest102.txtTest1020.txtTest1021.txtTest1022.txtTest1023.txtTest1024.txtTest1025.txtTest1026.txtTest1027.txtTest1028.txtTest1029.txtTest103.txtTest1030.txtTest1031.txtTest1032.txtTest1033.txtTest1034.txtTest1035.txtTest1036.txtTest1037.txtTest1038.txtTest1039.txtTest104.txtTest1040.txtTest1041.txtTest1042.txtTest1043.txtTest1044.txtTest1045.txtTest1046.txtTest1047.txtTest1048.txtTest1049.txtTest105.txtTest1050.txtTest1051.txtTest1052.txtTest1053.txtTest1054.txtTest1055.txtTest1056.txtTest1057.txtTest1058.txtTest1059.txtTest106.txtTest1060.txtTest1061.txtTest1062.txtTest1063.txtTest1064.txtTest1065.txtTest1066.txtTest1067.txtTest1068.txtTest1069.txtTest107.txtTest1070.txtTest1071.txtTest1072.txtTest1073.txtTest1074.txtTest1075.txtTest1076.txtTest1077.txtTest1078.txtTest1079.txtTest108.txtTest1080.txtTest1081.txtTest1082.txtTest1083.txtTest1084.txtTest1085.txtTest1086.txt
@ -1,5 +1,6 @@
|
|||||||
package com.baeldung.streams.parallel;
|
package com.baeldung.streams.parallel;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -7,26 +8,51 @@ import java.nio.file.Paths;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Level;
|
||||||
import org.openjdk.jmh.annotations.Mode;
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
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 {
|
public class FileSearchCost {
|
||||||
|
|
||||||
@Benchmark
|
private final static String FILE_NAME = "src/main/resources/Test";
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
|
||||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
@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 {
|
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());
|
.filter(path -> path.getFileName().toString().endsWith(".txt")).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
public static void textFileSearchParallel() throws IOException {
|
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());
|
.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