Class: TheMechanic2::BenchmarkService

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

Overview

Service for orchestrating benchmark execution Coordinates between RailsRunnerService and result formatting

Instance Method Summary collapse

Instance Method Details

#run(shared_setup:, code_a:, code_b:, timeout: 30) ⇒ Hash

Executes a benchmark comparison between two code snippets

Parameters:

  • shared_setup (String)

    Optional setup code to run before both snippets

  • code_a (String)

    First code snippet to benchmark

  • code_b (String)

    Second code snippet to benchmark

  • timeout (Integer) (defaults to: 30)

    Maximum execution time per benchmark in seconds

Returns:

  • (Hash)

    Formatted benchmark results with winner and metrics



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/the_mechanic_2/benchmark_service.rb', line 13

def run(shared_setup:, code_a:, code_b:, timeout: 30)
  runner = RailsRunnerService.new
  
  # Execute code_a
  result_a = runner.execute(
    code: code_a,
    shared_setup: shared_setup,
    timeout: timeout
  )
  
  # Execute code_b
  result_b = runner.execute(
    code: code_b,
    shared_setup: shared_setup,
    timeout: timeout
  )
  
  # Format and return results
  format_results(result_a, result_b)
end