Class: TheMechanic2::BenchmarkResult
- Inherits:
-
Object
- Object
- TheMechanic2::BenchmarkResult
- Defined in:
- lib/the_mechanic_2/benchmark_result.rb
Overview
Model for formatting and exporting benchmark results Provides JSON and Markdown export capabilities
Instance Attribute Summary collapse
-
#code_a_metrics ⇒ Object
readonly
Returns the value of attribute code_a_metrics.
-
#code_b_metrics ⇒ Object
readonly
Returns the value of attribute code_b_metrics.
-
#performance_ratio ⇒ Object
readonly
Returns the value of attribute performance_ratio.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#winner ⇒ Object
readonly
Returns the value of attribute winner.
Instance Method Summary collapse
-
#initialize(data) ⇒ BenchmarkResult
constructor
A new instance of BenchmarkResult.
-
#to_h ⇒ Hash
Returns a hash representation of the results.
-
#to_json(*_args) ⇒ String
Exports results as JSON.
-
#to_markdown ⇒ String
Exports results as Markdown.
Constructor Details
#initialize(data) ⇒ BenchmarkResult
Returns a new instance of BenchmarkResult.
9 10 11 12 13 14 15 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 9 def initialize(data) @code_a_metrics = data[:code_a_metrics] @code_b_metrics = data[:code_b_metrics] @winner = data[:winner] @performance_ratio = data[:performance_ratio] @summary = data[:summary] end |
Instance Attribute Details
#code_a_metrics ⇒ Object (readonly)
Returns the value of attribute code_a_metrics.
7 8 9 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 7 def code_a_metrics @code_a_metrics end |
#code_b_metrics ⇒ Object (readonly)
Returns the value of attribute code_b_metrics.
7 8 9 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 7 def code_b_metrics @code_b_metrics end |
#performance_ratio ⇒ Object (readonly)
Returns the value of attribute performance_ratio.
7 8 9 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 7 def performance_ratio @performance_ratio end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
7 8 9 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 7 def summary @summary end |
#winner ⇒ Object (readonly)
Returns the value of attribute winner.
7 8 9 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 7 def winner @winner end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the results
62 63 64 65 66 67 68 69 70 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 62 def to_h { code_a_metrics: @code_a_metrics, code_b_metrics: @code_b_metrics, winner: @winner, performance_ratio: @performance_ratio, summary: @summary } end |
#to_json(*_args) ⇒ String
Exports results as JSON
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 19 def to_json(*_args) { code_a_metrics: @code_a_metrics, code_b_metrics: @code_b_metrics, winner: @winner, performance_ratio: @performance_ratio, summary: @summary, timestamp: Time.now.iso8601 }.to_json end |
#to_markdown ⇒ String
Exports results as Markdown
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/the_mechanic_2/benchmark_result.rb', line 32 def to_markdown " # Ruby Benchmark Results\n \n **Winner:** \#{winner_text}\n \n **Summary:** \#{@summary}\n \n ## Performance Metrics\n \n | Metric | Code A | Code B |\n |--------|--------|--------|\n | IPS (iterations/sec) | \#{format_number(@code_a_metrics[:ips])} | \#{format_number(@code_b_metrics[:ips])} |\n | Standard Deviation | \#{format_number(@code_a_metrics[:stddev])} | \#{format_number(@code_b_metrics[:stddev])} |\n | Objects Allocated | \#{format_number(@code_a_metrics[:objects])} | \#{format_number(@code_b_metrics[:objects])} |\n | Memory (MB) | \#{format_number(@code_a_metrics[:memory_mb])} | \#{format_number(@code_b_metrics[:memory_mb])} |\n | Execution Time (sec) | \#{format_number(@code_a_metrics[:execution_time])} | \#{format_number(@code_b_metrics[:execution_time])} |\n \n ## Analysis\n \n \#{analysis_text}\n \n ---\n \n *Generated at \#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}*\n MARKDOWN\nend\n" |