39 | Here are present actual charts for performance comparison of string formatting in Java/Scala for the corresponding 40 | post «Scala: String Interpolation Performance». 41 |
42 | 43 |44 | The legend for tests. «String length» is a length of a result string (after formatting). 45 |
46 | 47 |48 | Tests performed via JMH, 2 forks, 3 warmup 49 | runs and 7 iteration (3 seconds each). Ubuntu 16.04, linux-kernel 4.4.0-51-generic, JDK 1.8.0_91, scala library 2.12. 50 | The configuration of a hardware is Intel® Core™ i7–5600U CPU @ 2.60GHz × 4 (2 core + 2 HT) with 16 GB RAM. 51 |
52 | 53 |74 | 75 |
76 | 77 | 78 | 79 |80 | Full JMH log is here. 81 |
82 | 83 |84 | 85 |
86 | 87 | 90 | 91 || ').html('Method \\ String Length')); 136 | $.each(DataSizeToView, function (index, dataSize) { 137 | head.append($(' | ').html(dataSize.name)); 138 | }); 139 | table.append($('').append(head)); 140 | 141 | var tbody = $(' |
|---|---|
| ').html(text));
147 | }
148 |
149 | addTd(value.name);
150 |
151 | $.each(DataSizeToView, function (index, dataSize) {
152 | var time = getTime(value, dataSize.value, property);
153 | addTd(time);
154 | });
155 |
156 | tbody.append(tr);
157 | });
158 | table.append(tbody);
159 |
160 | $(elem).empty().append(table);
161 | }
162 |
163 | function getOrUpdate(map, name, defaultValue) {
164 | var v = map[name] || defaultValue || {};
165 | map[name] = v;
166 | return v;
167 | }
168 |
169 | function convertData(list) {
170 | // {
171 | // name: javaConcat,
172 | // values: {
173 | // 7: {avg, p0...},
174 | // 101: {avg, p0...}
175 | // }
176 | // }
177 | //
178 | var map = {};
179 |
180 | $.each(list, function (index, entry) {
181 | // code from Benchmarks!
182 | var type = entry.params
183 | ? entry.params.arg
184 | : '';
185 |
186 | var name = extractName(entry.benchmark);
187 | var pm = entry.primaryMetric;
188 |
189 | var timesByStringLength = getOrUpdate(map, name, {name: name, values: {}}).values;
190 | timesByStringLength[type] = {
191 | avg: pm.score,
192 | p0: pm.scorePercentiles['0.0'],
193 | p50: pm.scorePercentiles['50.0'],
194 | p95: pm.scorePercentiles['95.0'],
195 | p100: pm.scorePercentiles['100.0']
196 | };
197 | });
198 |
199 | var result = [];
200 | $.each(Methods, function (index, method) {
201 | result.push(map[method.name] || {name: method.name});
202 | });
203 |
204 | return result;
205 | }
206 |
207 | function extractName(benchmark) {
208 | //'com.komanov.stringformat.jmh.ManyParamsBenchmark.concat'
209 |
210 | var index = benchmark.lastIndexOf('.');
211 | if (index == -1) {
212 | throw new Error('Expected a dot in a benchmark: ' + benchmark);
213 | }
214 | return benchmark.substring(index + 1);
215 | }
216 |
217 | function getDataForChart(property) {
218 | var result = [];
219 |
220 | var header = ['string length'];
221 | $.each(data, function (index, value) {
222 | header.push(value.name);
223 | });
224 | result.push(header);
225 |
226 | $.each(DataSizeToView, function (index, dataSize) {
227 | var line = [dataSize.name];
228 | $.each(data, function (index, value) {
229 | var time = getTime(value, dataSize.value, property);
230 | line.push(time);
231 | });
232 | result.push(line);
233 | });
234 |
235 | return result;
236 | }
237 |
238 | function getTime(value, dataSize, property) {
239 | return Math.floor(((value.values || {})[dataSize] || {})[property] || 0.0);
240 | }
241 | }
242 |
243 | $(document).ready(function () {
244 | loadGoogleCharts(loadJmhResult);
245 | });
246 |
247 | function loadGoogleCharts(onLoadCallback) {
248 | google.charts.load('current', {'packages': ['bar']});
249 | google.charts.setOnLoadCallback(onLoadCallback);
250 | }
251 |
252 | function loadJmhResult() {
253 | var url = 'jmh-result.json';
254 | $.getJSON(url, function (list) {
255 | loadScalaSerializationChartsPage(list);
256 | });
257 | }
258 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | |