-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFastWriteBenchmarkTest.java
186 lines (165 loc) · 7.06 KB
/
FastWriteBenchmarkTest.java
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import org.dhatim.fastexcel.Workbook;
import org.dhatim.fastexcel.Worksheet;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class FastWriteBenchmarkTest {
public static void main(String[] args) {
// inlineStr模式
warmup(); w1k(); w5k(); w10k(); w50k(); w100k(); w500k(); w1000k();
// SharedStrings模式
warmup(); ws1k(); ws5k(); ws10k(); ws50k(); ws100k(); ws500k(); ws1000k();
}
public static void warmup() {
for (int i = 0; i < 5; i++)
fastWrite(10, RandomDataProvider.outPath.resolve("ignore.xlsx"));
}
public static void w1k() {
fastWrite(1000, RandomDataProvider.outPath.resolve("fast-1k.xlsx"));
}
public static void w5k() {
fastWrite(5000, RandomDataProvider.outPath.resolve("fast-5k.xlsx"));
}
public static void w10k() {
fastWrite(10000, RandomDataProvider.outPath.resolve("fast-10k.xlsx"));
}
public static void w50k() {
fastWrite(50000, RandomDataProvider.outPath.resolve("fast-50k.xlsx"));
}
public static void w100k() {
fastWrite(100000, RandomDataProvider.outPath.resolve("fast-100k.xlsx"));
}
public static void w500k() {
fastWrite(500000, RandomDataProvider.outPath.resolve("fast-500k.xlsx"));
}
public static void w1000k() {
fastWrite(1000000, RandomDataProvider.outPath.resolve("fast-1000k.xlsx"));
}
private static void fastWrite(int n, Path path) {
long start = System.currentTimeMillis();
try (Workbook wb = new Workbook(Files.newOutputStream(path), path.getFileName().toString(), "0.0")) {
Worksheet ws = wb.newWorksheet("Sheet 1");
int i = 0, c = 0;
ws.inlineString(i, c++, "nv");
ws.inlineString(i, c++, "lv");
ws.inlineString(i, c++, "dv");
ws.inlineString(i, c++, "av");
ws.inlineString(i, c++, "str1");
ws.inlineString(i, c++, "str2");
ws.inlineString(i, c++, "str3");
ws.inlineString(i, c++, "str4");
ws.inlineString(i, c++, "str5");
ws.inlineString(i, c++, "str6");
ws.inlineString(i, c++, "str7");
ws.inlineString(i, c++, "str8");
ws.inlineString(i, c++, "str9");
ws.inlineString(i, c++, "str10");
ws.inlineString(i, c++, "str11");
ws.inlineString(i, c++, "str12");
ws.inlineString(i, c++, "str13");
ws.inlineString(i, c++, "str14");
ws.inlineString(i, c, "str15");
c = 0;
for (; ++i <= n; c = 0) {
LargeData o = RandomDataProvider.randomOne();
ws.value(i, c++, o.getNv());
ws.value(i, c++, o.getLv());
ws.value(i, c++, o.getDv());
ws.value(i, c++, o.getAv());
ws.inlineString(i, c++, o.getStr1());
ws.inlineString(i, c++, o.getStr2());
ws.inlineString(i, c++, o.getStr3());
ws.inlineString(i, c++, o.getStr4());
ws.inlineString(i, c++, o.getStr5());
ws.inlineString(i, c++, o.getStr6());
ws.inlineString(i, c++, o.getStr7());
ws.inlineString(i, c++, o.getStr8());
ws.inlineString(i, c++, o.getStr9());
ws.inlineString(i, c++, o.getStr10());
ws.inlineString(i, c++, o.getStr11());
ws.inlineString(i, c++, o.getStr12());
ws.inlineString(i, c++, o.getStr13());
ws.inlineString(i, c++, o.getStr14());
ws.inlineString(i, c, o.getStr15());
}
ws.close();
} catch (IOException ex) {
ex.printStackTrace();
}
RandomDataProvider.println("[Fast] write \"" + path.getFileName() + "\" finished. Rows: " + n + " Cost(ms): " + (System.currentTimeMillis() - start));
}
public static void ws1k() {
fastSharedWrite(1000, RandomDataProvider.outPath.resolve("fast-shared-1k.xlsx"));
}
public static void ws5k() {
fastSharedWrite(5000, RandomDataProvider.outPath.resolve("fast-shared-5k.xlsx"));
}
public static void ws10k() {
fastSharedWrite(10000, RandomDataProvider.outPath.resolve("fast-shared-10k.xlsx"));
}
public static void ws50k() {
fastSharedWrite(50000, RandomDataProvider.outPath.resolve("fast-shared-50k.xlsx"));
}
public static void ws100k() {
fastSharedWrite(100000, RandomDataProvider.outPath.resolve("fast-shared-100k.xlsx"));
}
public static void ws500k() {
fastSharedWrite(500000, RandomDataProvider.outPath.resolve("fast-shared-500k.xlsx"));
}
public static void ws1000k() {
fastSharedWrite(1000000, RandomDataProvider.outPath.resolve("fast-shared-1000k.xlsx"));
}
private static void fastSharedWrite(int n, Path path) {
long start = System.currentTimeMillis();
try (Workbook wb = new Workbook(Files.newOutputStream(path), path.getFileName().toString(), "0.0")) {
Worksheet ws = wb.newWorksheet("Sheet 1");
int i = 0, c = 0;
ws.value(i, c++, "nv");
ws.value(i, c++, "lv");
ws.value(i, c++, "dv");
ws.value(i, c++, "av");
ws.value(i, c++, "str1");
ws.value(i, c++, "str2");
ws.value(i, c++, "str3");
ws.value(i, c++, "str4");
ws.value(i, c++, "str5");
ws.value(i, c++, "str6");
ws.value(i, c++, "str7");
ws.value(i, c++, "str8");
ws.value(i, c++, "str9");
ws.value(i, c++, "str10");
ws.value(i, c++, "str11");
ws.value(i, c++, "str12");
ws.value(i, c++, "str13");
ws.value(i, c++, "str14");
ws.value(i, c, "str15");
c = 0;
for (; ++i <= n; c = 0) {
LargeData o = RandomDataProvider.randomOne();
ws.value(i, c++, o.getNv());
ws.value(i, c++, o.getLv());
ws.value(i, c++, o.getDv());
ws.value(i, c++, o.getAv());
ws.value(i, c++, o.getStr1());
ws.value(i, c++, o.getStr2());
ws.value(i, c++, o.getStr3());
ws.value(i, c++, o.getStr4());
ws.value(i, c++, o.getStr5());
ws.value(i, c++, o.getStr6());
ws.value(i, c++, o.getStr7());
ws.value(i, c++, o.getStr8());
ws.value(i, c++, o.getStr9());
ws.value(i, c++, o.getStr10());
ws.value(i, c++, o.getStr11());
ws.value(i, c++, o.getStr12());
ws.value(i, c++, o.getStr13());
ws.value(i, c++, o.getStr14());
ws.value(i, c, o.getStr15());
}
ws.close();
} catch (IOException ex) {
ex.printStackTrace();
}
RandomDataProvider.println("[Fast] write \"" + path.getFileName() + "\" finished. Rows: " + n + " Cost(ms): " + (System.currentTimeMillis() - start));
}
}