Friday, February 7, 2014

Java - format

public class Test {

public static void main(String[] args) {
final int LOOP_COUNT = 100;
String a = "aaa", b = "bbb", c = "ccc";
long d = 1, e = 2, f = 3;
String data;

long startTime = System.nanoTime();

for (int i = 0; i < LOOP_COUNT; i++) {
data = a + " " + b + " " + c + " " + d + " " + e + " " + f;
}

long endTime = System.nanoTime();
double elaspedTime = (endTime - startTime) / 1000000.0;

System.out.println(elaspedTime);

startTime = System.nanoTime();

for (int i = 0; i < LOOP_COUNT; i++) {
data = String.format("%s %s %s %d %d %d", a, b, c, d, e, f);
}

endTime = System.nanoTime();
elaspedTime = (endTime - startTime) / 1000000.0;

System.out.println(elaspedTime);

startTime = System.nanoTime();

for (int i = 0; i < LOOP_COUNT; i++) {
System.out.print(a + " " + b + " " + c + " " + d + " " + e + " "
+ f);
}

endTime = System.nanoTime();
elaspedTime = (endTime - startTime) / 1000000.0;

System.out.println();
System.out.println(elaspedTime);

startTime = System.nanoTime();

for (int i = 0; i < LOOP_COUNT; i++) {
System.out.format("%s %s %s %d %d %d", a, b, c, d, e, f);
}

endTime = System.nanoTime();
elaspedTime = (endTime - startTime) / 1000000.0;

System.out.println();
System.out.println(elaspedTime);
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.