ruby-boost-regex 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.190000 0.020000 17.210000 ( 17.278168)
62
- Boost regex 12.120000 0.030000 12.150000 ( 12.213959)
63
- -------------------------------------- total: 29.360000sec
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.050000 0.020000 17.070000 ( 17.082539)
67
- Boost regex 12.000000 0.030000 12.030000 ( 12.040932)
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.070072)
73
- Boost regex 0.030000 0.000000 0.030000 ( 0.034858)
74
- --------------------------------------- total: 0.100000sec
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.070087)
78
- Boost regex 0.040000 0.000000 0.040000 ( 0.035052)
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
- Don't have it as a gem yet. Sorry! But you could do this in theory:
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.0
1
+ 1.0.1
@@ -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
@@ -1,5 +1,9 @@
1
1
  require 'mkmf'
2
2
 
3
+ dir_config("boost")
3
4
  have_library("stdc++")
4
5
  have_library("boost_regex")
6
+ if RUBY_VERSION =~ /1.9/ then
7
+ $CPPFLAGS += " -DRUBY_19"
8
+ end
5
9
  create_makefile('ruby-boost-regex/BoostRegexHook')
@@ -3,7 +3,12 @@
3
3
  #include <string>
4
4
  #include <exception>
5
5
  #include "ruby.h"
6
+
7
+ #ifdef RUBY_19
8
+ #include "ruby/re.h"
9
+ #else
6
10
  #include "re.h"
11
+ #endif
7
12
 
8
13
  static VALUE rb_mBoost;
9
14
  static VALUE rb_cBoostRegexp;
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.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-06 00:00:00 -04:00
17
+ date: 2010-04-08 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency