Code Monkey home page Code Monkey logo

antlr4-runtime-benchmarks's Introduction

ANTLR4 Benchmarks

This repository consists of various benchmarks that can be used to measure the performance of certain ANTLR4 runtimes in conjunction with a selected grammar.

Benchmarks Structure

The benchmarks are organized in folders (located in the src directory), whose names correspond to the grammar that is tested in that subtree, or a descriptive name for artificial grammars that deal with specific aspects of ANTLR4 lexers and grammars. Each of these folders contains subfolders for each target. This way we have independent subprojects, each of which can be built and run independently.

Currently there's only one set of benchmarks: MySQL parser benchmarks (using the official MySQL grammar from Oracle). The plan is to add more over time.

There's an own readme file for each grammar, explaining the installation details and listing the latest results. The general idea for all benchmarks is to do only the absolute minimum to measure the time a script or binary needs to parse specific input for a given grammar. No third party (test/benchmark) libraries or anything not directly related to building a runnable parser should be involved, to maintain a low entry point for everyone interested in running the benchmarks on their own boxes.

It's not needed to measure times in micro seconds or even smaller time units, for a comparison. Instead the input should be complex enough to make a parser run more than just a few milliseconds.

Here's the list of the existing grammar benchmarks:

Runtime Prequisites

Most runtimes must be built first, so that the benchmarks can use them. This section explains details for each of them.

TypeScript

As a scripting language there's nothing you need to prepare. If you have Node.js installed you have everything you need for execution.

C++

The C++ benchmarks need the C++ runtime as a dynamic library. You can either provide one yourself (e.g. from other projects) and copy that to the /antlr4-cpp-runtime/lib folder. It must be named antlr4-runtime (plus the platform dependent extension like .so on Linux or .dylib on macOS) so that the build scripts can find it for linking.

Or you can use a build script from this project, which I plan to add a bit later.

antlr4-runtime-benchmarks's People

Contributors

mike-lischke avatar

Stargazers

jialiang avatar Ivan Kochurkin avatar

Watchers

 avatar  avatar

Forkers

bkiers

antlr4-runtime-benchmarks's Issues

> StringTemplate for target actions in grammars

I don't use the @members

Sorry, you are right. I just noticed that you already have the code in base classes.

but still, you have to import these classes and the calls to methods are different (depending on the target)

Yes, that is true, but that's exactly what "transformGrammar is all about. Yes, it is a totally disgusting hack, but it allows for the grammar to be shared for all targets.

Rather than have all these different syntax, the grammar always uses "this." in all actions, and transformGrammmar.py replaces the pattern with the appropriate syntax. To be really "target agnostic", you shouldn't even use operators like <, %, etc. I forgot, but there is one target for one grammar in grammars-v4 that had this issue.

For Cpp, the semantic action https://github.com/mike-lischke/antlr4-runtime-benchmarks/blob/a971852628d9ecca0ce79c7972e3c026017bdadc/src/mysql/targets/antlr4-cpp/MySQLLexer.g4#L474C90-L474C111 does not have a "this->", but is it required because the field is already declared in the base class. In most grammars, the "transformGrammar.py" hack is required to mutate "this." to "this->".

For JavaScript and TypeScript, "this." must be used https://github.com/mike-lischke/antlr4-runtime-benchmarks/blob/a971852628d9ecca0ce79c7972e3c026017bdadc/src/mysql/targets/antlr4/MySQLLexer.g4#L486C90-L486C116 . But, since we already require "this." for all field and method references for "target agnostic format", it's fine as is.

For Go, lexer predicates must be reference with "l." which parser predicates are "p.".

Etc., etc., etc.

A much better solution would be to provide a StringTemplate expansion for the target. A PR was added for this here: antlr/antlr4#4345 , but personally, I'd make the entire file a string template, and prefix or suffix the file with .st, and just apply ST through the whole file. Trash already does this. (You have to have a tool like trgen because Java requires base class code to be in a specific directory structure if you use a -package option for the Antlr tool.

Originally posted by @kaby76 in #1 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.