Permalink
Browse files

Added reindex benchmarks [skip ci]

  • Loading branch information...
ankane committed Dec 30, 2016
1 parent a1a9a19 commit 44bcf6f0f244fe1a7867dfc855c00ad35da2f899
Showing with 54 additions and 1 deletion.
  1. +4 −0 Rakefile
  2. +10 −0 benchmark/Gemfile
  3. +39 −0 benchmark/benchmark.rb
  4. +1 −1 searchkick.gemspec
View
@@ -6,3 +6,7 @@ Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
end
task :benchmark do
require_relative "benchmark/benchmark"
end
View
@@ -0,0 +1,10 @@
source "https://rubygems.org"
# Specify your gem's dependencies in searchkick.gemspec
gemspec path: "../"
gem "sqlite3"
gem "activerecord", "~> 5.0.0"
gem "activerecord-import"
gem "ruby-prof"
gem "oj"
View
@@ -0,0 +1,39 @@
require "bundler/setup"
Bundler.require(:default)
require "active_record"
require "benchmark"
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Migration.create_table :products do |t|
t.string :name
t.string :color
t.integer :store_id
end
class Product < ActiveRecord::Base
searchkick batch_size: 100
end
Product.import ["name", "color", "store_id"], 100000.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }
puts "Imported"
result = nil
time =
Benchmark.realtime do
# result = RubyProf.profile do
Product.reindex(refresh_interval: "30s")
# end
end
puts time.round(1)
puts Product.searchkick_index.total_docs
# printer = RubyProf::GraphPrinter.new(result)
# printer.print(STDOUT, min_percent: 2)
# puts Product.count
View
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.test_files = spec.files.grep(%r{^(test|spec|features|benchmark)/})
spec.require_paths = ["lib"]
spec.add_dependency "activemodel", ">= 4.1"

0 comments on commit 44bcf6f

Please sign in to comment.