Class: TRuby::BenchmarkSuite
- Inherits:
-
Object
- Object
- TRuby::BenchmarkSuite
- Defined in:
- lib/t_ruby/benchmark.rb
Overview
Benchmark suite for T-Ruby performance measurement
Constant Summary collapse
- BENCHMARK_CATEGORIES =
%i[ parsing type_checking compilation incremental parallel memory ].freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#compare(previous_path) ⇒ Object
Compare with previous results.
-
#export_json(path = "benchmark_results.json") ⇒ Object
Export results to JSON.
-
#export_markdown(path = "benchmark_results.md") ⇒ Object
Export results to Markdown.
-
#initialize(config = nil) ⇒ BenchmarkSuite
constructor
A new instance of BenchmarkSuite.
-
#run_all(iterations: 5, warmup: 2) ⇒ Object
Run all benchmarks.
-
#run_category(category, iterations: 5, warmup: 2) ⇒ Object
Run specific category.
Constructor Details
#initialize(config = nil) ⇒ BenchmarkSuite
Returns a new instance of BenchmarkSuite.
21 22 23 24 25 26 |
# File 'lib/t_ruby/benchmark.rb', line 21 def initialize(config = nil) @config = config || Config.new @results = {} @compiler = nil @type_checker = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/t_ruby/benchmark.rb', line 10 def config @config end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
10 11 12 |
# File 'lib/t_ruby/benchmark.rb', line 10 def results @results end |
Instance Method Details
#compare(previous_path) ⇒ Object
Compare with previous results
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/t_ruby/benchmark.rb', line 99 def compare(previous_path) return nil unless File.exist?(previous_path) previous = JSON.parse(File.read(previous_path), symbolize_names: true) comparison = {} @results.each do |category, benchmarks| prev_cat = previous[:results][category] next unless prev_cat comparison[category] = {} benchmarks.each do |name, data| prev_data = prev_cat[name] next unless prev_data diff = ((data[:avg_time] - prev_data[:avg_time]) / prev_data[:avg_time] * 100).round(2) comparison[category][name] = { current: data[:avg_time], previous: prev_data[:avg_time], diff_percent: diff, improved: diff < 0 } end end comparison end |
#export_json(path = "benchmark_results.json") ⇒ Object
Export results to JSON
61 62 63 64 65 66 67 68 |
# File 'lib/t_ruby/benchmark.rb', line 61 def export_json(path = "benchmark_results.json") File.write(path, JSON.pretty_generate({ timestamp: Time.now.iso8601, ruby_version: RUBY_VERSION, platform: RUBY_PLATFORM, results: @results })) end |
#export_markdown(path = "benchmark_results.md") ⇒ Object
Export results to Markdown
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/t_ruby/benchmark.rb', line 71 def export_markdown(path = "benchmark_results.md") md = [] md << "# T-Ruby Benchmark Results" md << "" md << "**Generated:** #{Time.now}" md << "**Ruby Version:** #{RUBY_VERSION}" md << "**Platform:** #{RUBY_PLATFORM}" md << "" @results.each do |category, benchmarks| md << "## #{category.to_s.capitalize}" md << "" md << "| Benchmark | Time (ms) | Memory (KB) | Iterations/sec |" md << "|-----------|-----------|-------------|----------------|" benchmarks.each do |name, data| time_ms = (data[:avg_time] * 1000).round(2) memory_kb = (data[:memory] || 0).round(2) ips = data[:avg_time] > 0 ? (1.0 / data[:avg_time]).round(2) : 0 md << "| #{name} | #{time_ms} | #{memory_kb} | #{ips} |" end md << "" end File.write(path, md.join("\n")) end |
#run_all(iterations: 5, warmup: 2) ⇒ Object
Run all benchmarks
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/t_ruby/benchmark.rb', line 29 def run_all(iterations: 5, warmup: 2) puts "T-Ruby Benchmark Suite" puts "=" * 60 puts "Iterations: #{iterations}, Warmup: #{warmup}" puts BENCHMARK_CATEGORIES.each do |category| run_category(category, iterations: iterations, warmup: warmup) end print_summary @results end |
#run_category(category, iterations: 5, warmup: 2) ⇒ Object
Run specific category
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/t_ruby/benchmark.rb', line 44 def run_category(category, iterations: 5, warmup: 2) puts "Running #{category} benchmarks..." puts "-" * 40 @results[category] = case category when :parsing then benchmark_parsing(iterations, warmup) when :type_checking then benchmark_type_checking(iterations, warmup) when :compilation then benchmark_compilation(iterations, warmup) when :incremental then benchmark_incremental(iterations, warmup) when :parallel then benchmark_parallel(iterations, warmup) when :memory then benchmark_memory end puts end |