Print average and worst speeds in benchmark command
This commit is contained in:
parent
8f028ebf68
commit
8c005cddc6
1 changed files with 40 additions and 2 deletions
|
|
@ -19,8 +19,27 @@ vector<string> language_names({
|
|||
"python",
|
||||
});
|
||||
|
||||
size_t mean(const vector<size_t> &values) {
|
||||
if (values.empty()) return 0;
|
||||
double result = 0;
|
||||
for (double value : values) {
|
||||
result += value;
|
||||
}
|
||||
return result / values.size();
|
||||
}
|
||||
|
||||
size_t min(const vector<size_t> &values) {
|
||||
double result = 0;
|
||||
for (double value : values) {
|
||||
if (value < result || result == 0) result = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char *arg[]) {
|
||||
map<string, vector<ExampleEntry>> example_entries_by_language_name;
|
||||
vector<size_t> error_speeds;
|
||||
vector<size_t> non_error_speeds;
|
||||
|
||||
auto document = ts_document_new();
|
||||
|
||||
|
|
@ -46,6 +65,11 @@ int main(int argc, char *arg[]) {
|
|||
|
||||
for (auto &example : example_entries_by_language_name[language_name]) {
|
||||
if (file_name_filter && example.file_name != file_name_filter) continue;
|
||||
if (example.input.size() < 256) continue;
|
||||
|
||||
ts_document_invalidate(document);
|
||||
ts_document_set_input_string(document, "");
|
||||
ts_document_parse(document);
|
||||
|
||||
ts_document_invalidate(document);
|
||||
ts_document_set_input_string(document, example.input.c_str());
|
||||
|
|
@ -55,7 +79,9 @@ int main(int argc, char *arg[]) {
|
|||
clock_t end_time = clock();
|
||||
unsigned duration = (end_time - start_time) * 1000 / CLOCKS_PER_SEC;
|
||||
assert(!ts_node_has_error(ts_document_root_node(document)));
|
||||
printf(" %-30s\t%u\n", example.file_name.c_str(), duration);
|
||||
size_t speed = static_cast<double>(example.input.size()) / duration;
|
||||
printf(" %-30s\t%u ms\t\t%lu bytes/ms\n", example.file_name.c_str(), duration, speed);
|
||||
non_error_speeds.push_back(speed);
|
||||
}
|
||||
|
||||
for (auto &other_language_name : language_names) {
|
||||
|
|
@ -63,6 +89,7 @@ int main(int argc, char *arg[]) {
|
|||
|
||||
for (auto &example : example_entries_by_language_name[other_language_name]) {
|
||||
if (file_name_filter && example.file_name != file_name_filter) continue;
|
||||
if (example.input.size() < 256) continue;
|
||||
|
||||
ts_document_invalidate(document);
|
||||
ts_document_set_input_string(document, example.input.c_str());
|
||||
|
|
@ -71,12 +98,23 @@ int main(int argc, char *arg[]) {
|
|||
ts_document_parse(document);
|
||||
clock_t end_time = clock();
|
||||
unsigned duration = (end_time - start_time) * 1000 / CLOCKS_PER_SEC;
|
||||
printf(" %-30s\t%u\n", example.file_name.c_str(), duration);
|
||||
size_t speed = static_cast<double>(example.input.size()) / duration;
|
||||
printf(" %-30s\t%u ms\t\t%lu bytes/ms\n", example.file_name.c_str(), duration, speed);
|
||||
error_speeds.push_back(speed);
|
||||
}
|
||||
}
|
||||
|
||||
puts("");
|
||||
}
|
||||
|
||||
puts("without errors:");
|
||||
printf(" %-30s\t%lu bytes/ms\n", "average speed", mean(non_error_speeds));
|
||||
printf(" %-30s\t%lu bytes/ms\n", "worst speed", min(non_error_speeds));
|
||||
puts("");
|
||||
|
||||
puts("with errors:");
|
||||
printf(" %-30s\t%lu bytes/ms\n", "average speed", mean(error_speeds));
|
||||
printf(" %-30s\t%lu bytes/ms\n", "worst speed", min(error_speeds));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue