-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastPrint.java
More file actions
117 lines (99 loc) · 3.52 KB
/
FastPrint.java
File metadata and controls
117 lines (99 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.io.*;
class FastPrint {
static void prints() {
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
System.out.print(randomChar);
}
System.out.print(" ");
}
}
static void printff() throws Exception {
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
output.write(randomChar);
}
output.write(" ");
}
}
static void printo() throws Exception {
OutputStream output = new BufferedOutputStream ( System.out );
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
output.write(randomChar);
}
output.write(' ');
}
}
static void printSOPsb() {
StringBuilder sb = new StringBuilder();
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
sb.append(randomChar);
}
sb.append(" ");
}
System.out.print(sb.toString());
}
static void printBWsb() throws Exception {
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
sb.append(randomChar);
}
sb.append(" ");
}
output.write(sb.toString());
}
static void printOSsb() throws Exception {
OutputStream output = new BufferedOutputStream ( System.out );
StringBuilder sb = new StringBuilder();
for (int i=0; i<100000; i++) {
int randomCountOfSymbols = (int) (Math.random() * 50);
for (int j=0; j<randomCountOfSymbols; j++) {
char randomChar = (char) ((int) (Math.random()*27) + 65);
sb.append(randomChar);
}
sb.append(" ");
}
output.write(sb.toString().getBytes());
}
public static void main(String[] args) throws Exception{
long sopStart = System.currentTimeMillis();
prints();
long sopStop = System.currentTimeMillis();
long bwStart = System.currentTimeMillis();
printff();
long bwStop = System.currentTimeMillis();
long osStart = System.currentTimeMillis();
printo();
long osStop = System.currentTimeMillis();
long sOPsbStart = System.currentTimeMillis();
printSOPsb();
long sOPsbStop = System.currentTimeMillis();
long bWsbStart = System.currentTimeMillis();
printBWsb();
long bWsbStop = System.currentTimeMillis();
long oSsbStart = System.currentTimeMillis();
printOSsb();
long oSsbStop = System.currentTimeMillis();
System.out.println( "\n\nSystem.out.println: " + (sopStop - sopStart) );
System.out.println( "BufferedWriter: " + (bwStop - bwStart) );
System.out.println( "BufferedOutputStream: " + (osStop - osStart) );
System.out.println( "String Builder with System.out.println: " + (sOPsbStop - sOPsbStart) );
System.out.println( "BufferedWriter with System.out.println: " + (bWsbStop - bWsbStart) );
System.out.println( "BufferedOutputStream with System.out.println: " + (oSsbStop - oSsbStart) );
}
}