bibtex-ruby 1.3.3 → 1.3.4

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.

Potentially problematic release.


This version of bibtex-ruby might be problematic. Click here for more details.

data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibtex-ruby (1.3.3)
4
+ bibtex-ruby (1.3.4)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -11,15 +11,16 @@ GEM
11
11
  watchr
12
12
  builder (3.0.0)
13
13
  columnize (0.3.2)
14
- cucumber (0.10.3)
14
+ cucumber (0.10.5)
15
15
  builder (>= 2.1.2)
16
16
  diff-lcs (>= 1.1.2)
17
- gherkin (>= 2.3.8)
17
+ gherkin (~> 2.4.0)
18
18
  json (>= 1.4.6)
19
19
  term-ansicolor (>= 1.0.5)
20
20
  diff-lcs (1.1.2)
21
- gherkin (2.3.10)
21
+ gherkin (2.4.0)
22
22
  json (>= 1.4.6)
23
+ gnuplot (2.3.6)
23
24
  json (1.5.1)
24
25
  linecache (0.43)
25
26
  linecache19 (0.5.12)
@@ -30,7 +31,7 @@ GEM
30
31
  mynyml-redgreen (0.7.1)
31
32
  term-ansicolor (>= 1.0.4)
32
33
  racc (1.4.6)
33
- rake (0.9.0)
34
+ rake (0.9.2)
34
35
  ruby-debug (0.10.4)
35
36
  columnize (>= 0.1)
36
37
  ruby-debug-base (~> 0.10.4.0)
@@ -44,6 +45,7 @@ GEM
44
45
  columnize (>= 0.3.1)
45
46
  linecache19 (>= 0.5.11)
46
47
  ruby-debug-base19 (>= 0.11.19)
48
+ ruby-prof (0.10.7)
47
49
  ruby_core_source (0.1.5)
48
50
  archive-tar-minitar (>= 0.5.2)
49
51
  term-ansicolor (1.0.5)
@@ -56,6 +58,7 @@ DEPENDENCIES
56
58
  autowatchr (>= 0.1)
57
59
  bibtex-ruby!
58
60
  cucumber (>= 0.10)
61
+ gnuplot (>= 2.3)
59
62
  json (>= 1.5)
60
63
  mini_shoulda (>= 0.3)
61
64
  mynyml-redgreen (>= 0.7)
@@ -63,3 +66,4 @@ DEPENDENCIES
63
66
  rake (>= 0.8)
64
67
  ruby-debug
65
68
  ruby-debug19
69
+ ruby-prof (>= 0.10)
data/History.txt CHANGED
@@ -1,4 +1,8 @@
1
- === 1.3.3
1
+ === 1.3.4 / 2011-06-07
2
+
3
+ * Performance boost for parsing of large bibliographies
4
+
5
+ === 1.3.3 / 2011-06-06
2
6
 
3
7
  * Fixed name parsing of nested braced expressions
4
8
 
data/Manifest CHANGED
@@ -1,4 +1,3 @@
1
- Bibliography.bib
2
1
  Gemfile
3
2
  Gemfile.lock
4
3
  History.txt
@@ -61,6 +60,7 @@ test/bibtex/test_string.rb
61
60
  test/bibtex/test_utilities.rb
62
61
  test/bibtex/test_value.rb
63
62
  test/fixtures
63
+ test/fixtures/benchmark.bib
64
64
  test/fixtures/bibdesk.bib
65
65
  test/fixtures/comment.bib
66
66
  test/fixtures/decoret.bib
@@ -71,5 +71,7 @@ test/fixtures/no_bibtex.bib
71
71
  test/fixtures/preamble.bib
72
72
  test/fixtures/roundtrip.bib
73
73
  test/helper.rb
74
+ test/profile.dot
75
+ test/profile.rb
74
76
  test/test_bibtex.rb
75
77
  test/test_export.rb
data/Rakefile CHANGED
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
4
  require 'rubygems'
5
5
  require 'bundler/setup'
6
6
 
7
- require 'rake'
8
7
  require 'rake/clean'
9
8
  require 'rake/testtask'
10
- require 'rake/rdoctask'
9
+
10
+ require 'rdoc/task'
11
11
 
12
12
  require 'bibtex/version'
13
13
 
14
- Rake::RDocTask.new(:rdoc_task) do |rd|
14
+ RDoc::Task.new(:rdoc_task) do |rd|
15
15
  rd.main = 'README.md'
