Class: Serialbench::Runners::LocalRunner

Inherits:
Base
  • Object
show all
Defined in:
lib/serialbench/runners/local_runner.rb

Overview

Handles local benchmark execution using the current Ruby environment

Instance Method Summary collapse

Methods inherited from Base

#benchmark, #initialize

Constructor Details

This class inherits a constructor from Serialbench::Runners::Base

Instance Method Details

#prepareObject



13
14
15
16
17
# File 'lib/serialbench/runners/local_runner.rb', line 13

def prepare
  # For local environments, no preparation is needed
  # The current Ruby environment is already set up
  puts "✅ Local environment ready (using current Ruby: #{RUBY_VERSION})"
end

#run_benchmark(benchmark_config, benchmark_config_path, result_dir) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
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
59
60
61
62
63
64
65
66
67
68
# File 'lib/serialbench/runners/local_runner.rb', line 19

def run_benchmark(benchmark_config, benchmark_config_path, result_dir)
  puts "🏠 Running benchmark locally with Ruby #{RUBY_VERSION}..."
  puts "   📁 Results will be saved to: #{result_dir}"

  FileUtils.mkdir_p(result_dir)

  # Run the benchmark
  runner = Serialbench::BenchmarkRunner.new(
    environment_config: @environment_config,
    benchmark_config: benchmark_config
  )

  results = runner.run_all_benchmarks

  # Get platform information with correct Ruby version from environment config
  platform = Serialbench::Models::Platform.current_local(
    ruby_version: @environment_config.ruby_build_tag
  )

  # Create metadata
   = Models::.new(
    benchmark_config_path: benchmark_config_path,
    environment_config_path: @environment_config_path,
    tags: [
      'local',
      platform.os,
      platform.arch,
      "ruby-#{@environment_config.ruby_build_tag}"
    ]
  )

  # Save results
  results_model = Models::Result.new(
    platform: platform,
    metadata: ,
    environment_config: @environment_config,
    benchmark_config: benchmark_config,
    benchmark_result: results
  )

  # Restore YAML to use Psych for output, otherwise lutaml-model's to_yaml
  # will have no output (Syck gem overrides YAML constant)
  Object.const_set(:YAML, Psych)

  results_file = File.join(result_dir, 'results.yaml')
  results_model.to_file(results_file)

  puts "✅ Benchmark completed successfully"
  puts "   📊 Results saved to: #{results_file}"
end