ruby-boost-regex 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +27 -12
- data/VERSION +1 -1
- data/benchmark/benchmark.rb +18 -0
- data/ext/ruby-boost-regex/extconf.rb +4 -0
- data/ext/ruby-boost-regex/regexp.cpp +5 -0
- metadata +3 -3
data/README.markdown
CHANGED
@@ -58,36 +58,51 @@ Anyway, here's some results:
|
|
58
58
|
DNA-Matching (Computer Language Shootout)
|
59
59
|
=========================================
|
60
60
|
Rehearsal ------------------------------------------------
|
61
|
-
Normal regex 17.
|
62
|
-
|
63
|
-
|
61
|
+
Normal regex 17.240000 0.050000 17.290000 ( 17.353051)
|
62
|
+
Oniguruma 16.300000 0.030000 16.330000 ( 16.384928)
|
63
|
+
Boost regex 11.400000 0.040000 11.440000 ( 11.489252)
|
64
|
+
-------------------------------------- total: 45.060000sec
|
64
65
|
|
65
66
|
user system total real
|
66
|
-
Normal regex 17.
|
67
|
-
|
67
|
+
Normal regex 17.190000 0.030000 17.220000 ( 17.273140)
|
68
|
+
Oniguruma 16.220000 0.040000 16.260000 ( 16.325460)
|
69
|
+
Boost regex 11.330000 0.030000 11.360000 ( 11.402222)
|
68
70
|
|
69
71
|
Failing to match a phone number in a big string of text
|
70
72
|
=======================================================
|
71
73
|
Rehearsal ------------------------------------------------
|
72
|
-
Normal regex 0.070000 0.000000 0.070000 ( 0.
|
73
|
-
|
74
|
-
|
74
|
+
Normal regex 0.070000 0.000000 0.070000 ( 0.072128)
|
75
|
+
Oniguruma 0.040000 0.000000 0.040000 ( 0.043422)
|
76
|
+
Boost regex 0.040000 0.000000 0.040000 ( 0.034708)
|
77
|
+
--------------------------------------- total: 0.150000sec
|
75
78
|
|
76
79
|
user system total real
|
77
|
-
Normal regex 0.070000 0.000000 0.070000 ( 0.
|
78
|
-
|
79
|
-
|
80
|
+
Normal regex 0.070000 0.000000 0.070000 ( 0.071984)
|
81
|
+
Oniguruma 0.040000 0.000000 0.040000 ( 0.044686)
|
82
|
+
Boost regex 0.030000 0.000000 0.030000 ( 0.036421)
|
80
83
|
|
81
84
|
## Usage
|
82
85
|
|
83
|
-
|
86
|
+
Install the gem, use as follows:
|
87
|
+
|
88
|
+
require 'ruby-boost-regex'
|
84
89
|
|
85
90
|
r = Boost::Regexp.new("(\\d{3})-(\\d{3})-(\\d{4})")
|
86
91
|
r =~ "555-123-4567"
|
87
92
|
p $1 # ==> "555"
|
88
93
|
matches = r.match("123-456-7890")
|
89
94
|
p matches[2] # ==> "456"
|
95
|
+
|
96
|
+
Boost::Regex.enable_monkey_patch!
|
97
|
+
|
98
|
+
r = /hello|world/i.boost!
|
99
|
+
r =~ "i'm Mike. Hello!" #==> 10
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
## Installation
|
90
104
|
|
105
|
+
gem install ruby-boost-regex
|
91
106
|
|
92
107
|
## Note on Patches/Pull Requests
|
93
108
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/benchmark/benchmark.rb
CHANGED
@@ -8,8 +8,11 @@
|
|
8
8
|
require 'benchmark'
|
9
9
|
require 'rubygems'
|
10
10
|
require 'ruby-boost-regex'
|
11
|
+
require 'oniguruma'
|
11
12
|
require 'lorem'
|
12
13
|
|
14
|
+
include Oniguruma
|
15
|
+
|
13
16
|
fname = File.dirname(__FILE__) + "/fasta.input"
|
14
17
|
seq = File.read(fname)
|
15
18
|
seq.gsub!(/>.*\n|\n/,"")
|
@@ -50,16 +53,30 @@ boost_regexes = [
|
|
50
53
|
Boost::Regexp.new('agggta[cgt]a|t[acg]taccct', Boost::Regexp::IGNORECASE),
|
51
54
|
Boost::Regexp.new('agggtaa[cgt]|[acg]ttaccct', Boost::Regexp::IGNORECASE)
|
52
55
|
]
|
56
|
+
oni_regexes = [
|
57
|
+
ORegexp.new('agggtaaa|tttaccct', :options => OPTION_IGNORECASE),
|
58
|
+
ORegexp.new('[cgt]gggtaaa|tttaccc[acg]', :options => OPTION_IGNORECASE),
|
59
|
+
ORegexp.new('a[act]ggtaaa|tttacc[agt]t', :options => OPTION_IGNORECASE),
|
60
|
+
ORegexp.new('ag[act]gtaaa|tttac[agt]ct', :options => OPTION_IGNORECASE),
|
61
|
+
ORegexp.new('agg[act]taaa|ttta[agt]cct', :options => OPTION_IGNORECASE),
|
62
|
+
ORegexp.new('aggg[acg]aaa|ttt[cgt]ccct', :options => OPTION_IGNORECASE),
|
63
|
+
ORegexp.new('agggt[cgt]aa|tt[acg]accct', :options => OPTION_IGNORECASE),
|
64
|
+
ORegexp.new('agggta[cgt]a|t[acg]taccct', :options => OPTION_IGNORECASE),
|
65
|
+
ORegexp.new('agggtaa[cgt]|[acg]ttaccct', :options => OPTION_IGNORECASE)
|
66
|
+
]
|
67
|
+
|
53
68
|
puts "DNA-Matching (Computer Language Shootout)"
|
54
69
|
puts "========================================="
|
55
70
|
Benchmark.bmbm do |x|
|
56
71
|
x.report("Normal regex") { 100.times { regexes.each { |reg| fair_scan(seq, reg)}} }
|
72
|
+
x.report("Oniguruma") { 100.times { oni_regexes.each {|reg| fair_scan(seq, reg)}} }
|
57
73
|
x.report("Boost regex") { 100.times { boost_regexes.each { |reg| fair_scan(seq, reg)}} }
|
58
74
|
end
|
59
75
|
|
60
76
|
|
61
77
|
reg = /\d{3}-\d{3}-\d{4}/
|
62
78
|
boost_reg = Boost::Regexp.new('\d{3}-\d{3}-\d{4}')
|
79
|
+
oni_reg = ORegexp.new('\d{3}-\d{3}-\d{4}')
|
63
80
|
text = Lorem::Base.new('paragraphs', 200).output
|
64
81
|
|
65
82
|
puts ""
|
@@ -67,5 +84,6 @@ puts "Failing to match a phone number in a big string of text"
|
|
67
84
|
puts "======================================================="
|
68
85
|
Benchmark.bmbm do |x|
|
69
86
|
x.report("Normal regex") { 100.times { fair_scan(text, reg)}}
|
87
|
+
x.report("Oniguruma") { 100.times { fair_scan(text, oni_reg)}}
|
70
88
|
x.report("Boost regex") { 100.times { fair_scan(text, boost_reg)}}
|
71
89
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Edgar
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-08 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|