16
16
  rd.title = "BibTeX-Ruby Documentation"
17
17
  rd.rdoc_files.include('README.md',"lib/**/*.rb")
@@ -59,6 +59,18 @@ file 'lib/bibtex/name_parser.rb' => ['lib/bibtex/names.y'] do
59
59
  sh 'racc -v -o lib/bibtex/name_parser.rb lib/bibtex/names.y'
60
60
  end
61
61
 
62
+ desc 'Runs the benchmarks (and plots the results)'
63
+ task :benchmark => ['racc'] do
64
+ require File.expand_path('../test/benchmark.rb', __FILE__)
65
+ end
66
+ task :bm => ['benchmark']
67
+
68
+ desc 'Runs the profiler'
69
+ task :profile => ['racc'] do
70
+ require File.expand_path('../test/profile.rb', __FILE__)
71
+ end
72
+
73
+
62
74
  desc 'Updates the Manifest file'
63
75
  task :manifest => ['clean', 'racc'] do
64
76
  m = File.open('Manifest', 'w')
data/bibtex-ruby.gemspec CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency('autowatchr', ['>= 0.1'])
26
26
  s.add_development_dependency('cucumber', ['>= 0.10'])
27
27
  s.add_development_dependency('json', ['>= 1.5'])
28
+ s.add_development_dependency('ruby-prof', ['>= 0.10'])
29
+ s.add_development_dependency('gnuplot', ['>= 2.3'])
28
30
 
29
31
  s.files = File.open('Manifest').readlines.map(&:chomp)
30
32
  s.test_files = Dir.glob('test/**/test*.rb')
data/lib/bibtex/bibtex.y CHANGED
@@ -102,7 +102,7 @@ require 'bibtex/lexer'
102
102
  def parse(input)
103
103
  @yydebug = debug?
104
104
 
105
- @lexer.src = input
105
+ @lexer.data = input
106
106
  @lexer.analyse
107
107
 
108
108
  do_parse
data/lib/bibtex/lexer.rb CHANGED
@@ -26,8 +26,11 @@ module BibTeX
26
26
  #
27
27
  class Lexer
28
28
 
29
- attr_reader :src, :options, :stack
30
-
29
+ attr_reader :data, :options, :stack, :mode
30
+
31
+ DEFAULTS = { :include => [:errors], :strict => true }.freeze
32
+
33
+
31
34
  #
32
35
  # Creates a new instance. Possible options and their respective
33
36
  # default values are:
@@ -41,27 +44,26 @@ module BibTeX
41
44
  # expected to start after a new line (leading white space is permitted).
42
45
  #
43
46
  def initialize(options = {})
44
- @options = options
45
- @options[:include] ||= [:errors]
46
- @options[:strict] = true unless @options.has_key?(:strict)
47
- @src = nil
47
+ @options = DEFAULTS.merge(options)
48
+ @data = nil
48
49
  end
49
50
 
50
51
  # Sets the source for the lexical analysis and resets the internal state.
51
- def src=(src)
52
+ def data=(string)
52
53
  @stack = []
53
54
  @brace_level = 0
54
55
  @mode = :meta
55
56
  @active_object = nil
56
- @src = StringScanner.new(src)
57
- @line_breaks = []
58
- @line_breaks << @src.pos until @src.scan_until(/\n|$/).empty?
59
- @src.reset
57
+ @data = StringScanner.new(string)
58
+
59
+ # @line_breaks = []
60
+ # @line_breaks << @data.pos until @data.scan_until(/\n|$/).empty?
61
+ # @data.reset
60
62
  end
61
63
 
62
64
  # Returns the line number at a given position in the source.
63
65
  def line_number_at(index)
64
- (@line_breaks.find_index { |n| n >= index } || 0) + 1
66
+ 0 # (@line_breaks.find_index { |n| n >= index } || 0) + 1
65
67
  end
66
68
 
67
69
  # Returns the next token from the parse stack.
@@ -70,7 +72,7 @@ module BibTeX
70
72
  end
71
73
 
72
74
  def mode=(mode)
73
- Log.debug("Lexer: switching to #{mode} mode...")
75
+ # Log.debug("Lexer: switching to #{mode} mode...")
74
76
 
75
77
  @active_object = case
76
78
  when [:comment,:string,:preamble,:entry].include?(mode) then mode
@@ -81,73 +83,63 @@ module BibTeX
81
83
  @mode = mode
