Skip to content

Instantly share code, notes, and snippets.

@megascus
Created May 4, 2017 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megascus/5bdf8d7d45b06cb639c40ce67d1533a3 to your computer and use it in GitHub Desktop.
Save megascus/5bdf8d7d45b06cb639c40ce67d1533a3 to your computer and use it in GitHub Desktop.
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);
}
}
}
}
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");
}
}
@megascus
Copy link
Author

megascus commented May 4, 2017

Parallel:lessThan
2891ms
2634ms
2595ms
2605ms
2540ms
2590ms
2593ms
2597ms
2549ms
2601ms
Parallel:moreThan
9371ms
9204ms
9399ms
9347ms
9112ms
9058ms
9314ms
9003ms
9138ms
9044ms
Single:lessThan
6730ms
6620ms
6666ms
6693ms
6593ms
6654ms
6678ms
6589ms
6618ms
6637ms
Single:moreThan
7116ms
7147ms
7107ms
7129ms
7107ms
7151ms
7119ms
7289ms
9998ms
8124ms

@megascus
Copy link
Author

megascus commented May 4, 2017

jdk-9-ea+167_windows-x64_bin.exe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment