Closed
Description
Following code, when compiled and ran it as java application, completes it by 34 seconds
whereas when I build the native image and ran it, it took 1 min 30 seconds. Am I miss something here?
I used ./native-image -cp . writer.Test to create the image
$ time java -cp bin writer.Test
real 0m34.762s
user 0m25.064s
sys 0m10.100s
$ time ./writer.test
real 1m30.609s
user 1m9.447s
sys 0m20.056s
package writer;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Test {
public static void main(String arg[]) {
BufferedWriter bw = null;
FileWriter fw = null;
int classes = 2500;
int filesCount = 14;
int records = 5000;
int columns = 10;
try {
for (int k=0; k<classes; k++) {
for (int j=0; j<filesCount; j++) {
StringBuilder builder = new StringBuilder();
for (int i=0; i<records; i++) {
for (int c=0; c<columns; c++) {
builder.append(c);
builder.append(",");
}
}
fw = new FileWriter("/tmp/" + k + "_" + j + ".txt");
bw = new BufferedWriter(fw);
bw.write(builder.toString());
bw.close();
fw.close();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}