Sha256: 4a9c9bfc28ddb408ea6c2c57e38305b1049b1beaddcb67d7067a08217a4d46d6

Contents?: true

Size: 1.65 KB

Versions: 26

Compression:

Stored size: 1.65 KB

Contents

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

require 'benchmark/ips'

# For this pull request, which changes Page#dir
# https://github.com/jekyll/jekyll/pull/4403

CONTENT_CONTAINING = <<~HTML
  <!DOCTYPE HTML>
  <html lang="en-US">
    <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="UTF-8">
      <title>Jemoji</title>
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <link rel="stylesheet" href="/css/screen.css">
    </head>
    <body class="wrap">
      <p><img class="emoji" title=":+1:" alt=":+1:" src="https://assets.github.com/images/icons/emoji/unicode/1f44d.png" height="20" width="20" align="absmiddle"></p>

    </body>
  </html>
HTML
CONTENT_NOT_CONTAINING = <<~HTML
  <!DOCTYPE HTML>
  <html lang="en-US">
    <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="UTF-8">
      <title>Jemoji</title>
      <meta name="viewport" content="width=device-width,initial-scale=1">
      <link rel="stylesheet" href="/css/screen.css">
    </head>
    <body class="wrap">
      <p><img class="emoji" title=":+1:" alt=":+1:" src="https://assets.github.com/images/icons/emoji/unicode/1f44d.png" height="20" width="20" align="absmiddle"></p>

    </body>
  </html>
HTML

Benchmark.ips do |x|
  x.report('no body include?') { CONTENT_NOT_CONTAINING.include?('<body') }
  x.report('no body regexp')   { CONTENT_NOT_CONTAINING =~ /<\s*body/ }
  x.compare!
end

# No trailing slash
Benchmark.ips do |x|
  x.report('with body include?') { CONTENT_CONTAINING.include?('<body') }
  x.report('with body regexp')   { CONTENT_CONTAINING =~ /<\s*body/ }
  x.compare!
end

Version data entries

26 entries across 26 versions & 1 rubygems

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