Class: Serialbench::BenchmarkRunner
- Inherits:
-
Object
- Object
- Serialbench::BenchmarkRunner
- Defined in:
- lib/serialbench/benchmark_runner.rb
Constant Summary collapse
- XPATH_QUERIES =
['//book', "//book[@id='101']", '//book[price > 30]/title'].freeze
- XQUERY_EXPRESSIONS =
['count(//user | //record)', "//record[@id='101']/data/field1", '//user[profile/age > 40]/name'].freeze
- RNG_SCHEMA =
File.('test_data/schema.rng', Dir.pwd).then { |p| File.exist?(p) ? File.read(p) : _DEFAULT_RNG_SCHEMA }
- XSLT_STYLESHEET =
File.('test_data/transform.xsl', Dir.pwd).then { |p| File.exist?(p) ? File.read(p) : _DEFAULT_XSLT_STYLESHEET }
- XSLT30_STYLESHEET =
File.('test_data/transform30.xsl', Dir.pwd).then { |p| File.exist?(p) ? File.read(p) : _DEFAULT_XSLT30_STYLESHEET }
- OPERATIONS =
{ 'parsing' => ->(s, data) { s.parse(data) }, 'generation' => ->(s, data) { s.generate(s.parse(data)) }, 'xpath' => lambda { |s, data| doc = s.parse(data) XPATH_QUERIES.each { |q| s.xpath_query(doc, q) } }, 'xquery' => lambda { |s, data| doc = s.parse(data) XQUERY_EXPRESSIONS.each { |x| s.xquery_eval(doc, x) } }, 'xslt' => ->(s, data) { s.xslt_apply(data, XSLT_STYLESHEET) }, 'xslt30' => ->(s, data) { s.xslt_apply(data, XSLT30_STYLESHEET) }, 'validation' => ->(s, data) { s.validate(s.parse(data), RNG_SCHEMA) }, 'streaming' => ->(s, data) { s.stream_parse(data) { |_event, _data| } }, }.freeze
Instance Attribute Summary collapse
-
#benchmark_config ⇒ Object
readonly
Returns the value of attribute benchmark_config.
-
#environment_config ⇒ Object
readonly
Returns the value of attribute environment_config.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#serializers ⇒ Object
readonly
Returns the value of attribute serializers.
-
#test_data ⇒ Object
readonly
Returns the value of attribute test_data.
Instance Method Summary collapse
-
#initialize(benchmark_config:, environment_config:) ⇒ BenchmarkRunner
constructor
A new instance of BenchmarkRunner.
- #run_all_benchmarks ⇒ Object
- #run_memory_benchmarks ⇒ Object
Constructor Details
#initialize(benchmark_config:, environment_config:) ⇒ BenchmarkRunner
18 19 20 21 22 23 24 25 26 |
# File 'lib/serialbench/benchmark_runner.rb', line 18 def initialize(benchmark_config:, environment_config:) @environment_config = environment_config @benchmark_config = benchmark_config @serializers = Serializers.available @test_data = {} @results = [] validate_operations! load_test_data end |
Instance Attribute Details
#benchmark_config ⇒ Object (readonly)
Returns the value of attribute benchmark_config.
16 17 18 |
# File 'lib/serialbench/benchmark_runner.rb', line 16 def benchmark_config @benchmark_config end |
#environment_config ⇒ Object (readonly)
Returns the value of attribute environment_config.
16 17 18 |
# File 'lib/serialbench/benchmark_runner.rb', line 16 def environment_config @environment_config end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
16 17 18 |
# File 'lib/serialbench/benchmark_runner.rb', line 16 def results @results end |
#serializers ⇒ Object (readonly)
Returns the value of attribute serializers.
16 17 18 |
# File 'lib/serialbench/benchmark_runner.rb', line 16 def serializers @serializers end |
#test_data ⇒ Object (readonly)
Returns the value of attribute test_data.
16 17 18 |
# File 'lib/serialbench/benchmark_runner.rb', line 16 def test_data @test_data end |
Instance Method Details
#run_all_benchmarks ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/serialbench/benchmark_runner.rb', line 196 def run_all_benchmarks puts 'Serialbench - Running comprehensive serialization performance tests' puts '=' * 70 puts "Available serializers: #{@serializers.map(&:name).join(', ')}" puts "Test formats: #{@benchmark_config.formats.join(', ')}" puts "Test data sizes: #{@test_data.keys.join(', ')}" puts selected = @benchmark_config.operations selected = OPERATIONS.keys + ['memory'] if selected.nil? || selected.empty? results = {} OPERATIONS.each do |name, handler| results[name.to_sym] = selected.include?(name) ? run_benchmark_type(name, name, &handler) : [] end results[:memory] = selected.include?('memory') ? run_memory_benchmarks : [] Models::BenchmarkResult.new( serializers: Serializers.information, **results ) end |
#run_memory_benchmarks ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/serialbench/benchmark_runner.rb', line 218 def run_memory_benchmarks puts "\nRunning memory usage benchmarks..." return [] unless defined?(::MemoryProfiler) run_benchmark_iteration('memory') do |serializer, format, size, data| # Memory profiling for parsing. MemoryProfiler disables GC while # reporting, so every profiled parse accumulates: ten large-document # trees exhaust the 16GB windows runners. One parse fully captures # a large document's allocation and retention profile. report = ::MemoryProfiler.report do profile_iterations(size).times { serializer.parse(data) } end result = Models::MemoryPerformance.new( adapter: serializer.name, format: format, data_size: size, total_allocated: report.total_allocated, total_retained: report.total_retained, allocated_memory: report.total_allocated_memsize, retained_memory: report.total_retained_memsize ) puts " #{format}/#{serializer.name}: #{(report.total_allocated_memsize / 1024.0 / 1024.0).round(2)}MB allocated" result end end |