Skip to content

Commit ec82fb0

Browse files
authored
Merge pull request #395 from jpmorganchase/optimize_main
Benchmark limit + minor changes to DataAccessor
2 parents 2a59ea7 + e719e82 commit ec82fb0

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

docs/development.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ with your changes to preserve them for future comparison.
152152
yarn bench
153153
```
154154

155+
Use the `--limit <NUMBER>` flag to control the number of Perspective versions that the
156+
benchmark suite will run, where `<NUMBER>` is an integer greater than 0. If `<NUMBER>`
157+
cannot be parsed, is 0, or is greater than the number of versions, the benchmark suite
158+
will run all previous versions of Perspective.
159+
155160
The benchmarks report and `results.json` show a historgram of current
156161
performance, as well as that of the previous `results.json`. Running this
157162
should probably be standard practice after making a large change which may
158163
affect performance, but please create a baseline `results.json` entry for your
159-
test machine on a commit before your changes first, such that the affect of your
164+
test machine on a commit before your changes first, such that the effects of your
160165
PR can be properly compared.

packages/perspective/bench/js/bench.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const puppeteer = require("puppeteer");
1111
const fs = require("fs");
1212
const path = require("path");
1313

14+
const args = process.argv.slice(2);
15+
const LIMIT = args.indexOf("--limit");
16+
1417
const multi_template = (xs, ...ys) => ys[0].map((y, i) => [y, xs.reduce((z, x, ix) => (ys[ix] ? z + x + ys[ix][i] : z + x), "")]);
1518

1619
const UNPKG_VERSIONS = ["0.2.11", "0.2.10", "0.2.9", "0.2.8", "0.2.7", "0.2.6", "0.2.5", "0.2.4", "0.2.3", "0.2.2", "0.2.1", "0.2.0"];
@@ -46,9 +49,20 @@ function transpose(json) {
4649
}
4750

4851
async function run() {
52+
// Allow users to set a limit on version lookbacks
53+
let psp_urls = URLS;
54+
console.log(`limit: ${LIMIT}`);
55+
if (LIMIT !== -1) {
56+
let limit_num = Number(args[LIMIT + 1]);
57+
if (!isNaN(limit_num) && limit_num > 0 && limit_num <= psp_urls.length) {
58+
console.log(`Benchmarking the last ${limit_num} versions`);
59+
psp_urls = URLS.slice(0, limit_num);
60+
}
61+
}
62+
4963
let data = [],
5064
version_index = 1;
51-
for (let [version, url] of URLS) {
65+
for (let [version, url] of psp_urls) {
5266
let browser = await puppeteer.launch({
5367
headless: true,
5468
args: ["--auto-open-devtools-for-tabs", "--no-sandbox"]

scripts/bench.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const execSync = require("child_process").execSync;
1212
const execute = cmd => execSync(cmd, {stdio: "inherit"});
1313

1414
const args = process.argv.slice(2);
15+
const LIMIT = args.indexOf("--limit");
1516

1617
function docker() {
1718
console.log("Creating puppeteer docker image");
@@ -20,6 +21,10 @@ function docker() {
2021
cmd += ` --cpus="${parseInt(process.env.PSP_CPU_COUNT)}.0"`;
2122
}
2223
cmd += " perspective/puppeteer nice -n -20 node packages/perspective/bench/js/bench.js";
24+
if (LIMIT !== -1) {
25+
let limit = args[LIMIT + 1];
26+
cmd += ` --limit ${limit}`;
27+
}
2328
return cmd;
2429
}
2530

src/cpp/emscripten.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ infer_type(val x, val date_validator) {
10301030
}
10311031

10321032
t_dtype
1033-
get_data_type(val data, std::int32_t format, std::string name, val date_validator) {
1033+
get_data_type(val data, std::int32_t format, const std::string& name, val date_validator) {
10341034
std::int32_t i = 0;
10351035
boost::optional<t_dtype> inferredType;
10361036

@@ -1069,7 +1069,7 @@ get_data_type(val data, std::int32_t format, std::string name, val date_validato
10691069
}
10701070

10711071
std::vector<t_dtype>
1072-
data_types(val data, std::int32_t format, std::vector<std::string> names, val date_validator) {
1072+
data_types(val data, std::int32_t format, const std::vector<std::string>& names, val date_validator) {
10731073
if (names.size() == 0) {
10741074
PSP_COMPLAIN_AND_ABORT("Cannot determine data types without column names!");
10751075
}
@@ -1081,9 +1081,8 @@ data_types(val data, std::int32_t format, std::vector<std::string> names, val da
10811081
std::vector<std::string> data_names
10821082
= vecFromArray<val, std::string>(keys);
10831083

1084-
for (std::vector<std::string>::iterator name = data_names.begin();
1085-
name != data_names.end(); ++name) {
1086-
std::string value = data[*name].as<std::string>();
1084+
for (const std::string& name : data_names) {
1085+
std::string value = data[name].as<std::string>();
10871086
t_dtype type;
10881087

10891088
if (value == "integer") {
@@ -1099,17 +1098,16 @@ data_types(val data, std::int32_t format, std::vector<std::string> names, val da
10991098
} else if (value == "date") {
11001099
type = t_dtype::DTYPE_DATE;
11011100
} else {
1102-
PSP_COMPLAIN_AND_ABORT("Unknown type '" + value + "' for key '" + *name + "'");
1101+
PSP_COMPLAIN_AND_ABORT("Unknown type '" + value + "' for key '" + name + "'");
11031102
}
11041103

11051104
types.push_back(type);
11061105
}
11071106

11081107
return types;
11091108
} else {
1110-
for (std::vector<std::string>::iterator name = names.begin(); name != names.end();
1111-
++name) {
1112-
t_dtype type = get_data_type(data, format, *name, date_validator);
1109+
for (const std::string& name : names) {
1110+
t_dtype type = get_data_type(data, format, name, date_validator);
11131111
types.push_back(type);
11141112
}
11151113
}

0 commit comments

Comments
 (0)