Class: Serialbench::BenchmarkRunner
- Inherits:
-
Object
- Object
- Serialbench::BenchmarkRunner
- Defined in:
- lib/serialbench/benchmark_runner.rb
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_generation_benchmarks ⇒ Object
- #run_memory_benchmarks ⇒ Object
- #run_parsing_benchmarks ⇒ Object
- #run_streaming_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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/serialbench/benchmark_runner.rb', line 27 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 Models::BenchmarkResult.new( serializers: Serializers.information, parsing: run_parsing_benchmarks, generation: run_generation_benchmarks, memory: run_memory_benchmarks, streaming: run_streaming_benchmarks ) end |
#run_generation_benchmarks ⇒ Object
50 51 52 53 54 55 |
# File 'lib/serialbench/benchmark_runner.rb', line 50 def run_generation_benchmarks run_benchmark_type('generation', 'generation') do |serializer, data| document = serializer.parse(data) serializer.generate(document) end end |
#run_memory_benchmarks ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/serialbench/benchmark_runner.rb', line 63 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 |
#run_parsing_benchmarks ⇒ Object
44 45 46 47 48 |
# File 'lib/serialbench/benchmark_runner.rb', line 44 def run_parsing_benchmarks run_benchmark_type('parsing', 'parse') do |serializer, data| serializer.parse(data) end end |
#run_streaming_benchmarks ⇒ Object
57 58 59 60 61 |
# File 'lib/serialbench/benchmark_runner.rb', line 57 def run_streaming_benchmarks run_benchmark_type('streaming', 'stream parse') do |serializer, data| serializer.stream_parse(data) { |event, data| } end end |