/Output.java Secret
Created
October 18, 2019 19:34
This file contains 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
import java.io.*; | |
import java.util.*; | |
class Main { | |
public static void main(String[] args) throws Exception { | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
StringBuilder sb = new StringBuilder(); | |
long start, end; | |
// System.out.print TEST | |
start = System.currentTimeMillis(); | |
for(int i=0; i<100000; i++) | |
System.out.print(i); | |
end = System.currentTimeMillis(); | |
double sysTime = (end-start) / 1000.0; | |
// bw.write TEST | |
start = System.currentTimeMillis(); | |
for(int i=0; i<100000; i++) | |
bw.write(i + ""); | |
bw.flush(); | |
end = System.currentTimeMillis(); | |
double bwTime = (end-start) / 1000.0; | |
// sb.append TEST | |
start = System.currentTimeMillis(); | |
for(int i=0; i<100000; i++) | |
sb.append(i); | |
System.out.print(sb); | |
end = System.currentTimeMillis(); | |
double sbTime = (end-start) / 1000.0; | |
// Result | |
System.out.println(); | |
System.out.println("sysTime : " + sysTime); | |
System.out.println("bwTime : " + bwTime); | |
System.out.println("sbTime : " + sbTime); | |
} | |
} |
This file contains 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
sysTime : 5.411 | |
bwTime : 0.274 | |
sbTime : 0.229 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment