Skip to content

Instantly share code, notes, and snippets.

@ccocchi
Created January 22, 2019 16:46
Show Gist options
  • Save ccocchi/a5201dcd70c07d5388799546e264fa7d to your computer and use it in GitHub Desktop.
Save ccocchi/a5201dcd70c07d5388799546e264fa7d to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'benchmark/ips'
require 'oj'
require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment'))
require 'elasticsearch-dsl'
class Official
include Elasticsearch::DSL
def result
definition = search do
query do
bool do
must do
match title: 'test'
end
must do
terms 'profile.cities' => ['FR_10', 'ES_10']
end
end
end
end
definition.to_hash
end
end
class Ours
include ::QueryBuilding::Builder
def result
query do
bool do
match :title, 'test'
terms 'profile.cities', ['FR_10', 'ES_10']
end
end
end
end
official = Official.new
ours = Ours.new
Benchmark.ips do |x|
x.report('official') do
official.result
end
x.report('ours') do
ours.result
end
x.compare!
end
@ccocchi
Copy link
Author

ccocchi commented Jan 22, 2019

Warming up --------------------------------------
            official     1.824k i/100ms
                ours    11.364k i/100ms
Calculating -------------------------------------
            official     18.403k (±11.1%) i/s -     91.200k in   5.017215s
                ours    121.321k (±10.7%) i/s -    602.292k in   5.019276s

Comparison:
                ours:   121320.8 i/s
            official:    18403.2 i/s - 6.59x  slower

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment