forked from jekyll/jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp-vs-include.rb
executable file
·51 lines (45 loc) · 1.59 KB
/
regexp-vs-include.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
require 'benchmark/ips'
# For this pull request, which changes Page#dir
# https://github.com/jekyll/jekyll/pull/4403
CONTENT_CONTAINING = <<-HTML.freeze
<!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.freeze
<!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