82
84
  end
83
85
 
84
- def mode
85
- @mode
86
- end
87
-
88
86
  # Returns true if the lexer is currenty parsing a BibTeX object.
89
87
  def bibtex_mode?
90
88
  [:bibtex,:comment,:string,:preamble,:entry].include?(self.mode)
91
89
  end
92
-
93
- # Returns true if the lexer is currently parsing meta content.
94
- def meta_mode?
95
- self.mode == :meta
90
+
91
+ %w{ meta literal content }.each do |m|
92
+ define_method "#{m}_mode?" do
93
+ mode == m.to_sym
94
+ end
96
95
  end
97
96
 
98
- # Returns true if the lexer is currently parsing a braced-out expression.
99
- def content_mode?
100
- self.mode == :content
101
- end
102
-
103
- # Returns true if the lexer is currently parsing a string literal.
104
- def literal_mode?
105
- self.mode == :literal
106
- end
107
-
108
97
  # Returns true if the lexer is currently parsing the given object type.
109
- def is_active?(object)
98
+ def active?(object)
110
99
  @active_object == object
111
100
  end
112
101
 
102
+ # Returns true if the lexer is currently in strict mode.
103
+ def strict?; !!(@options[:strict]); end
104
+
113
105
  # Pushes a value onto the parse stack.
114
106
  def push(value)
115
107
  case
116
108
  when ([:CONTENT,:STRING_LITERAL].include?(value[0]) && value[0] == @stack.last[0])
117
109
  @stack.last[1][0] << value[1]
118
- @stack.last[1][1] = line_number_at(@src.pos)
110
+ @stack.last[1][1] = line_number_at(@data.pos)
119
111
  when value[0] == :ERROR
120
112
  @stack.push(value) if @options[:include].include?(:errors)
121
113
  leave_object
122
114
  when value[0] == :META_CONTENT
123
115
  if @options[:include].include?(:meta_content)
124
- value[1] = [value[1], line_number_at(@src.pos)]
116
+ value[1] = [value[1], line_number_at(@data.pos)]
125
117
  @stack.push(value)
126
118
  end
127
119
  else
128
- value[1] = [value[1], line_number_at(@src.pos)]
120
+ value[1] = [value[1], line_number_at(@data.pos)]
129
121
  @stack.push(value)
130
122
  end
131
- return self
123
+ self
132
124
  end
133
125
 
134
126
  # Start the lexical analysis.
135
- def analyse(src=nil)
136
- raise(ArgumentError, 'Lexer: failed to start analysis: no source given!') if src.nil? && @src.nil?
127
+ def analyse(data=nil)
128
+ raise(ArgumentError, 'Lexer: failed to start analysis: no source given!') if data.nil? && @data.nil?
137
129
  Log.debug('Lexer: starting lexical analysis...')
138
130
 
139
- self.src = src || @src.string
140
- self.src.reset
131
+ self.data = data || @data.string
132
+ @data.reset
141
133
 
142
- until self.src.eos?
134
+ until @data.eos?
143
135
  case
144
- when self.bibtex_mode?
136
+ when bibtex_mode?
145
137
  parse_bibtex
146
- when self.meta_mode?
138
+ when meta_mode?
147
139
  parse_meta
148
- when self.content_mode?
140
+ when content_mode?
149
141
  parse_content
150
- when self.literal_mode?
142
+ when literal_mode?
151
143
  parse_literal
152
144
  end
153
145
  end
@@ -158,53 +150,53 @@ module BibTeX
158
150
 
159
151
  def parse_bibtex
160
152
  case
161
- when self.src.scan(/[\t\r\n\s]+/o)
162
- when self.src.scan(/\{/o)
153
+ when @data.scan(/[\t\r\n\s]+/o)
154
+ when @data.scan(/\{/o)
163
155
  @brace_level += 1
164
156
  push [:LBRACE,'{']
165
- if (@brace_level == 1 && is_active?(:comment)) || (@brace_level == 2 && is_active?(:entry))
157
+ if (@brace_level == 1 && active?(:comment)) || (@brace_level == 2 && active?(:entry))
166
158
  self.mode = :content
167
159
  end
168
- when self.src.scan(/\}/o)
160
+ when @data.scan(/\}/o)
169
161
  return error_unbalanced_braces if @brace_level < 1
170
162
  @brace_level -= 1
171
163
  push [:RBRACE,'}']
