Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to use ffi #4

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .commit/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ ruby:
spec.files = Dir["CHANGELOG.md", "README.md", "LICENSE", "lib/**/*"]
spec.require_path = "lib"

spec.extensions = %w[ext/llhttp/extconf.rb]
spec.extensions = %w[ext/Rakefile]

spec.add_dependency "ffi-compiler", "~> 1.0"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.

Copyright 2020 Metabahn.
Copyright 2020-2021 Metabahn.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
Expand Down
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

require "fileutils"
require "rake/extensiontask"

Rake::ExtensionTask.new "llhttp_ext" do |ext|
ext.ext_dir = "ext/llhttp"
ext.lib_dir = "lib/llhttp"
task :compile do
system "cd ext && bundle exec rake"
end

task test: :compile do
Expand Down
8 changes: 8 additions & 0 deletions benchmarks/ffi/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "llhttp", path: "../.."

gem "benchmark-ips"
gem "ruby-prof"
20 changes: 20 additions & 0 deletions benchmarks/ffi/run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require_relative "../shared"

benchmark

# require "ruby-prof"

# delegate = LLHttp::Delegate.new
# instance = LLHttp::Parser.new(delegate, type: :request)

# result = RubyProf.profile {
# 1_000_000.times do
# parse(instance)
# instance.finish
# end
# }

# printer = RubyProf::GraphPrinter.new(result)
# printer.print(STDOUT, {})
6 changes: 6 additions & 0 deletions benchmarks/mri/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "benchmark-ips"
gem "llhttp"
5 changes: 5 additions & 0 deletions benchmarks/mri/run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require_relative "../shared"

benchmark
26 changes: 26 additions & 0 deletions benchmarks/shared.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "benchmark/ips"
require "llhttp"

def parse(instance)
instance << "GET / HTTP/1.1\r\n"
instance << "content-length: 18\r\n"
instance << "\r\n"
instance << "body1\n"
instance << "body2\n"
instance << "body3\n"
instance << "\r\n"
end

def benchmark
delegate = LLHttp::Delegate.new
instance = LLHttp::Parser.new(delegate, type: :request)

Benchmark.ips do |x|
x.report do
parse(instance)
instance.finish
end
end
end
5 changes: 5 additions & 0 deletions ext/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require "ffi-compiler/compile_task"

FFI::Compiler::CompileTask.new("llhttp-ext")
7 changes: 0 additions & 7 deletions ext/llhttp/extconf.rb

This file was deleted.

Loading