From 9f77380ddbc72347063065d9e9f7c4a13cd504d5 Mon Sep 17 00:00:00 2001 From: Michael Herold Date: Fri, 24 Feb 2017 06:36:59 -0600 Subject: [PATCH] Add performance benchmarks for Mash --- benchmarks/mash_method_access.rb | 15 +++++++++++++++ spec/integration/omniauth/Gemfile | 2 ++ spec/integration/omniauth/Rakefile | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100755 benchmarks/mash_method_access.rb create mode 100644 spec/integration/omniauth/Rakefile diff --git a/benchmarks/mash_method_access.rb b/benchmarks/mash_method_access.rb new file mode 100755 index 00000000..d76cd58f --- /dev/null +++ b/benchmarks/mash_method_access.rb @@ -0,0 +1,15 @@ +$LOAD_PATH.unshift('lib') + +require 'hashie' +require 'benchmark/ips' + +mash = Hashie::Mash.new(test: 'value') + +Benchmark.ips do |x| + x.hold!('tmp/mash_benchmark.json') + + x.report('before') { mash.test } + x.report('after') { mash.test } + + x.compare! +end diff --git a/spec/integration/omniauth/Gemfile b/spec/integration/omniauth/Gemfile index cbb4b875..4221e7f0 100644 --- a/spec/integration/omniauth/Gemfile +++ b/spec/integration/omniauth/Gemfile @@ -1,7 +1,9 @@ source 'http://rubygems.org' +gem 'benchmark-ips' gem 'hashie', path: '../../..' gem 'omniauth', '~> 1.4.1' gem 'sinatra' +gem 'rake' gem 'rspec', '~> 3.5.0' gem 'rack-test', '~> 0.6.3' diff --git a/spec/integration/omniauth/Rakefile b/spec/integration/omniauth/Rakefile new file mode 100644 index 00000000..4e0c11f8 --- /dev/null +++ b/spec/integration/omniauth/Rakefile @@ -0,0 +1,29 @@ +namespace :perf do + task :setup do + require 'omniauth' + require 'rack/test' + app = Rack::Builder.new do |b| + b.use Rack::Session::Cookie, secret: 'abc123' + b.use OmniAuth::Strategies::Developer + b.run ->(_env) { [200, {}, ['Not Found']] } + end.to_app + @app = Rack::MockRequest.new(app) + + def call_app(path = ENV['GET_PATH'] || '/') + result = @app.get(path) + fail "Did not succeed #{result.body}" unless result.status == 200 + result + end + end + + task ips: :setup do + require 'benchmark/ips' + Benchmark.ips do |x| + x.hold!('../../../tmp/omniauth_benchmark.json') + x.report('before') { call_app } + x.report('after') { call_app } + + x.compare! + end + end +end