172
164
  leave_object if @brace_level == 0
173
- when self.src.scan( /=/o)
165
+ when @data.scan( /=/o)
174
166
  push [:EQ,'=']
175
- when self.src.scan(/,/o)
167
+ when @data.scan(/,/o)
176
168
  push [:COMMA,',']
177
- when self.src.scan(/#/o)
169
+ when @data.scan(/#/o)
178
170
  push [:SHARP,'#']
179
- when self.src.scan(/\d+/o)
180
- push [:NUMBER,self.src.matched]
181
- when self.src.scan(/[a-z\d\/:_!$\.%&*-]+/io)
182
- push [:NAME,self.src.matched]
183
- when self.src.scan(/"/o)
171
+ when @data.scan(/\d+/o)
172
+ push [:NUMBER,@data.matched]
173
+ when @data.scan(/[a-z\d\/:_!$\.%&*-]+/io)
174
+ push [:NAME,@data.matched]
175
+ when @data.scan(/"/o)
184
176
  self.mode = :literal
185
- when self.src.scan(/@/o)
177
+ when @data.scan(/@/o)
186
178
  error_unexpected_token
187
179
  enter_object
188
- when self.src.scan(/./o)
180
+ when @data.scan(/./o)
189
181
  error_unexpected_token
190
182
  enter_object
191
183
  end
192
184
  end
193
185
 
194
186
  def parse_meta
195
- match = self.src.scan_until(@options[:strict] ? /@[\t ]*/o : /(^|\n)[\t ]*@[\t ]*/o)
196
- unless self.src.matched.nil?
187
+ match = @data.scan_until(strict? ? /@[\t ]*/o : /(^|\n)[\t ]*@[\t ]*/o)
188
+ unless @data.matched.nil?
197
189
  push [:META_CONTENT, match.chop]
198
190
  enter_object
199
191
  else
200
- push [:META_CONTENT,self.src.rest]
201
- self.src.terminate
192
+ push [:META_CONTENT,@data.rest]
193
+ @data.terminate
202
194
  end
203
195
  end
204
196
 
205
197
  def parse_content
206
- match = self.src.scan_until(/\{|\}/o)
207
- case self.src.matched
198
+ match = @data.scan_until(/\{|\}/o)
199
+ case @data.matched
208
200
  when '{'
209
201
  @brace_level += 1
210
202
  push [:CONTENT,match]
@@ -218,7 +210,7 @@ module BibTeX
218
210
  push [:CONTENT,match.chop]
219
211
  push [:RBRACE,'}']
220
212
  leave_object
221
- when @brace_level == 1 && is_active?(:entry)
213
+ when @brace_level == 1 && active?(:entry)
222
214
  push [:CONTENT,match.chop]
223
215
  push [:RBRACE,'}']
224
216
  self.mode = :bibtex
@@ -226,15 +218,15 @@ module BibTeX
226
218
  push [:CONTENT, match]
227
219
  end
228
220
  else
229
- push [:CONTENT,self.src.rest]
230
- self.src.terminate
221
+ push [:CONTENT,@data.rest]
222
+ @data.terminate
231
223
  error_unterminated_content
232
224
  end
233
225
  end
234
226
 
235
227
  def parse_literal
236
- match = self.src.scan_until(/[\{\}"\n]/o)
237
- case self.src.matched
228
+ match = @data.scan_until(/[\{\}"\n]/o)
229
+ case @data.matched
238
230
  when '{'
239
231
  @brace_level += 1
240
232
  push [:STRING_LITERAL,match]
@@ -257,8 +249,8 @@ module BibTeX
257
249
  push [:STRING_LITERAL,match.chop]
258
250
  error_unterminated_string
259
251
  else
260
- push [:STRING_LITERAL,self.src.rest]
261
- self.src.terminate
252
+ push [:STRING_LITERAL,self.data.rest]
253
+ @data.terminate
262
254
  error_unterminated_string
263
255
  end
264
256
  end
@@ -270,18 +262,18 @@ module BibTeX
270
262
  push [:AT,'@']
271
263
 
272
264
  case
273
- when self.src.scan(/string/io)
265
+ when @data.scan(/string/io)
274
266
  self.mode = :string
275
- push [:STRING, self.src.matched]
276
- when self.src.scan(/preamble/io)
267
+ push [:STRING, @data.matched]
268
+ when @data.scan(/preamble/io)
277
269
  self.mode = :preamble
278
- push [:PREAMBLE, self.src.matched]
279
- when self.src.scan(/comment/io)
270
+ push [:PREAMBLE, self.data.matched]
271
+ when @data.scan(/comment/io)
280
272
  self.mode = :comment
281
- push [:COMMENT, self.src.matched]
282
- when self.src.scan(/[a-z\d:_!\.$%&*-]+/io)
273
+ push [:COMMENT, self.data.matched]
274
+ when @data.scan(/[a-z\d:_!\.$%&*-]+/io)
283
275
  self.mode = :entry
284
- push [:NAME, self.src.matched]
276
+ push [:NAME, @data.matched]
285
277
  end
286
278
  end
287
279
 
@@ -293,27 +285,27 @@ module BibTeX
293
285
 
294
286
 
295
287
  def error_unbalanced_braces
296
- n = line_number_at(self.src.pos)
288
+ n = line_number_at(@data.pos)
297
289
  Log.warn("Lexer: unbalanced braces on line #{n}; brace level #{@brace_level}; mode #{@mode.inspect}.")
298
- backtrace [:E_UNBALANCED_BRACES, [self.src.matched,n]]
290
+ backtrace [:E_UNBALANCED_BRACES, [self.data.matched,n]]
299
291
  end
300
292
 
301
293
  def error_unterminated_string
302
- n = line_number_at(self.src.pos)
294
+ n = line_number_at(@data.pos)
303
295
  Log.warn("Lexer: unterminated string on line #{n}; brace level #{@brace_level}; mode #{@mode.inspect}.")
304
- backtrace [:E_UNTERMINATED_STRING, [self.src.matched,n]]
296
+ backtrace [:E_UNTERMINATED_STRING, [@data.matched,n]]
305
297
  end
306
298
 
307
299
  def error_unterminated_content
308
- n = line_number_at(self.src.pos)
300
+ n = line_number_at(@data.pos)
309
301
  Log.warn("Lexer: unterminated content on line #{n}; brace level #{@brace_level}; mode #{@mode.inspect}.")
310
- backtrace [:E_UNTERMINATED_CONTENT, [self.src.matched,n]]
302
+ backtrace [:E_UNTERMINATED_CONTENT, [@data.matched,n]]
311
303
  end
312
304
 
313
305
  def error_unexpected_token
314
- n = line_number_at(self.src.pos)
315
- Log.warn("Lexer: unexpected token `#{self.src.matched}' on line #{n}; brace level #{@brace_level}; mode #{@mode.inspect}.")
316
- backtrace [:E_UNEXPECTED_TOKEN, [self.src.matched,n]]
306
+ n = line_number_at(@data.pos)
307
+ Log.warn("Lexer: unexpected token `#{@data.matched}' on line #{n}; brace level #{@brace_level}; mode #{@mode.inspect}.")
308
+ backtrace [:E_UNEXPECTED_TOKEN, [@data.matched,n]]
317
309
  end
318
310
 
319
311
  def backtrace(error)
data/lib/bibtex/parser.rb CHANGED
@@ -27,7 +27,7 @@ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 90)
27
27
  def parse(input)
28
28
  @yydebug = debug?
29
29
 
30
- @lexer.src = input
30
+ @lexer.data = input
31
31
  @lexer.analyse
32
32
 
33
33
  do_parse
@@ -18,6 +18,6 @@
18
18
 
19
19
  module BibTeX
20
20
  module Version
21
- STRING = '1.3.3'.freeze
21
+ STRING = '1.3.4'.freeze
22
22
  end
23
23
  end
data/test/benchmark.rb CHANGED
@@ -1,52 +1,79 @@
1
1
  require File.expand_path('../../lib/bibtex.rb', __FILE__)
2
- require 'profile'
3
-
4
- module BibTeX
5
- module Benchmark
6
- def self.open
7
- BibTeX.parse <<-END
8
- @book{rails,
9
- Address = {Raleigh, North Carolina},
10
- Author = {Ruby, Sam, and Thomas, Dave, and Hansson Heinemeier, David},
11
- Booktitle = {Agile Web Development with Rails},
12
- Date-Added = {2010-08-05 10:01:36 +0200},
13
- Date-Modified = {2010-08-05 10:06:46 +0200},
14
- Edition = {third},
15
- Isbn = {978-1-9343561-6-6},
16
- Keywords = {ruby, rails},
17
- Publisher = {The Pragmatic Bookshelf},
18
- Series = {The Facets of Ruby},
19
- Title = {Agile Web Development with Rails},
20
- Year = {2009}
21
- }
22
-
23
- @book{dragon,
24
- Address = {Boston},
25
- Author = {Aho, Alfred V., and Lam, Monica S., and Ullman, Jeffrey D.},
26
- Booktitle = {Compilers: Principles, Techniques, and Tools},
27
- Date-Added = {2010-08-05 09:57:15 +0200},
28
- Date-Modified = {2010-08-05 10:06:32 +0200},
29
- Edition = {second},
30
- Keywords = {compiler, lex, yacc},
31
- Publisher = {Addison Wesley},
32
- Title = {Compilers: Principles, Techniques, and Tools},
33
- Year = {2007}
34
- }
35
-
36
- @book{pickaxe,
37
- Address = {Raleigh, North Carolina},
38
- Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
39
- Date-Added = {2010-08-05 09:54:07 +0200},
40
- Date-Modified = {2010-08-05 10:07:01 +0200},
41
- Keywords = {ruby},
42
- Publisher = {The Pragmatic Bookshelf},
43
- Series = {The Facets of Ruby},
44
- Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
45
- Year = {2009}
46
- }
47
- END
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'benchmark'
7
+ include Benchmark
8
+
9
+ # data = File.open(BibTeX::Test.fixtures(:benchmark)).read
10
+
11
+ input = <<-END
12
+ @book{pickaxe,
13
+ Address = {Raleigh, North Carolina},
14
+ Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
15
+ Date-Added = {2010-08-05 09:54:07 +0200},
16
+ Date-Modified = {2010-08-05 10:07:01 +0200},
17
+ Keywords = {ruby},
18
+ Publisher = {The Pragmatic Bookshelf},
19
+ Series = {The Facets of Ruby},
20
+ Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
21
+ Year = {2009}
22
+ }
23
+ END
24
+
25
+ n, k = 1001, 20
26
+ lexer = BibTeX::Lexer.new
27
+
28
+ f = []
29
+ g = []
30
+
31
+ Benchmark.benchmark((" "*15) + CAPTION, 7, FMTSTR, '%14s:' % 'sum(f)', '%14s:' % 'sum(g)') do |b|
32
+
33
+ 1.step(n,k) do |i|
34
+
35
+ f << b.report('%14s:' % "f(#{i})") do
36
+ i.times do
37
+ lexer.data = input
38
+ lexer.analyse
39
+ end
40
+ end
41
+
42
+ data = input * i
43
+
44
+ g << b.report('%14s:' % "g(#{i})") do
45
+ lexer.data = data
46
+ lexer.analyse
48
47
  end
48
+
49
49
  end
50
+
51
+ [f.inject(:+), g.inject(:+)]
50
52
  end
51
53
 
52
- BibTeX::Benchmark.open
54
+ require 'gnuplot'
55
+
56
+ f = f.map(&:total)
57
+ g = g.map(&:total)
58
+
59
+ x = 1.step(n,k).to_a
60
+
61
+ Gnuplot.open do |gp|
62
+ Gnuplot::Plot.new(gp) do |plot|
63
+
64
+ plot.title 'BibTeX-Ruby Benchmark'
65
+ plot.ylabel 't'
66
+ plot.xlabel 'n'
67
+
68
+ plot.data << Gnuplot::DataSet.new([x,f]) do |ds|
69
+ ds.with = 'linespoints'
70
+ ds.title = 'f'
71
+ end
72
+
73
+ plot.data << Gnuplot::DataSet.new([x,g]) do |ds|
74
+ ds.with = 'linespoints'
75
+ ds.title = 'g'
76
+ end
77
+
78
+ end
79
+ end
File without changes
data/test/profile.dot ADDED
@@ -0,0 +1,130 @@
1
+ digraph "Profile" {
2
+ label="PROCESS_TIME >=5%\nTotal: 2.810879";
3
+ labelloc=t;
4
+ labeljust=l;
5
+ subgraph "Thread 2151955260" {
6
+ 2157659280 [label="parse_names\n(9%)"];
7
+ 2157659280 -> 2157643080 [label="50/3353" fontsize=10 fontcolor="#666666"];
8
+ 2157659200 [label="call\n(9%)"];
9
+ 2157659200 -> 2157659280 [label="50/50" fontsize=10 fontcolor="#666666"];
10
+ 2157656740 [label="matches?\n(7%)"];
11
+ 2157656220 [label="each\n(9%)"];
12
+ 2157656220 -> 2157643080 [label="52/3353" fontsize=10 fontcolor="#666666"];
13
+ 2157655660 [label="select\n(9%)"];
14
+ 2157655660 -> 2157656220 [label="52/52" fontsize=10 fontcolor="#666666"];
15
+ 2157652320 [label="query\n(9%)"];
16
+ 2157652320 -> 2157655660 [label="52/52" fontsize=10 fontcolor="#666666"];
17
+ 2157651980 [label="parse_names\n(9%)"];
18
+ 2157651980 -> 2157652320 [label="1/52" fontsize=10 fontcolor="#666666"];
19
+ 2157643080 [label="each\n(10%)"];
20
+ 2157643080 -> 2157659200 [label="100/100" fontsize=10 fontcolor="#666666"];
21
+ 2157643080 -> 2157656740 [label="2600/2600" fontsize=10 fontcolor="#666666"];
22
+ 2157643080 -> 2157652320 [label="50/52" fontsize=10 fontcolor="#666666"];
23
+ 2157634620 [label="parse_content\n(25%)"];
24
+ 2157634620 -> 2157625160 [label="900/3002" fontsize=10 fontcolor="#666666"];
25
+ 2157634260 [label="parse_bibtex\n(55%)"];
26
+ 2157634260 -> 2157625160 [label="1950/3002" fontsize=10 fontcolor="#666666"];
27
+ 2157626660 [label="find_index\n(75%)"];
28
+ 2157626440 [label="line_number_at\n(75%)"];
29
+ 2157626440 -> 2157626660 [label="2951/2951" fontsize=10 fontcolor="#666666"];
30
+ 2157625160 [label="push\n(78%)"];
31
+ 2157625160 -> 2157626440 [label="2951/2951" fontsize=10 fontcolor="#666666"];
32
+ 2157618760 [label="analyse\n(86%)"];
33
+ 2157618760 -> 2157634260 [label="3350/3350" fontsize=10 fontcolor="#666666"];
34
+ 2157618760 -> 2157634620 [label="450/450" fontsize=10 fontcolor="#666666"];
35
+ 2157618760 -> 2157625160 [label="1/3002" fontsize=10 fontcolor="#666666"];
36
+ 2157616120 [label="parse\n(90%)"];
37
+ 2157616120 -> 2157618760 [label="1/1" fontsize=10 fontcolor="#666666"];
38
+ 2157613960 [label="parse\n(100%)"];
39
+ 2157613960 -> 2157616120 [label="1/1" fontsize=10 fontcolor="#666666"];
40
+ 2157613960 -> 2157651980 [label="1/1" fontsize=10 fontcolor="#666666"];
41
+ 2157613840 [label="parse\n(100%)"];
42
+ 2157613840 -> 2157613960 [label="1/1" fontsize=10 fontcolor="#666666"];
43
+ 2157613760 [label="[No method]\n(100%)"];
44
+ 2157613760 -> 2157613840 [label="1/1" fontsize=10 fontcolor="#666666"];
45
+ }
46
+ subgraph cluster_2159557740 {
47
+ label = "Global";
48
+ fontcolor = "#666666";
49
+ fontsize = 16;
50
+ color = "#666666";
51
+ 2157613760;
52
+ }
53
+ subgraph cluster_2159558100 {
54
+ label = "<Module::BibTeX>";
55
+ fontcolor = "#666666";
56
+ fontsize = 16;
57
+ color = "#666666";
58
+ 2157613840;
59
+ }
60
+ subgraph cluster_2159572300 {
61
+ label = "<Class::BibTeX::Bibliography>";
62
+ fontcolor = "#666666";
63
+ fontsize = 16;
64
+ color = "#666666";
65
+ 2157613960;
66
+ }
67
+ subgraph cluster_2159574340 {
68
+ label = "BibTeX::Parser";
69
+ fontcolor = "#666666";
70
+ fontsize = 16;
71
+ color = "#666666";
72
+ 2157616120;
73
+ }
74
+ subgraph cluster_2159578300 {
75
+ label = "BibTeX::Lexer";
76
+ fontcolor = "#666666";
77
+ fontsize = 16;
78
+ color = "#666666";
79
+ 2157618760;
80
+ 2157625160;
81
+ 2157626440;
82
+ 2157634260;
83
+ 2157634620;
84
+ }
85
+ subgraph cluster_2159613500 {
86
+ label = "Array";
87
+ fontcolor = "#666666";
88
+ fontsize = 16;
89
+ color = "#666666";
90
+ 2157626660;
91
+ 2157643080;
92
+ }
93
+ subgraph cluster_2159621220 {
94
+ label = "BibTeX::Entry";
95
+ fontcolor = "#666666";
96
+ fontsize = 16;
97
+ color = "#666666";
98
+ 2157659280;
99
+ }
100
+ subgraph cluster_2159625420 {
101
+ label = "BibTeX::Bibliography";
102
+ fontcolor = "#666666";
103
+ fontsize = 16;
104
+ color = "#666666";
105
+ 2157651980;
106
+ 2157652320;
107
+ 2157656220;
108
+ }
109
+ subgraph cluster_2159645280 {
110
+ label = "BibTeX::Element";
111
+ fontcolor = "#666666";
112
+ fontsize = 16;
113
+ color = "#666666";
114
+ 2157656740;
115
+ }
116
+ subgraph cluster_2159651300 {
117
+ label = "Enumerable";
118
+ fontcolor = "#666666";
119
+ fontsize = 16;
120
+ color = "#666666";
121
+ 2157655660;
122
+ }
123
+ subgraph cluster_2159654320 {
124
+ label = "Proc";
125
+ fontcolor = "#666666";
126
+ fontsize = 16;
127
+ color = "#666666";
128
+ 2157659200;
129
+ }
130
+ }
data/test/profile.rb ADDED
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../lib/bibtex.rb', __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'ruby-prof'
7
+
8
+ data = <<-END
9
+ @book{pickaxe,
10
+ Address = {Raleigh, North Carolina},
11
+ Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
12
+ Date-Added = {2010-08-05 09:54:07 +0200},
13
+ Date-Modified = {2010-08-05 10:07:01 +0200},
14
+ Keywords = {ruby},
15
+ Publisher = {The Pragmatic Bookshelf},
16
+ Series = {The Facets of Ruby},
17
+ Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
18
+ Year = {2009}
19
+ }
20
+ END
21
+
22
+ data = data * 50
23
+
24
+ result = RubyProf.profile do
25
+ BibTeX.parse(data)
26
+ end
27
+
28
+ printer = RubyProf::DotPrinter.new(result)
29
+ printer.print(File.open(File.expand_path('../profile.dot', __FILE__), 'w'), :min_percent => 5)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bibtex-ruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.3
5
+ version: 1.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sylvester Keil
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-06 00:00:00 +02:00
13
+ date: 2011-06-07 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,28 @@ dependencies:
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: ruby-prof
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0.10"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: gnuplot
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "2.3"
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
93
115
  description: A (fairly complete) BibTeX library and parser written in Ruby. Includes a name parser and supports regular BibTeX entries, @comments, string replacement via @string. Allows for easy export/conversion to formats such as YAML, JSON, and XML.
94
116
  email: http://sylvester.keil.or.at
95
117
  executables: []
@@ -99,7 +121,6 @@ extensions: []
99
121
  extra_rdoc_files:
100
122
  - README.md
101
123
  files:
102
- - Bibliography.bib
103
124
  - Gemfile
104
125
  - Gemfile.lock
105
126
  - History.txt
@@ -152,6 +173,7 @@ files:
152
173
  - test/bibtex/test_string.rb
153
174
  - test/bibtex/test_utilities.rb
154
175
  - test/bibtex/test_value.rb
176
+ - test/fixtures/benchmark.bib
155
177
  - test/fixtures/bibdesk.bib
156
178
  - test/fixtures/comment.bib
157
179
  - test/fixtures/decoret.bib
@@ -162,6 +184,8 @@ files:
162
184
  - test/fixtures/preamble.bib
163
185
  - test/fixtures/roundtrip.bib
164
186
  - test/helper.rb
187
+ - test/profile.dot
188
+ - test/profile.rb
165
189
  - test/test_bibtex.rb
166
190
  - test/test_export.rb
167
191
  has_rdoc: true
@@ -185,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
209
  requirements:
186
210
  - - ">="
187
211
  - !ruby/object:Gem::Version
188
- hash: 3560654511728718454
212
+ hash: 1653592792088481803
189
213
  segments:
190
214
  - 0
191
215
  version: "0"