Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/lexer_performance' into …
Browse files Browse the repository at this point in the history
…feature/pure_ruby_lexer
  • Loading branch information
bklang committed May 28, 2013
2 parents adb5e4c + 65650a4 commit 8976878
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ guard 'rspec', :version => 2, :cli => '--format documentation' do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec/" }
end

guard 'shell' do
watch("lib/ruby_ami/lexer.rb") { `rake features benchmark` }
end

guard 'shell' do
watch(/benchmarks\/*/) { `rake benchmark` }
end
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Cucumber::Rake::Task.new(:wip) do |t|
end

task :default => [:spec, :features]
require 'timeout'
desc "Run benchmarks"
task :benchmark do
begin
Timeout.timeout(120) do
glob = File.expand_path("../benchmarks/*.rb", __FILE__)
Dir[glob].each { |benchmark| load benchmark }
end
rescue Exception, Timeout::Error => ex
puts "ERROR: Couldn't complete benchmark: #{ex.class}: #{ex}"
puts " #{ex.backtrace.join("\n ")}"

exit 1 unless ENV['CI'] # Hax for running benchmarks on Travis
end
end

require 'yard'
YARD::Rake::YardocTask.new
47 changes: 47 additions & 0 deletions benchmarks/lexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'bundler/setup'
require 'ruby_ami'
require 'benchmark/ips'

class LexerHost
def initialize
@lexer = RubyAMI::Lexer.new self
end

def receive_data(data)
@lexer << data
end

def message_received(message)
end

def error_received(error)
end

def syntax_error_encountered(ignored_chunk)
end
end

lexer_host = LexerHost.new

event = <<-EVENT
Event: Dial
SubEvent: <value>
Channel: <value>
Destination: <value>
CallerIDNum: <value>
CallerIDName: <value>
ConnectedLineNum: <value>
ConnectedLineName: <value>
UniqueID: <value>
DestUniqueID: <value>
Dialstring: <value>
EVENT
event.gsub!("\n", "\r\n")

Benchmark.ips do |ips|
ips.report("event lexing") { lexer_host.receive_data event }
end
1 change: 1 addition & 0 deletions ruby_ami.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Gem::Specification.new do |s|
s.add_development_dependency %q<guard-rspec>
s.add_development_dependency %q<guard-shell>
s.add_development_dependency %q<ruby_gntp>
s.add_development_dependency %q<benchmark_suite>
end

0 comments on commit 8976878

Please sign in to comment.