daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'benchmark/ips'
  2.  
  3. Benchmark.ips do |bench|
  4.   EMPTY_STRING  = ''
  5.   WHITESPACE    = "   \n\t\n   "
  6.   CONTAINS_TEXT = '   hi       '
  7.  
  8.   PATTERN = /\A[[:space:]]*\z/
  9.  
  10.   bench.report('Regexp#match?') do
  11.     PATTERN.match?(EMPTY_STRING)
  12.     PATTERN.match?(WHITESPACE)
  13.     PATTERN.match?(CONTAINS_TEXT)
  14.   end
  15.  
  16.   bench.report('Regexp#match') do
  17.     PATTERN.match(EMPTY_STRING)
  18.     PATTERN.match(WHITESPACE)
  19.     PATTERN.match(CONTAINS_TEXT)
  20.   end
  21.  
  22.   bench.report('Regexp#=~') do
  23.     PATTERN =~ EMPTY_STRING
  24.     PATTERN =~ WHITESPACE
  25.     PATTERN =~ CONTAINS_TEXT
  26.   end
  27.  
  28.   bench.report('Regexp#===') do
  29.     PATTERN === EMPTY_STRING
  30.     PATTERN === WHITESPACE
  31.     PATTERN === CONTAINS_TEXT
  32.   end
  33.  
  34.   bench.compare!
  35. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top