-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental Rust parser + benchmark
- Loading branch information
1 parent
1b1d382
commit d436cdb
Showing
67 changed files
with
8,959 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM debian:bookworm-slim | ||
|
||
SHELL ["/bin/bash","-l","-c"] | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Libs | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
gnupg \ | ||
build-essential \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN apt-get update && apt-get install -y libclang-dev | ||
|
||
RUN apt-get install ghostscript shared-mime-info openssl curl gnupg2 dirmngr git-core libcurl4-openssl-dev software-properties-common zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libffi-dev libpq-dev libmagickcore-6.q16-dev -y | ||
|
||
# Rust | ||
|
||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ | ||
&& chmod +x $HOME/.cargo/bin/rustc | ||
|
||
# Ruby (rbenv) | ||
|
||
RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv | ||
RUN echo 'export PATH="~/.rbenv/bin:$PATH"' >> ~/.bashrc | ||
RUN echo 'eval "$(rbenv init -)"' >> ~/.bashrc | ||
|
||
RUN git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build | ||
RUN echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc | ||
|
||
ENV PATH="${HOME}/.rbenv/plugins/ruby-build/bin:${HOME}/.rbenv/bin:${PATH}" | ||
|
||
RUN rbenv install 3.3.6 | ||
RUN rbenv global 3.3.6 | ||
|
||
# Benchmark | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN bundle config set without 'jekyll-plugins' && bundle install | ||
RUN bundle exec rake clobber compile | ||
|
||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
RUN cd rust_graphql_parser && bundle install && bundle exec rake clobber compile && cd .. | ||
CMD ["/root/.rbenv/shims/bundle", "exec", "ruby", "--yjit", "/app/benchmark/parser_benchmark.rb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "benchmark/ips" | ||
require "graphql/c_parser" | ||
require 'rust_graphql_parser' | ||
require "memory_profiler" | ||
|
||
BENCHMARK_PATH = File.expand_path("../", __FILE__) | ||
BIG_QUERY_STRING = File.read(File.join(BENCHMARK_PATH, "big_query.graphql")) | ||
BIG_QUERY = GraphQL.parse(BIG_QUERY_STRING) | ||
|
||
def rust_parse(query) | ||
GraphQL.default_parser = RustGraphqlParserWrapper | ||
GraphQL.parse(BIG_QUERY_STRING) | ||
end | ||
|
||
def ruby_parse(query) | ||
GraphQL.default_parser = GraphQL::Language::Parser | ||
GraphQL.parse(BIG_QUERY_STRING) | ||
end | ||
|
||
def c_parse(query) | ||
GraphQL.default_parser = GraphQL::CParser | ||
GraphQL.parse(BIG_QUERY_STRING) | ||
end | ||
|
||
# Sanity check. | ||
raise "output mismatch" unless rust_parse(BIG_QUERY) == ruby_parse(BIG_QUERY) | ||
|
||
Benchmark.ips(time: 30) do |x| | ||
x.report("parsing - Rust") { rust_parse(BIG_QUERY) } | ||
x.report("parsing - C") { c_parse(BIG_QUERY) } | ||
x.report("parsing - Ruby") { ruby_parse(BIG_QUERY) } | ||
x.compare! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.bundle | ||
*.so | ||
*.o | ||
*.a | ||
mkmf.log | ||
target/ | ||
|
||
# rspec failure tracking | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
AllCops: | ||
TargetRubyVersion: 2.6 | ||
|
||
Style/StringLiterals: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
|
||
Style/StringLiteralsInInterpolation: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
|
||
Layout/LineLength: | ||
Max: 120 |
Oops, something went wrong.