@@ -23,47 +23,51 @@ class GraphRenderer
2323 DEFAULT_BOTTOM_MARGIN = 30.0
2424 DEFAULT_LEGEND_MARGIN = 4.0
2525
26- def self . render ( json_path , png_path , title_font_size : 16.0 , legend_font_size : 12.0 , marker_font_size : 10.0 )
27- ruby_descriptions , data , baseline , bench_names = load_benchmark_data ( json_path )
26+ class << self
27+ def render ( json_path , png_path , title_font_size : 16.0 , legend_font_size : 12.0 , marker_font_size : 10.0 )
28+ ruby_descriptions , data , baseline , bench_names = load_benchmark_data ( json_path )
2829
29- graph = Gruff ::Bar . new ( DEFAULT_WIDTH )
30- configure_graph ( graph , ruby_descriptions , bench_names , title_font_size , legend_font_size , marker_font_size )
30+ graph = Gruff ::Bar . new ( DEFAULT_WIDTH )
31+ configure_graph ( graph , ruby_descriptions , bench_names , title_font_size , legend_font_size , marker_font_size )
3132
32- ruby_descriptions . each do |ruby , description |
33- speedups = calculate_speedups ( data , baseline , ruby , bench_names )
34- graph . data "#{ ruby } : #{ description } " , speedups
33+ ruby_descriptions . each do |ruby , description |
34+ speedups = calculate_speedups ( data , baseline , ruby , bench_names )
35+ graph . data "#{ ruby } : #{ description } " , speedups
36+ end
37+ graph . write ( png_path )
38+ png_path
3539 end
36- graph . write ( png_path )
37- png_path
38- end
3940
40- def self . load_benchmark_data ( json_path )
41- json = JSON . load_file ( json_path )
42- ruby_descriptions = json . fetch ( "metadata" )
43- data = json . fetch ( "raw_data" )
44- baseline = ruby_descriptions . first . first
45- bench_names = data . first . last . keys
41+ private
4642
47- [ ruby_descriptions , data , baseline , bench_names ]
48- end
43+ def load_benchmark_data ( json_path )
44+ json = JSON . load_file ( json_path )
45+ ruby_descriptions = json . fetch ( "metadata" )
46+ data = json . fetch ( "raw_data" )
47+ baseline = ruby_descriptions . first . first
48+ bench_names = data . first . last . keys
4949
50- def self . configure_graph ( graph , ruby_descriptions , bench_names , title_font_size , legend_font_size , marker_font_size )
51- graph . title = "Speedup ratio relative to #{ ruby_descriptions . keys . first } "
52- graph . title_font_size = title_font_size
53- graph . theme = THEME
54- graph . labels = bench_names . map . with_index { |bench , index | [ index , bench ] } . to_h
55- graph . show_labels_for_bar_values = true
56- graph . bottom_margin = DEFAULT_BOTTOM_MARGIN
57- graph . legend_margin = DEFAULT_LEGEND_MARGIN
58- graph . legend_font_size = legend_font_size
59- graph . marker_font_size = marker_font_size
60- end
50+ [ ruby_descriptions , data , baseline , bench_names ]
51+ end
6152
62- def self . calculate_speedups ( data , baseline , ruby , bench_names )
63- bench_names . map { |bench |
64- baseline_times = data . fetch ( baseline ) . fetch ( bench ) . fetch ( "bench" )
65- times = data . fetch ( ruby ) . fetch ( bench ) . fetch ( "bench" )
66- Stats . new ( baseline_times ) . mean / Stats . new ( times ) . mean
67- }
53+ def configure_graph ( graph , ruby_descriptions , bench_names , title_font_size , legend_font_size , marker_font_size )
54+ graph . title = "Speedup ratio relative to #{ ruby_descriptions . keys . first } "
55+ graph . title_font_size = title_font_size
56+ graph . theme = THEME
57+ graph . labels = bench_names . map . with_index { |bench , index | [ index , bench ] } . to_h
58+ graph . show_labels_for_bar_values = true
59+ graph . bottom_margin = DEFAULT_BOTTOM_MARGIN
60+ graph . legend_margin = DEFAULT_LEGEND_MARGIN
61+ graph . legend_font_size = legend_font_size
62+ graph . marker_font_size = marker_font_size
63+ end
64+
65+ def calculate_speedups ( data , baseline , ruby , bench_names )
66+ bench_names . map { |bench |
67+ baseline_times = data . fetch ( baseline ) . fetch ( bench ) . fetch ( "bench" )
68+ times = data . fetch ( ruby ) . fetch ( bench ) . fetch ( "bench" )
69+ Stats . new ( baseline_times ) . mean / Stats . new ( times ) . mean
70+ }
71+ end
6872 end
6973end
0 commit comments