Class: Benchkit::BenchmarkScript

Inherits:
Object
  • Object
show all
Defined in:
lib/benchkit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, prelude: '', loop_count: nil, benchmark:) ⇒ BenchmarkScript

Returns a new instance of BenchmarkScript.

Parameters:

  • name (String)
  • prelude (String) (defaults to: '')
  • benchmark (String)


119
120
121
122
123
124
# File 'lib/benchkit.rb', line 119

def initialize(name:, prelude: '', loop_count: nil, benchmark:)
  @name = name
  @prelude = prelude
  @loop_count = loop_count
  @benchmark = benchmark
end

Instance Attribute Details

#loop_countInteger (readonly)

Returns:

  • (Integer)


130
131
132
# File 'lib/benchkit.rb', line 130

def loop_count
  @loop_count
end

#nameString (readonly)

Returns:

  • (String)


127
128
129
# File 'lib/benchkit.rb', line 127

def name
  @name
end

Instance Method Details

#benchmark_script(iterations) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/benchkit.rb', line 149

def benchmark_script(iterations)
  "\#{@prelude}\ni = 0\nwhile i < \#{iterations}\n  i += 1\n\#{@benchmark}\nend\n  RUBY\nend\n"

#inherit_root(prelude:, loop_count:) ⇒ Object



132
133
134
135
136
137
# File 'lib/benchkit.rb', line 132

def inherit_root(prelude:, loop_count:)
  @prelude = "#{prelude}\n#{@prelude}"
  if @loop_count.nil? && loop_count
    @loop_count = loop_count
  end
end

#overhead_script(iterations) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/benchkit.rb', line 139

def overhead_script(iterations)
  "\#{@prelude}\ni = 0\nwhile i < \#{iterations}\n  i += 1\nend\n  RUBY\nend\n"