UNPKG

2.85 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
7 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
8 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
9 * Google as part of the polymer project is also subject to an additional IP
10 * rights grant found at http://polymer.github.io/PATENTS.txt
11 */
12var __importDefault = (this && this.__importDefault) || function (mod) {
13 return (mod && mod.__esModule) ? mod : { "default": mod };
14};
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.formatCsvRaw = exports.formatCsvStats = void 0;
17const sync_1 = __importDefault(require("csv-stringify/lib/sync"));
18const precision = 5;
19/**
20 * Format statistical results as a CSV file string.
21 */
22function formatCsvStats(results) {
23 // Note the examples in ./test/csv_test.ts should make this easier to
24 // understand.
25 const h1 = ['', '', ''];
26 const h2 = ['', 'ms', ''];
27 const h3 = ['', 'min', 'max'];
28 const rows = [];
29 for (const result of results) {
30 h1.push(`vs ${result.result.name}`, '', '', '');
31 h2.push('% change', '', 'ms change', '');
32 h3.push('min', 'max', 'min', 'max');
33 const row = [];
34 row.push(result.result.name, result.stats.meanCI.low.toFixed(precision), result.stats.meanCI.high.toFixed(precision));
35 for (const diff of result.differences) {
36 if (diff === null) {
37 row.push('', '', '', '');
38 }
39 else {
40 row.push((diff.relative.low * 100).toFixed(precision) + '%', (diff.relative.high * 100).toFixed(precision) + '%', diff.absolute.low.toFixed(precision), diff.absolute.high.toFixed(precision));
41 }
42 }
43 rows.push(row);
44 }
45 return sync_1.default([h1, h2, h3, ...rows]);
46}
47exports.formatCsvStats = formatCsvStats;
48/**
49 * Format raw sample results as a CSV file string.
50 *
51 * Columns correspond to benchmarks. Rows correspond to sample iterations. The
52 * first row is headers containing the benchmark names.
53 *
54 * For example:
55 *
56 * foo, bar, baz
57 * 1.2, 5.5, 9.4
58 * 1.8, 5.6, 9.1
59 * 1.3, 5.2, 9.8
60 */
61function formatCsvRaw(results) {
62 const headers = [];
63 const rows = [];
64 for (let r = 0; r < results.length; r++) {
65 const { result } = results[r];
66 headers.push(result.name);
67 for (let m = 0; m < result.millis.length; m++) {
68 if (rows[m] === undefined) {
69 rows[m] = [];
70 }
71 rows[m][r] = result.millis[m];
72 }
73 }
74 return sync_1.default([headers, ...rows]);
75}
76exports.formatCsvRaw = formatCsvRaw;
77//# sourceMappingURL=csv.js.map
\No newline at end of file