From 994ba6fdd074a0dd2fe77ffca116c48664f71fe5 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Sat, 13 Jun 2020 12:56:49 +0200 Subject: [PATCH] Add benchmark specs --- spec/benchmark_spec.rb | 17 +++++++++++++++++ spec/spec_helper.rb | 9 +++++++++ valid_email2.gemspec | 1 + 3 files changed, 27 insertions(+) create mode 100644 spec/benchmark_spec.rb diff --git a/spec/benchmark_spec.rb b/spec/benchmark_spec.rb new file mode 100644 index 0000000..8824c3e --- /dev/null +++ b/spec/benchmark_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Performance testing" do + + let(:disposable_domain) { ValidEmail2.disposable_emails.first } + + it "lookup timing" do + # preload disposable emails + list = ValidEmail2.disposable_emails + address = ValidEmail2::Address.new("test@example.com") + + expect { address.send(:domain_is_in?, list) }.to perform_under(0.0001).sample(10).times + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8ffdb50..3a2a1ec 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,15 @@ $:.unshift File.expand_path("../lib",__FILE__) require "valid_email2" +# Include and configure benchmark +require 'rspec-benchmark' +RSpec.configure do |config| + config.include RSpec::Benchmark::Matchers +end +RSpec::Benchmark.configure do |config| + config.disable_gc = true +end + class TestModel include ActiveModel::Validations diff --git a/valid_email2.gemspec b/valid_email2.gemspec index f89c8a0..55c7d52 100644 --- a/valid_email2.gemspec +++ b/valid_email2.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 2.0" spec.add_development_dependency "rake", "~> 12.3.3" spec.add_development_dependency "rspec", "~> 3.5.0" + spec.add_development_dependency "rspec-benchmark", "~> 0.6" spec.add_development_dependency "pry" spec.add_runtime_dependency "mail", "~> 2.5" spec.add_runtime_dependency "activemodel", ">= 3.2"