Class: Serialbench::BenchmarkRunner
- Inherits:
-
Object
- Object
- Serialbench::BenchmarkRunner
- Defined in:
- lib/serialbench/benchmark_runner.rb
Constant Summary collapse
- OPERATIONS =
Each operation maps to a lambda. Adding an operation = one entry.
{ 'parsing' => ->(s, data) { s.parse(data) }, 'generation' => ->(s, data) { s.generate(s.parse(data)) }, 'xpath' => lambda { |s, data| doc = s.parse(data) s.xpath_query(doc, '//book') s.xpath_query(doc, "//book[@id='101']") s.xpath_query(doc, '//book[price > 30]/title') }, '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
Returns a new instance of BenchmarkRunner.
18 19 20 21 22 23 24 25 |
# 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 = [] 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/serialbench/benchmark_runner.rb', line 40 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 results = {} OPERATIONS.each do |name, handler| results[name.to_sym] = run_benchmark_type(name, name, &handler) end results[:memory] = run_memory_benchmarks Models::BenchmarkResult.new( serializers: Serializers.information, **results ) end |
#run_memory_benchmarks ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/serialbench/benchmark_runner.rb', line 60 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 report = ::MemoryProfiler.report do 10.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 |