Created
May 4, 2017 13:17
-
-
Save megascus/5bdf8d7d45b06cb639c40ce67d1533a3 to your computer and use it in GitHub Desktop.
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
package test; | |
import java.io.BufferedWriter; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStreamWriter; | |
import static java.nio.charset.StandardCharsets.*; | |
public class CreateFile { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) throws IOException { | |
final String str = "あいうえおかきくけこさしすせそたちつてと\r\n"; | |
final int charlen = str.getBytes(UTF_8).length; | |
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\moreThan2G.txt"), UTF_8))) { | |
long size = 0; | |
while (size <= Integer.MAX_VALUE) { | |
size += charlen; | |
writer.write(str); | |
} | |
} | |
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\lessThan2G.txt"), UTF_8))) { | |
long size = 0; | |
while (size + charlen <= Integer.MAX_VALUE) { | |
size += charlen; | |
writer.write(str); | |
} | |
} | |
} | |
} |
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
package test; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import static java.nio.charset.StandardCharsets.*; | |
public class Test { | |
private static final String lessThan2G = "D:\\lessThan2G.txt"; | |
private static final String moreThan2G = "D:\\moreThan2G.txt"; | |
public static void main(String[] args) throws IOException { | |
System.out.println("Parallel:lessThan"); | |
for (int i = 0; i < 10; i++) { | |
measureP(lessThan2G); | |
} | |
System.out.println("Parallel:moreThan"); | |
for (int i = 0; i < 10; i++) { | |
measureP(moreThan2G); | |
} | |
System.out.println("Single:lessThan"); | |
for (int i = 0; i < 10; i++) { | |
measureS(lessThan2G); | |
} | |
System.out.println("Single:moreThan"); | |
for (int i = 0; i < 10; i++) { | |
measureS(moreThan2G); | |
} | |
} | |
public static void measureP(String fileName) throws IOException { | |
long start = System.nanoTime(); | |
Files.lines(Paths.get(fileName), UTF_8).parallel().filter(s -> true).forEach(s -> {return;}); | |
long end = System.nanoTime(); | |
System.out.println((end - start) / 1000000 + "ms"); | |
} | |
public static void measureS(String fileName) throws IOException { | |
long start = System.nanoTime(); | |
Files.lines(Paths.get(fileName), UTF_8).filter(s -> true).forEach(s -> {return;}); | |
long end = System.nanoTime(); | |
System.out.println((end - start) / 1000000 + "ms"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jdk-9-ea+167_windows-x64_bin.exe