Rework API completely
This commit is contained in:
parent
33f7643040
commit
e75ecd1bb1
31 changed files with 841 additions and 1075 deletions
|
|
@ -43,12 +43,12 @@ int main(int argc, char *arg[]) {
|
|||
vector<size_t> error_speeds;
|
||||
vector<size_t> non_error_speeds;
|
||||
|
||||
auto document = ts_document_new();
|
||||
TSParser *parser = ts_parser_new();
|
||||
|
||||
if (getenv("TREE_SITTER_BENCHMARK_SVG")) {
|
||||
ts_document_print_debugging_graphs(document, true);
|
||||
ts_parser_print_debugging_graphs(parser, true);
|
||||
} else if (getenv("TREE_SITTER_BENCHMARK_LOG")) {
|
||||
ts_document_set_logger(document, stderr_logger_new(false));
|
||||
ts_parser_set_logger(parser, stderr_logger_new(false));
|
||||
}
|
||||
|
||||
auto language_filter = getenv("TREE_SITTER_BENCHMARK_LANGUAGE");
|
||||
|
|
@ -61,7 +61,7 @@ int main(int argc, char *arg[]) {
|
|||
for (auto &language_name : language_names) {
|
||||
if (language_filter && language_name != language_filter) continue;
|
||||
|
||||
ts_document_set_language(document, load_real_language(language_name));
|
||||
ts_parser_set_language(parser, load_real_language(language_name));
|
||||
|
||||
printf("%s\n", language_name.c_str());
|
||||
|
||||
|
|
@ -69,20 +69,16 @@ int main(int argc, char *arg[]) {
|
|||
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());
|
||||
|
||||
clock_t start_time = clock();
|
||||
ts_document_parse(document);
|
||||
TSTree *tree = ts_parser_parse_string(parser, nullptr, example.input.c_str(), example.input.size());
|
||||
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)));
|
||||
|
||||
assert(!ts_node_has_error(ts_tree_root_node(tree)));
|
||||
ts_tree_delete(tree);
|
||||
|
||||
size_t duration = (end_time - start_time) * 1000 / CLOCKS_PER_SEC;
|
||||
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);
|
||||
printf(" %-30s\t%lu ms\t\t%lu bytes/ms\n", example.file_name.c_str(), duration, speed);
|
||||
if (speed != 0) non_error_speeds.push_back(speed);
|
||||
}
|
||||
|
||||
|
|
@ -93,15 +89,15 @@ int main(int argc, char *arg[]) {
|
|||
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());
|
||||
|
||||
clock_t start_time = clock();
|
||||
ts_document_parse(document);
|
||||
TSTree *tree = ts_parser_parse_string(parser, nullptr, example.input.c_str(), example.input.size());
|
||||
clock_t end_time = clock();
|
||||
unsigned duration = (end_time - start_time) * 1000 / CLOCKS_PER_SEC;
|
||||
|
||||
ts_tree_delete(tree);
|
||||
|
||||
size_t duration = (end_time - start_time) * 1000 / CLOCKS_PER_SEC;
|
||||
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);
|
||||
printf(" %-30s\t%lu ms\t\t%lu bytes/ms\n", example.file_name.c_str(), duration, speed);
|
||||
if (speed != 0) error_speeds.push_back(speed);
|
||||
}
|
||||
}
|
||||
|
|
@ -118,5 +114,6 @@ int main(int argc, char *arg[]) {
|
|||
printf(" %-30s\t%lu bytes/ms\n", "average speed", mean(error_speeds));
|
||||
printf(" %-30s\t%lu bytes/ms\n", "worst speed", min(error_speeds));
|
||||
|
||||
ts_parser_delete(parser);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue