Sha256: a17ddb360948aedbc5b303451b21f06db48edb232c517bd8da459e43f46f82b5

Contents?: true

Size: 1.4 KB

Versions: 26

Compression:

Stored size: 1.4 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'benchmark/ips'
require_relative '../lib/jekyll'

puts ''
print 'Setting up... '

SITE = Jekyll::Site.new(
  Jekyll.configuration({
                         'source' => File.expand_path('../docs', __dir__),
                         'destination' => File.expand_path('../docs/_site', __dir__),
                         'disable_disk_cache' => true,
                         'quiet' => true
                       })
)

TEMPLATE_1 = Liquid::Template.parse(<<~HTML)
  {%- assign doc = site.documents | where: 'url', '/docs/assets/' | first -%}
  {{- doc.title -}}
HTML

TEMPLATE_2 = Liquid::Template.parse(<<~HTML)
  {%- assign doc = site.documents | find: 'url', '/docs/assets/' -%}
  {{- doc.title -}}
HTML

%i[reset read generate].each { |phase| SITE.send(phase) }

puts 'done.'
puts 'Testing... '
puts "  #{'where + first'.cyan} results in #{TEMPLATE_1.render(SITE.site_payload).inspect.green}"
puts "  #{'find'.cyan} results in #{TEMPLATE_2.render(SITE.site_payload).inspect.green}"

if TEMPLATE_1.render(SITE.site_payload) == TEMPLATE_2.render(SITE.site_payload)
  puts 'Success! Proceeding to run benchmarks.'.green
  puts ''
else
  puts 'Something went wrong. Aborting.'.magenta
  puts ''
  return
end

Benchmark.ips do |x|
  x.report('where + first') { TEMPLATE_1.render(SITE.site_payload) }
  x.report('find') { TEMPLATE_2.render(SITE.site_payload) }
  x.compare!
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
lbenicio-minimal-v1-1.6.4 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.6.3 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.6.2 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.6.1 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.5.3 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.5.2 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.5.0 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.4.0 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.3.3 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.3.2 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.3.1 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.3.0 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.2.1 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.2.0 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.9 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.8 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.7 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.6 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.5 benchmark/find-filter-vs-where-first-filters.rb
lbenicio-minimal-v1-1.1.4 benchmark/find-filter-vs-where-first-filters.rb