|
1 | | -:ruby |
2 | | - category_benchmarks = [ |
3 | | - %w[app_answer app_erb app_fib app_mandelbrot app_raise app_tak app_uri app_aobench |
4 | | - app_factorial app_lc_fizzbuzz app_pentomino app_strconcat app_tarai], |
5 | | - %w[array_sample_100k__1k array_small_and array_values_at_int |
6 | | - array_sample_100k__100 array_sample_100k___50k array_small_diff |
7 | | - array_values_at_range array_sample_100k___10k array_sample_100k__6k |
8 | | - array_small_or array_sample_100k_10 array_sort_block |
9 | | - array_sample_100k_11 array_shift array_sort_float], |
10 | | - %w[complex_float_add complex_float_div complex_float_mul complex_float_new complex_float_power complex_float_sub], |
11 | | - %w[enum_lazy_grep_v_100 enum_lazy_grep_v_20 enum_lazy_grep_v_50 enum_lazy_uniq_100 enum_lazy_uniq_20 enum_lazy_uniq_50], |
12 | | - %w[hash_aref_array hash_aref_dsym_long hash_aref_dsym hash_aref_fix hash_aref_flo hash_aref_miss hash_aref_str |
13 | | - hash_aref_sym_long hash_aref_sym hash_flatten hash_ident_flo hash_ident_num |
14 | | - hash_ident_obj hash_ident_str hash_ident_sym hash_keys hash_literal_small2 hash_literal_small4 hash_literal_small8 |
15 | | - hash_long hash_shift hash_shift_u16 hash_shift_u24 hash_shift_u32 hash_small2 hash_small4 hash_small8 hash_to_proc hash_values], |
16 | | - %w[io_copy_stream_write io_copy_stream_write_socket io_file_create io_file_read io_file_write io_nonblock_noex2 |
17 | | - io_nonblock_noex io_pipe_rw io_select2 io_select3 io_select io_write], |
18 | | - %w[loop_for loop_generator loop_times loop_whileloop2 loop_whileloop], |
19 | | - %w[so_ackermann so_array so_binary_trees so_concatenate so_count_words so_exception so_fannkuch so_fasta |
20 | | - so_k_nucleotide so_lists so_mandelbrot so_matrix so_meteor_contest so_nbody so_nested_loop so_nsieve_bits |
21 | | - so_nsieve so_object so_partial_sums so_pidigits so_random so_reverse_complement so_sieve so_spectralnorm], |
22 | | - %w[vm_array vm_attr_ivar_set vm_attr_ivar vm_backtrace vm_bigarray vm_bighash vm_blockparam_call vm_blockparam_pass |
23 | | - vm_blockparam_yield vm_blockparam vm_block vm_case_classes vm_case_lit vm_case vm_clearmethodcache vm_const vm_cvar vm_defined_method |
24 | | - vm_dstr_ary vm_dstr_bool vm_dstr_class_module vm_dstr_digit vm_dstr_int vm_dstr_nil vm_dstr_obj_def vm_dstr_obj vm_dstr_str |
25 | | - vm_dstr_sym vm_dstr vm_ensure vm_eval vm_fiber_allocate vm_fiber_count vm_fiber_reuse_gc vm_fiber_reuse vm_fiber_switch vm_float_simple |
26 | | - vm_freezestring vm_gc_old_full vm_gc_old_immediate vm_gc_old_lazy vm_gc vm_gc_short_lived vm_gc_short_with_complex_long |
27 | | - vm_gc_short_with_long vm_gc_short_with_symbol vm_gc_wb_ary_promoted vm_gc_wb_ary vm_gc_wb_obj_promoted vm_gc_wb_obj vm_iclass_super |
28 | | - vm_ivar_embedded_obj_init vm_ivar_extended_obj_init vm_ivar_generic_get vm_ivar_generic_set vm_ivar_get |
29 | | - vm_ivar_lazy_set vm_ivar_of_class_set vm_ivar_of_class vm_ivar_set_on_instance vm_ivar_set vm_ivar vm_length |
30 | | - vm_lvar_cond_set vm_lvar_init vm_lvar_set vm_method_missing vm_method_with_block vm_method vm_module_ann_const_set vm_module_const_set |
31 | | - vm_mutex vm_neq vm_newlambda vm_not vm_poly_method_ov vm_poly_method vm_poly_same_method vm_poly_singleton vm_proc vm_raise1 |
32 | | - vm_raise2 vm_regexp vm_rescue vm_send_cfunc vm_send vm_simplereturn vm_string_literal vm_struct_big_aref_hi vm_struct_big_aref_lo |
33 | | - vm_struct_big_aset vm_struct_big_href_hi vm_struct_big_href_lo vm_struct_big_hset vm_struct_small_aref vm_struct_small_aset |
34 | | - vm_struct_small_href vm_struct_small_hset vm_super vm_swap vm_symbol_block_pass vm_thread_alive_check vm_thread_close |
35 | | - vm_thread_condvar1 vm_thread_condvar2 vm_thread_create_join vm_thread_mutex1 vm_thread_mutex2 vm_thread_mutex3 vm_thread_pass_flood |
36 | | - vm_thread_pass vm_thread_pipe vm_thread_queue vm_thread_sized_queue2 vm_thread_sized_queue3 vm_thread_sized_queue4 |
37 | | - vm_thread_sized_queue vm_thread_sleep vm_unif1 vm_yield vm_zsuper], |
38 | | - ] |
| 1 | +- category_benchmarks = ruby_core_benchmarks |
39 | 2 | .benchmark_page |
40 | 3 | .text-center |
41 | 4 | %h1 ruby/ruby |
|
44 | 7 |
|
45 | 8 | #graph_metadata{ 'data-unit': 'i/s', 'data-type': 'line' } |
46 | 9 |
|
| 10 | + %div |
| 11 | + .category_switcher |
| 12 | + - category_benchmarks.each_key do |category| |
| 13 | + %button.category_switch{ type: 'button', 'data-category': category.downcase }= category |
| 14 | + |
47 | 15 | %ul.nav.nav-pills.benchmark_navbar |
48 | | - - category_benchmarks.each do |benchmarks| |
49 | | - - benchmarks.each_with_index do |benchmark, index| |
50 | | - %li.nav-item |
| 16 | + - category_benchmarks.each do |category, benchmarks| |
| 17 | + - benchmarks.each do |benchmark| |
| 18 | + %li.nav-item{ 'data-category': category.downcase } |
51 | 19 | %a.nav-link.activate-chart{ href: '#', 'data-id': benchmark }= benchmark |
52 | | - %li.nav-item{ style: 'clear: both; float: left; display: block; position: relative;' } |
53 | 20 |
|
54 | 21 | - graph_data = { 'data-ruby-versions': [], 'data-vm-values': [] } |
55 | | - - category_benchmarks.each do |benchmarks| |
| 22 | + - category_benchmarks.each_value do |benchmarks| |
56 | 23 | - benchmarks.each do |benchmark| |
57 | 24 | .benchmark_graph{ graph_data, id: benchmark, 'data-name': benchmark } |
58 | 25 |
|
|
125 | 92 | }); |
126 | 93 | }; |
127 | 94 |
|
| 95 | + // Show only the benchmark tabs of the given category |
| 96 | + function showCategory(category) { |
| 97 | + $('.category_switch').removeClass('active'); |
| 98 | + $('.category_switch[data-category="' + category + '"]').addClass('active'); |
| 99 | + $('.benchmark_navbar .nav-item[data-category]').hide(); |
| 100 | + $('.benchmark_navbar .nav-item[data-category="' + category + '"]').show(); |
| 101 | + } |
| 102 | +
|
128 | 103 | function activateChart(graphElement) { |
129 | 104 | // TODO: show a loading indicator until it receives a response? |
130 | 105 |
|
131 | 106 | var benchmark = graphElement.attr('id'); |
| 107 | +
|
| 108 | + // Keep the category switcher in sync with the benchmark being shown |
| 109 | + var category = $('.activate-chart[data-id="' + benchmark + '"]').closest('.nav-item').data('category'); |
| 110 | + if (category) { |
| 111 | + showCategory(category); |
| 112 | + } |
| 113 | +
|
132 | 114 | $.get('https://raw.githubusercontent.com/rubybench/rubybench-data/main/ruby/' + benchmark + '/' + benchmark + '.yml').done(function (data) { |
133 | 115 | // Show only graphElement and hide everything else |
134 | 116 | $('.benchmark_graph').hide(); |
|
162 | 144 | window.location.hash = id; |
163 | 145 | }); |
164 | 146 |
|
| 147 | + // Switch category and jump to its first benchmark |
| 148 | + showCategory('#{category_benchmarks.keys.first.downcase}'); |
| 149 | + $('.category_switch').on('click', function() { |
| 150 | + var category = $(this).data('category'); |
| 151 | + showCategory(category); |
| 152 | + var active = $('.benchmark_navbar li.active'); |
| 153 | + if (active.data('category') !== category) { |
| 154 | + $('.benchmark_navbar .nav-item[data-category="' + category + '"] .activate-chart').first().trigger('click'); |
| 155 | + } |
| 156 | + }); |
| 157 | + |
165 | 158 | // Load rubies first |
166 | 159 | $.get('https://raw.githubusercontent.com/rubybench/rubybench-data/master/rubies.yml').done(function (data) { |
167 | 160 | rubies = jsyaml.load(data); |
|
175 | 168 | $('.activate-chart[data-id=' + id + ']').closest('li').addClass('active'); |
176 | 169 | } |
177 | 170 | else { |
178 | | - activateChart($('.benchmark_graph##{category_benchmarks.first.first}')); |
| 171 | + activateChart($('.benchmark_graph##{category_benchmarks.values.flatten.first}')); |
179 | 172 | } |
180 | 173 | }); |
181 | 174 | }); |
0 commit comments