├── .byebug_history ├── rails ├── benchmarks │ ├── partials │ │ ├── heavy │ │ │ ├── _item.html.erb │ │ │ ├── _third.html.erb │ │ │ └── _second.html.erb │ │ ├── layouts │ │ │ └── application.html.erb │ │ └── first.html.erb │ ├── assets │ │ └── javascripts │ │ │ ├── two.js │ │ │ ├── application.js │ │ │ └── one.js.erb │ ├── views │ │ └── posts │ │ │ ├── show.json.jbuilder │ │ │ ├── new.html.erb │ │ │ ├── edit.html.erb │ │ │ ├── index.json.jbuilder │ │ │ ├── show.html.erb │ │ │ ├── _form.html.erb │ │ │ └── index.html.erb │ ├── form_partials │ │ ├── heavy │ │ │ ├── _third.html.erb │ │ │ ├── _second.html.erb │ │ │ └── _item.html.erb │ │ ├── layouts │ │ │ └── application.html.erb │ │ └── first.html.erb │ ├── support │ │ ├── request_helper.rb │ │ ├── echo_channel.rb │ │ ├── benchmark_rails.rb │ │ └── url_generation_base.rb │ ├── actionpack_url_generation_others.rb │ ├── actionpack_url_generation_url_for.rb │ ├── bm_activerecord_pluck.rb │ ├── bm_activerecord_pluck_with_scope.rb │ ├── bm_activerecord_finders_first.rb │ ├── bm_activerecord_finders_first_over_select.rb │ ├── bm_activerecord_finders_find_by_sql.rb │ ├── bm_activerecord_preload.rb │ ├── bm_actioncontroller_api.rb │ ├── actionpack_url_generation_rest.rb │ ├── bm_activerecord_finders_find_by_attributes.rb │ ├── bm_activerecord_finders_find_by_attributes_over_select.rb │ ├── bm_sprockets_javascript.rb │ ├── bm_activerecord_create_string_columns.rb │ ├── bm_activerecord_scope_all_over_select.rb │ ├── bm_activerecord_scope_all_with_default_scope.rb │ ├── bm_activerecord_save.rb │ ├── bm_activerecord_scope_all_with_default_scope_over_select.rb │ ├── bm_activerecord_scope_all.rb │ ├── bm_activerecord_destroy.rb │ ├── bm_activerecord_scope_where_over_select.rb │ ├── bm_activerecord_scope_where.rb │ ├── bm_activerecord_validations_invalid.rb │ ├── bm_activerecord_validations_valid.rb │ ├── actionview_partials.rb │ ├── activemodel_views.rb │ ├── bm_scaffold_new.rb │ ├── bm_scaffold_index.rb │ ├── bm_scaffold_show.rb │ ├── bm_activerecord_discourse.rb │ ├── bm_scaffold_create.rb │ ├── bm_scaffold_update.rb │ └── actionpack_router.rb ├── .bundle │ └── config └── Gemfile ├── ruby ├── benchmark │ ├── int_quo.rb │ ├── loop_times.rb │ ├── bighash.rb │ ├── loop_for.rb │ ├── match_small.rb │ ├── time_subsec.rb │ ├── hash_small2.rb │ ├── hash_small4.rb │ ├── hash_small8.rb │ ├── match_gt4.rb │ ├── array_sample_100k_10.rb │ ├── array_sample_100k_11.rb │ ├── array_sample_100k__100.rb │ ├── array_sample_100k__1k.rb │ ├── array_sample_100k__6k.rb │ ├── array_sort_float.rb │ ├── marshal_dump_load_time.rb │ ├── array_sample_100k___10k.rb │ ├── array_sample_100k___50k.rb │ ├── vm2_eval.yml │ ├── loop_whileloop.rb │ ├── loop_whileloop2.rb │ ├── app_strconcat.rb │ ├── array_values_at_int.rb │ ├── string_scan_re.rb │ ├── string_scan_str.rb │ ├── vm2_newlambda.yml │ ├── array_values_at_range.rb │ ├── vm3_gc_old_full.rb │ ├── array_sort_block.rb │ ├── marshal_dump_flo.rb │ ├── vm1_ivar_set.yml │ ├── vm2_array.yml │ ├── vm3_gc.rb │ ├── app_raise.rb │ ├── vm_thread_sleep.yml │ ├── securerandom.rb │ ├── vm1_rescue.yml │ ├── vm1_not.yml │ ├── vm3_clearmethodcache.rb │ ├── vm_thread_alive_check1.rb │ ├── hash_aref_fix.rb │ ├── hash_literal_small2.rb │ ├── string_index.rb │ ├── vm1_ivar.yml │ ├── vm_thread_create_join.rb │ ├── hash_keys.rb │ ├── range_last.yml │ ├── vm1_swap.yml │ ├── vm2_unif1.yml │ ├── hash_flatten.rb │ ├── hash_values.rb │ ├── vm1_blockparam.yml │ ├── vm2_dstr.yml │ ├── vm2_regexp.yml │ ├── app_fib.rb │ ├── dir_empty_p.rb │ ├── hash_aref_flo.rb │ ├── hash_to_proc.rb │ ├── vm1_const.yml │ ├── vm1_simplereturn.yml │ ├── hash_aref_dsym.rb │ ├── hash_aref_str.rb │ ├── hash_ident_num.rb │ ├── vm2_module_ann_const_set.yml │ ├── vm3_gc_old_lazy.rb │ ├── hash_ident_str.rb │ ├── io_select.rb │ ├── vm1_neq.yml │ ├── vm3_gc_old_immediate.rb │ ├── app_uri.rb │ ├── enum_lazy_uniq_20.rb │ ├── enum_lazy_uniq_50.rb │ ├── hash_literal_small4.rb │ ├── hash_shift.rb │ ├── vm1_block.yml │ ├── vm1_lvar_set.yml │ ├── vm2_method.yml │ ├── vm_thread_close.rb │ ├── enum_lazy_uniq_100.rb │ ├── hash_ident_flo.rb │ ├── hash_ident_obj.rb │ ├── vm1_blockparam_call.yml │ ├── vm1_length.yml │ ├── app_factorial.rb │ ├── enum_lazy_grep_v_100.rb │ ├── enum_lazy_grep_v_20.rb │ ├── enum_lazy_grep_v_50.rb │ ├── hash_ident_sym.rb │ ├── vm2_mutex.yml │ ├── vm2_string_literal.yml │ ├── hash_aref_miss.rb │ ├── hash_shift_u16.rb │ ├── vm2_struct_small_aref.yml │ ├── vm2_struct_small_href.yml │ ├── hash_shift_u24.rb │ ├── vm1_blockparam_yield.yml │ ├── vm2_struct_small_hset.yml │ ├── hash_shift_u32.rb │ ├── vm_thread_alive_check.yml │ ├── vm2_defined_method.yml │ ├── vm2_method_with_block.yml │ ├── vm2_module_const_set.yml │ ├── vm2_proc.yml │ ├── vm2_send.yml │ ├── vm1_float_simple.yml │ ├── vm2_struct_big_href_hi.yml │ ├── vm2_struct_big_href_lo.yml │ ├── file_chmod.rb │ ├── vm2_fiber_count.yml │ ├── vm2_struct_big_aref_hi.yml │ ├── vm2_struct_big_aref_lo.yml │ ├── vm1_gc_short_lived.yml │ ├── vm_thread_pass_flood.rb │ ├── app_tak.rb │ ├── vm2_fiber_allocate.yml │ ├── app_tarai.rb │ ├── hash_literal_small8.rb │ ├── io_file_create.rb │ ├── string_split.yml │ ├── vm1_blockparam_pass.yml │ ├── complex_float_add.yml │ ├── complex_float_div.yml │ ├── complex_float_mul.yml │ ├── complex_float_sub.yml │ ├── complex_float_new.yml │ ├── complex_float_power.yml │ ├── vm_symbol_block_pass.rb │ ├── io_file_write.rb │ ├── marshal_dump_load_geniv.rb │ ├── vm2_case.yml │ ├── hash_aref_sym.rb │ ├── io_file_read.rb │ ├── loop_generator.rb │ ├── vm2_freezestring.yml │ ├── vm2_method_missing.yml │ ├── vm2_super.yml │ ├── vm2_fiber_switch.yml │ ├── vm2_raise1.yml │ ├── vm1_attr_ivar.yml │ ├── vm2_raise2.yml │ ├── vm2_zsuper.yml │ ├── irb_exec.yml │ ├── vm1_attr_ivar_set.yml │ ├── vm1_yield.yml │ ├── string_upcase.yml │ ├── vm2_fiber_reuse.yml │ ├── vm2_struct_small_aset.yml │ ├── vm_thread_pass.rb │ ├── vm_thread_queue.rb │ ├── string_downcase.yml │ ├── vm1_gc_short_with_long.yml │ ├── vm1_gc_short_with_symbol.yml │ ├── vm2_fiber_reuse_gc.yml │ ├── hash_long.rb │ ├── string_swapcase.yml │ ├── vm1_ensure.yml │ ├── vm2_struct_big_hset.yml │ ├── file_rename.rb │ ├── vm2_struct_big_aset.yml │ ├── vm1_gc_wb_ary.yml │ ├── string_capitalize.yml │ ├── io_pipe_rw.rb │ ├── vm_thread_pipe.rb │ ├── array_shift.rb │ ├── vm3_backtrace.rb │ ├── vm_thread_mutex3.rb │ ├── vm_thread_sized_queue.rb │ ├── app_answer.rb │ ├── so_random.rb │ ├── vm1_gc_wb_ary_promoted.yml │ ├── vm_thread_mutex2.rb │ ├── vm1_gc_wb_obj.yml │ ├── app_mandelbrot.rb │ ├── irb_color.yml │ ├── vm_thread_mutex1.rb │ ├── so_ackermann.rb │ ├── so_concatenate.rb │ ├── io_select3.rb │ ├── vm1_gc_wb_obj_promoted.yml │ ├── io_nonblock_noex2.rb │ ├── vm_thread_sized_queue3.rb │ ├── io_nonblock_noex.rb │ ├── vm2_poly_singleton.yml │ ├── vm_thread_sized_queue2.rb │ ├── app_erb.yml │ ├── hash_aref_sym_long.rb │ ├── io_select2.rb │ ├── vm2_poly_method.yml │ ├── so_sieve.rb │ ├── vm2_poly_method_ov.yml │ ├── so_array.rb │ ├── vm1_gc_short_with_complex_long.yml │ ├── vm_thread_sized_queue4.rb │ ├── array_small_and.rb │ ├── array_small_diff.rb │ ├── array_small_or.rb │ ├── time_strptime.yml │ ├── erb_render.yml │ ├── so_nested_loop.rb │ ├── hash_aref_dsym_long.rb │ ├── vm_thread_condvar1.rb │ ├── vm2_case_lit.yml │ ├── vm1_lvar_init.yml │ ├── io_copy_stream_write.rb │ ├── fiber_chain.yml │ ├── require.yml │ ├── fiber_chain.rb │ ├── so_nsieve.rb │ ├── vm_thread_condvar2.rb │ ├── so_partial_sums.rb │ ├── require_thread.yml │ ├── io_copy_stream_write_socket.rb │ ├── so_nsieve_bits.rb │ ├── so_spectralnorm.rb │ ├── so_fannkuch.rb │ ├── so_exception.rb │ ├── so_lists.rb │ ├── so_matrix.rb │ ├── so_object.rb │ ├── realpath.yml │ ├── cgi_escape_html.yml │ ├── so_binary_trees.rb │ ├── so_mandelbrot.rb │ ├── so_pidigits.rb │ ├── so_fasta.rb │ └── app_pentomino.rb └── driver.rb ├── suite-logo.png ├── benchmark_driver-output-rubybench ├── Rakefile ├── .gitignore ├── lib │ └── benchmark_driver │ │ ├── output │ │ └── rubybench │ │ │ └── version.rb │ │ └── runner │ │ └── seconds.rb ├── Gemfile ├── README.md ├── LICENSE.txt └── benchmark_driver-output-rubybench.gemspec ├── sequel ├── .bundle │ └── config ├── benchmarks │ ├── bm_sequel_finders_first.rb │ ├── bm_sequel_finders_first_over_select.rb │ ├── support │ │ └── benchmark_sequel.rb │ ├── bm_sequel_finders_find_by_attributes.rb │ ├── bm_sequel_finders_find_by_attributes_over_select.rb │ ├── bm_sequel_scope_all_over_select.rb │ ├── bm_sequel_scope_all.rb │ ├── bm_sequel_save.rb │ ├── bm_sequel_create_string_columns.rb │ ├── bm_sequel_scope_where_over_select.rb │ ├── bm_sequel_scope_where.rb │ ├── bm_sequel_scope_all_with_default_scope.rb │ ├── bm_sequel_destroy.rb │ ├── bm_sequel_scope_all_with_default_scope_over_select.rb │ ├── bm_sequel_validations_invalid.rb │ ├── bm_sequel_validations_valid.rb │ └── bm_sequel_discourse.rb └── Gemfile ├── bundler └── benchmarks │ ├── gems │ └── noop-gem │ │ ├── bin │ │ └── noop-gem │ │ ├── lib │ │ └── noop │ │ │ ├── gem │ │ │ └── version.rb │ │ │ └── gem.rb │ │ └── noop-gem.gemspec │ ├── bm_resolve_rails.rb │ ├── bm_resolve_cocoapods.rb │ ├── bm_resolve_gx_api_rails.rb │ ├── bm_bundle_lock_gem.rb │ ├── bm_bundle_outdated_rails.rb │ ├── bm_bundle_exec_binary.rb │ ├── bm_bundle_exec_gem.rb │ ├── bm_bundle_install_rails_fixed.rb │ ├── bm_bundle_exec_shell.rb │ ├── bm_bundle_install_rails.rb │ └── support │ └── benchmark_bundler.rb ├── .gitignore ├── support ├── setup │ ├── .bundle │ │ └── config │ ├── Gemfile │ ├── bm_save_setup.rb │ ├── bm_destroy_setup.rb │ ├── bm_create_string_columns_setup.rb │ ├── bm_validations_invalid_setup.rb │ ├── bm_validations_valid_setup.rb │ ├── bm_scope_all_setup.rb │ ├── bm_scope_where_setup.rb │ ├── bm_with_default_scope_setup.rb │ ├── bm_finders_setup.rb │ └── bm_preload_setup.rb ├── helpers.rb └── benchmark_runner.rb ├── discourse ├── rails_ruby_bench │ └── patches │ │ └── assets_jq.rb └── benchmarks │ └── patches │ └── active_support_duration.rb ├── liquid_benchmarks ├── bm_parse.rb ├── bm_render.rb ├── bm_parse_and_render.rb └── benchmark_liquid.rb ├── .gitmodules ├── pg ├── Gemfile └── benchmarks │ ├── driver.rb │ ├── support │ └── benchmark_pg.rb │ ├── bm_scope_all_over_select.rb │ ├── bm_scope_all.rb │ └── bm_discourse.rb ├── optcarrot_benchmarks └── driver.rb ├── README.md ├── LICENSE ├── guides └── running_and_writing_rails_benchmarks.md └── CODE_OF_CONDUCT.md /.byebug_history: -------------------------------------------------------------------------------- 1 | exit 2 | -------------------------------------------------------------------------------- /rails/benchmarks/partials/heavy/_item.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rails/benchmarks/assets/javascripts/two.js: -------------------------------------------------------------------------------- 1 | alert() 2 | -------------------------------------------------------------------------------- /ruby/benchmark/int_quo.rb: -------------------------------------------------------------------------------- 1 | 5000000.times { 42.quo(3) } 2 | -------------------------------------------------------------------------------- /ruby/benchmark/loop_times.rb: -------------------------------------------------------------------------------- 1 | 30_000_000.times{|e|} 2 | -------------------------------------------------------------------------------- /ruby/benchmark/bighash.rb: -------------------------------------------------------------------------------- 1 | h = {}; 5000000.times {|n| h[n] = n } 2 | -------------------------------------------------------------------------------- /ruby/benchmark/loop_for.rb: -------------------------------------------------------------------------------- 1 | for i in 1..30_000_000 2 | # 3 | end 4 | -------------------------------------------------------------------------------- /ruby/benchmark/match_small.rb: -------------------------------------------------------------------------------- 1 | 1000000.times { 'haystack'.match(/hay/) } 2 | -------------------------------------------------------------------------------- /ruby/benchmark/time_subsec.rb: -------------------------------------------------------------------------------- 1 | t = Time.now 2 | 4000000.times { t.subsec } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/hash_small2.rb: -------------------------------------------------------------------------------- 1 | 1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a} 2 | -------------------------------------------------------------------------------- /ruby/benchmark/hash_small4.rb: -------------------------------------------------------------------------------- 1 | 1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a} 2 | -------------------------------------------------------------------------------- /ruby/benchmark/hash_small8.rb: -------------------------------------------------------------------------------- 1 | 1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a} 2 | -------------------------------------------------------------------------------- /ruby/benchmark/match_gt4.rb: -------------------------------------------------------------------------------- 1 | 1000000.times { /(.)(.)(\d+)(\d)/.match("THX1138.") } 2 | -------------------------------------------------------------------------------- /suite-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruby-bench/ruby-bench-suite/HEAD/suite-logo.png -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k_10.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 10} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k_11.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 11} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k__100.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 100} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k__1k.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 1000} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k__6k.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 6000} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sort_float.rb: -------------------------------------------------------------------------------- 1 | arr = Array.new(1000) { rand } 2 | 10000.times { arr.sort } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/marshal_dump_load_time.rb: -------------------------------------------------------------------------------- 1 | 100000.times { Marshal.load(Marshal.dump(Time.now)) } 2 | -------------------------------------------------------------------------------- /benchmark_driver-output-rubybench/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | task :default => :spec 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k___10k.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 10_000} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sample_100k___50k.rb: -------------------------------------------------------------------------------- 1 | arr = [*0...100000] 2 | 10_000.times {arr.sample 50_000} 3 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_eval.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm2_eval: | 3 | eval("1") 4 | loop_count: 6000000 5 | -------------------------------------------------------------------------------- /sequel/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle" 3 | BUNDLE_DISABLE_SHARED_GEMS: "true" 4 | -------------------------------------------------------------------------------- /ruby/benchmark/loop_whileloop.rb: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i<30_000_000 # benchmark loop 1 3 | i += 1 4 | end 5 | -------------------------------------------------------------------------------- /ruby/benchmark/loop_whileloop2.rb: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i< 6_000_000 # benchmark loop 2 3 | i += 1 4 | end 5 | -------------------------------------------------------------------------------- /ruby/benchmark/app_strconcat.rb: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i<2_000_000 3 | "#{1+1} #{1+1} #{1+1}" 4 | i += 1 5 | end 6 | -------------------------------------------------------------------------------- /ruby/benchmark/array_values_at_int.rb: -------------------------------------------------------------------------------- 1 | ary = Array.new(10000) {|i| i} 2 | 100000.times { ary.values_at(500) } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/string_scan_re.rb: -------------------------------------------------------------------------------- 1 | str = Array.new(1_000, 'abc').join(',') 2 | 1_000.times { str.scan(/abc/) } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/string_scan_str.rb: -------------------------------------------------------------------------------- 1 | str = Array.new(1_000, 'abc').join(',') 2 | 1_000.times { str.scan('abc') } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_newlambda.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm2_newlambda: | 3 | lambda {} 4 | loop_count: 6000000 5 | -------------------------------------------------------------------------------- /rails/benchmarks/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | //= require one.js 2 | //= require_tree . 3 | //= link two.js 4 | -------------------------------------------------------------------------------- /rails/benchmarks/partials/heavy/_third.html.erb: -------------------------------------------------------------------------------- 1 | <% users.each do |user| %> 2 | <%= user.email %> 3 | <% end %> 4 | -------------------------------------------------------------------------------- /ruby/benchmark/array_values_at_range.rb: -------------------------------------------------------------------------------- 1 | ary = Array.new(10000) {|i| i} 2 | 100000.times { ary.values_at(1..2000) } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/vm3_gc_old_full.rb: -------------------------------------------------------------------------------- 1 | old_object = Array.new(1_000_000){''} 2 | 100.times do 3 | GC.start 4 | end 5 | -------------------------------------------------------------------------------- /bundler/benchmarks/gems/noop-gem/bin/noop-gem: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'rubygems' 3 | require 'rails' 4 | exit 0 5 | -------------------------------------------------------------------------------- /rails/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle" 3 | BUNDLE_DISABLE_SHARED_GEMS: "true" 4 | BUNDLE_JOBS: "4" 5 | -------------------------------------------------------------------------------- /ruby/benchmark/array_sort_block.rb: -------------------------------------------------------------------------------- 1 | ary = Array.new(1000) { rand(1000) } 2 | 10000.times { ary.sort { |a, b| a <=> b } } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/marshal_dump_flo.rb: -------------------------------------------------------------------------------- 1 | bug10761 = 10000.times.map { |x| x.to_f } 2 | 100.times { Marshal.dump(bug10761) } 3 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_ivar_set.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm1_ivar_set: | 3 | @a = 1 4 | @b = 2 5 | loop_count: 30000000 6 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_array.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm2_array: | 3 | a = [1,2,3,4,5,6,7,8,9,10] 4 | loop_count: 6000000 5 | -------------------------------------------------------------------------------- /ruby/benchmark/vm3_gc.rb: -------------------------------------------------------------------------------- 1 | 5000.times do 2 | 100.times do 3 | {"xxxx"=>"yyyy"} 4 | end 5 | GC.start 6 | end 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | rails/vendor/ 2 | rails/log/ 3 | Gemfile.lock 4 | sequel/vendor/ 5 | sequel/log/ 6 | support/setup/vendor 7 | 8 | -------------------------------------------------------------------------------- /rails/benchmarks/views/posts/show.json.jbuilder: -------------------------------------------------------------------------------- 1 | json.extract! @post, :id, :title, :body, :author, :created_at, :updated_at 2 | -------------------------------------------------------------------------------- /ruby/benchmark/app_raise.rb: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i<300000 3 | i += 1 4 | begin 5 | raise 6 | rescue 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_sleep.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm_thread_sleep: | 3 | Thread.new { sleep } 4 | loop_count: 10_000 5 | -------------------------------------------------------------------------------- /bundler/benchmarks/gems/noop-gem/lib/noop/gem/version.rb: -------------------------------------------------------------------------------- 1 | module Noop 2 | module Gem 3 | VERSION = "0.1.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /ruby/benchmark/securerandom.rb: -------------------------------------------------------------------------------- 1 | require "securerandom" 2 | 3 | 20_0000.times do 4 | SecureRandom.random_number(100) 5 | end 6 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_rescue.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm1_rescue: | 3 | begin 4 | rescue 5 | end 6 | loop_count: 30000000 7 | -------------------------------------------------------------------------------- /support/setup/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_DISABLE_SHARED_GEMS: "true" 3 | BUNDLE_PATH: "vendor/bundle" 4 | BUNDLE_JOBS: "4" 5 | -------------------------------------------------------------------------------- /rails/benchmarks/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |
<%= post.body %>
4 | <%= post.from %> 5 | 6 | <%= render partial: 'third', locals: { users: users } %> 7 | <% end %> 8 | -------------------------------------------------------------------------------- /ruby/benchmark/complex_float_new.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | max, min = 1000.0, -1000.0 3 | a = Complex(rand(max)+min, rand(max)+min) 4 | b = Complex(rand(max)+min, rand(max)+min) 5 | benchmark: 6 | complex_float_new: c = Complex(a, b) 7 | loop_count: 1000000 8 | -------------------------------------------------------------------------------- /ruby/benchmark/complex_float_power.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | max, min = 1000.0, -1000.0 3 | a = Complex(rand(max)+min, rand(max)+min) 4 | b = Complex(rand(max)+min, rand(max)+min) 5 | benchmark: 6 | complex_float_power: c = a ** b 7 | loop_count: 1000000 8 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_symbol_block_pass.rb: -------------------------------------------------------------------------------- 1 | class C 2 | 1000.times {|i| 3 | eval("def i#{i};end") 4 | } 5 | end 6 | 7 | c = C.new 8 | m = C.instance_methods(false) 9 | 5_000.times do 10 | m.each do |n| 11 | c.tap(&n) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /rails/benchmarks/form_partials/heavy/_second.html.erb: -------------------------------------------------------------------------------- 1 | <% posts.each do |post| %> 2 |<%= post.body %>
4 | <%= post.from %> 5 | 6 | <%= render partial: 'third', locals: { users: users } %> 7 | <% end %> 8 | -------------------------------------------------------------------------------- /ruby/benchmark/io_file_write.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Seek and Write file. 3 | # 4 | 5 | require 'tempfile' 6 | 7 | max = 200_000 8 | str = "Hello world! " * 1000 9 | f = Tempfile.new('yarv-benchmark') 10 | 11 | max.times{ 12 | f.seek 0 13 | f.write str 14 | } 15 | -------------------------------------------------------------------------------- /ruby/benchmark/marshal_dump_load_geniv.rb: -------------------------------------------------------------------------------- 1 | a = '' 2 | a.instance_eval do 3 | @a = :a 4 | @b = :b 5 | @c = :c 6 | end 7 | 100000.times do 8 | a = Marshal.load(Marshal.dump(a)) 9 | end 10 | #p(a.instance_eval { @a == :a && @b == :b && @c == :c }) 11 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_case.yml: -------------------------------------------------------------------------------- 1 | benchmark: 2 | vm2_case: | 3 | case :foo 4 | when :bar 5 | raise 6 | when :baz 7 | raise 8 | when :boo 9 | raise 10 | when :foo 11 | # noop 12 | end 13 | loop_count: 6000000 14 | -------------------------------------------------------------------------------- /ruby/benchmark/hash_aref_sym.rb: -------------------------------------------------------------------------------- 1 | h = {} 2 | syms = ('a'..'z').to_a 3 | begin 4 | syms = eval("%i[#{syms.join(' ')}]") 5 | rescue SyntaxError # <= 1.9.3 6 | syms.map!(&:to_sym) 7 | end 8 | syms.each { |s| h[s] = s } 9 | 200_000.times { syms.each { |s| h[s] } } 10 | -------------------------------------------------------------------------------- /ruby/benchmark/io_file_read.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Seek and Read file. 3 | # 4 | 5 | require 'tempfile' 6 | 7 | max = 200_000 8 | str = "Hello world! " * 1000 9 | f = Tempfile.new('yarv-benchmark') 10 | f.write str 11 | 12 | max.times{ 13 | f.seek 0 14 | f.read 15 | } 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "optcarrot_benchmarks/optcarrot"] 2 | path = optcarrot_benchmarks/optcarrot 3 | url = https://github.com/mame/optcarrot.git 4 | [submodule "liquid_benchmarks/liquid"] 5 | path = liquid_benchmarks/liquid 6 | url = https://github.com/Shopify/liquid.git 7 | -------------------------------------------------------------------------------- /ruby/benchmark/loop_generator.rb: -------------------------------------------------------------------------------- 1 | max = 600000 2 | 3 | if defined? Fiber 4 | gen = (1..max).each 5 | loop do 6 | gen.next 7 | end 8 | else 9 | require 'generator' 10 | gen = Generator.new((0..max)) 11 | while gen.next? 12 | gen.next 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_freezestring.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class String 3 | def freeze 4 | -self 5 | end 6 | end 7 | benchmark: 8 | vm2_freezestring: | 9 | "tXnL1BP5T1WPXMjuFNLQtallEtRcay1t2lHtJSrlVsDgvunlbtfpr/DGdH0NGYE9".freeze 10 | loop_count: 6000000 11 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_method_missing.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class C 3 | def method_missing mid 4 | end 5 | end 6 | 7 | obj = C.new 8 | benchmark: 9 | vm2_method_missing: | 10 | obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; obj.m; 11 | loop_count: 6000000 12 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_super.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class C 3 | def m 4 | 1 5 | end 6 | end 7 | 8 | class CC < C 9 | def m 10 | super() 11 | end 12 | end 13 | 14 | obj = CC.new 15 | benchmark: 16 | vm2_super: obj.m 17 | loop_count: 6000000 18 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_fiber_switch.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | # based on benchmark for [ruby-core:65518] [Feature #10341] by Knut Franke 3 | fib = Fiber.new do 4 | loop { Fiber.yield } 5 | end 6 | benchmark: 7 | vm2_fiber_switch: | 8 | fib.resume 9 | loop_count: 6000000 10 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_raise1.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | def rec n 3 | if n > 0 4 | rec n-1 5 | else 6 | raise 7 | end 8 | end 9 | benchmark: 10 | vm2_raise1: | 11 | begin 12 | rec 1 13 | rescue 14 | # ignore 15 | end 16 | loop_count: 6000000 17 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_attr_ivar.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class C 3 | attr_reader :a, :b 4 | def initialize 5 | @a = nil 6 | @b = nil 7 | end 8 | end 9 | obj = C.new 10 | benchmark: 11 | vm1_attr_ivar: | 12 | j = obj.a 13 | k = obj.b 14 | loop_count: 30000000 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_raise2.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | def rec n 3 | if n > 0 4 | rec n-1 5 | else 6 | raise 7 | end 8 | end 9 | benchmark: 10 | vm2_raise2: | 11 | begin 12 | rec 10 13 | rescue 14 | # ignore 15 | end 16 | loop_count: 6000000 17 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_zsuper.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class C 3 | def m a 4 | 1 5 | end 6 | end 7 | 8 | class CC < C 9 | def m a 10 | super 11 | end 12 | end 13 | 14 | obj = CC.new 15 | benchmark: 16 | vm2_zsuper: | 17 | obj.m 10 18 | loop_count: 6000000 19 | -------------------------------------------------------------------------------- /ruby/benchmark/irb_exec.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | # frozen_string_literal: true 3 | require 'rbconfig' 4 | irb_f = [File.join(File.dirname(RbConfig.ruby), 'irb'), '-f'] 5 | benchmark: 6 | irb_exec: | 7 | IO.popen(irb_f, 'w') do |io| 8 | io.write('exit') 9 | end 10 | loop_count: 30 11 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_attr_ivar_set.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | class C 3 | attr_accessor :a, :b 4 | def initialize 5 | @a = nil 6 | @b = nil 7 | end 8 | end 9 | obj = C.new 10 | benchmark: 11 | vm1_attr_ivar_set: | 12 | obj.a = 1 13 | obj.b = 2 14 | loop_count: 30000000 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_yield.yml: -------------------------------------------------------------------------------- 1 | # while loop cost is not removed due to benchmark_driver.gem's limitation 2 | benchmark: 3 | vm1_yield: | 4 | def m 5 | i = 0 6 | while i<30_000_000 7 | i += 1 8 | yield 9 | end 10 | end 11 | 12 | m{} 13 | loop_count: 1 14 | -------------------------------------------------------------------------------- /support/helpers.rb: -------------------------------------------------------------------------------- 1 | STRING_COLUMNS_COUNT = 25 2 | 3 | def db_adapter 4 | ENV['DATABASE_URL'].split(":")[0] 5 | end 6 | 7 | def db_setup(script:) 8 | Dir.chdir("../../support/setup") do 9 | `DATABASE_URL=#{ENV.fetch("DATABASE_URL")} BUNDLE_GEMFILE=Gemfile ruby #{script}` 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /benchmark_driver-output-rubybench/README.md: -------------------------------------------------------------------------------- 1 | # BenchmarkDriver::Output::Rubybench 2 | 3 | Use this with `gem install benchmark_driver-output-rubybench` on ruby-bench-docker. 4 | 5 | ## License 6 | 7 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 8 | -------------------------------------------------------------------------------- /bundler/benchmarks/bm_resolve_gx_api_rails.rb: -------------------------------------------------------------------------------- 1 | require_relative 'support/benchmark_bundler.rb' 2 | 3 | gemfile = proc do 4 | source "https://rubygems.org" 5 | 6 | gem "sass-rails" 7 | gem "rails", "~> 3" 8 | gem "gxapi_rails" 9 | end 10 | 11 | Benchmark.resolve_definition('gxapi_rails', gemfile) 12 | -------------------------------------------------------------------------------- /ruby/benchmark/string_upcase.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | str1 = [*"a".."z",*"0".."9"].join("") 3 | str10 = str1 * 10 4 | str100 = str10 * 10 5 | str1000 = str100 * 10 6 | benchmark: 7 | upcase-1: str1.upcase 8 | upcase-10: str10.upcase 9 | upcase-100: str100.upcase 10 | upcase-1000: str1000.upcase 11 | -------------------------------------------------------------------------------- /pg/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | module ::Kernel 4 | def pg_master? 5 | ENV["PG_MASTER"] == '1' 6 | end 7 | end 8 | 9 | if pg_master? 10 | gem 'pg', github: 'ged/ruby-pg' 11 | else 12 | gem 'pg', path: '/ruby-pg' 13 | end 14 | 15 | gem 'benchmark-ips', '~> 2.2.0' 16 | gem 'byebug' 17 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_fiber_reuse.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | GC.disable 3 | fibers = [] 4 | benchmark: 5 | vm2_fiber_reuse: | 6 | 1024.times do 7 | fiber = Fiber.new{Fiber.yield} 8 | fibers << fiber 9 | fiber.resume 10 | end 11 | 12 | fibers.clear 13 | GC.start 14 | loop_count: 200 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_struct_small_aset.yml: -------------------------------------------------------------------------------- 1 | # loop_count is not utilized since `i` is involved in the script 2 | benchmark: 3 | vm2_struct_small_aset: | 4 | s = Struct.new(:a, :b, :c) 5 | x = s.new 6 | i = 0 7 | while i<6_000_000 8 | i += 1 9 | x.a = i 10 | end 11 | loop_count: 1 12 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_pass.rb: -------------------------------------------------------------------------------- 1 | # Plenty Thtread.pass 2 | # A performance may depend on GVL implementation. 3 | 4 | tmax = (ARGV.shift || 2).to_i 5 | lmax = 200_000 / tmax 6 | 7 | (1..tmax).map{ 8 | Thread.new{ 9 | lmax.times{ 10 | Thread.pass 11 | } 12 | } 13 | }.each{|t| t.join} 14 | 15 | 16 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_queue.rb: -------------------------------------------------------------------------------- 1 | require 'thread' 2 | 3 | n = 1_000_000 4 | q = Thread::Queue.new 5 | consumer = Thread.new{ 6 | while q.pop 7 | # consuming 8 | end 9 | } 10 | 11 | producer = Thread.new{ 12 | n.times{ 13 | q.push true 14 | } 15 | q.push nil 16 | } 17 | 18 | consumer.join 19 | -------------------------------------------------------------------------------- /rails/benchmarks/form_partials/heavy/_item.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for post, url: '/posts' do |f|%> 2 | <%= f.label :body %> 3 | <%= f.text_field :body %> 4 | 5 | <%= f.label :from %> 6 | <%= f.text_field :from %> 7 | 8 | <%= f.label :title %> 9 | <%= f.text_field :title %> 10 | 11 | <%= f.submit 'save' %> 12 | <% end %> 13 | -------------------------------------------------------------------------------- /ruby/benchmark/string_downcase.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | str1 = [*"A".."Z",*"0".."9"].join("") 3 | str10 = str1 * 10 4 | str100 = str10 * 10 5 | str1000 = str100 * 10 6 | benchmark: 7 | downcase-1: str1.upcase 8 | downcase-10: str10.upcase 9 | downcase-100: str100.upcase 10 | downcase-1000: str1000.upcase 11 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_gc_short_with_long.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | long_lived = Array.new(1_000_000){|i| "#{i}"} 3 | GC.start 4 | GC.start 5 | benchmark: 6 | vm1_gc_short_with_long: | 7 | a = '' # short-lived String 8 | b = '' 9 | c = '' 10 | d = '' 11 | e = '' 12 | f = '' 13 | loop_count: 30000000 14 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_gc_short_with_symbol.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | 50_000.times{|i| sym = "sym#{i}".to_sym} 3 | GC.start 4 | GC.start 5 | benchmark: 6 | vm1_gc_short_with_symbol: | 7 | a = '' # short-lived String 8 | b = '' 9 | c = '' 10 | d = '' 11 | e = '' 12 | f = '' 13 | loop_count: 30000000 14 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_fiber_reuse_gc.yml: -------------------------------------------------------------------------------- 1 | # https://bugs.ruby-lang.org/issues/16009 2 | prelude: | 3 | fibers = [] 4 | benchmark: 5 | vm2_fiber_reuse_gc: | 6 | 2000.times do 7 | fiber = Fiber.new{Fiber.yield} 8 | fibers << fiber 9 | fiber.resume 10 | end 11 | fibers.clear 12 | loop_count: 100 13 | -------------------------------------------------------------------------------- /ruby/benchmark/hash_long.rb: -------------------------------------------------------------------------------- 1 | k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong"; 2 | k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping"; 3 | h = {k1 => 0, k2 => 0}; 4 | 3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1} 5 | -------------------------------------------------------------------------------- /rails/benchmarks/support/request_helper.rb: -------------------------------------------------------------------------------- 1 | module RequestHelper 2 | VALID_STATUS = [200, 302] 3 | 4 | def self.perform(app, request) 5 | status, _, body = app.call(request) 6 | raise "Error: response status: #{status}" unless VALID_STATUS.include?(status) 7 | body.close if body.respond_to?(:close) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /ruby/benchmark/string_swapcase.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | str1 = [*"A".."M",*"n".."z",*"0".."9"].join("") 3 | str10 = str1 * 10 4 | str100 = str10 * 10 5 | str1000 = str100 * 10 6 | benchmark: 7 | swapcase-1: str1.swapcase 8 | swapcase-10: str10.swapcase 9 | swapcase-100: str100.swapcase 10 | swapcase-1000: str1000.swapcase 11 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_ensure.yml: -------------------------------------------------------------------------------- 1 | # Not utilizing loop_count since using it for this is too unstable for now 2 | benchmark: 3 | vm1_ensure: | 4 | i = 0 5 | while i<30_000_000 6 | i += 1 7 | begin 8 | begin 9 | ensure 10 | end 11 | ensure 12 | end 13 | end 14 | loop_count: 1 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_struct_big_hset.yml: -------------------------------------------------------------------------------- 1 | # loop_count is not utilized since `i` is involved in the script 2 | benchmark: 3 | vm2_struct_big_hset: | 4 | s = Struct.new(*('a'..'z').map { |x| x.to_sym }) 5 | x = s.new 6 | i = 0 7 | while i<6_000_000 8 | i += 1 9 | x[:k] = i 10 | end 11 | loop_count: 1 12 | -------------------------------------------------------------------------------- /rails/benchmarks/support/echo_channel.rb: -------------------------------------------------------------------------------- 1 | class EchoChannel < ApplicationCable::Channel 2 | def subscribed 3 | stream_from "echo_channel" 4 | end 5 | 6 | def unsubscribed 7 | # Any cleanup needed when channel is unsubscribed 8 | end 9 | 10 | def ding(data) 11 | transmit(dong: data['message']) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /ruby/benchmark/file_rename.rb: -------------------------------------------------------------------------------- 1 | # rename file 2 | require 'tempfile' 3 | 4 | max = 100_000 5 | tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ] 6 | a, b = tmp.map { |x| x.path } 7 | tmp.each { |t| t.close } # Windows can't rename files without closing them 8 | max.times do 9 | File.rename(a, b) 10 | File.rename(b, a) 11 | end 12 | -------------------------------------------------------------------------------- /ruby/benchmark/vm2_struct_big_aset.yml: -------------------------------------------------------------------------------- 1 | # loop_count is not utilized since `i` is involved in the script 2 | benchmark: 3 | vm2_struct_big_aset: | 4 | s = Struct.new(*('a'..'z').map { |x| x.to_sym }) 5 | x = s.new 6 | i = 0 7 | while i<6_000_000 8 | i += 1 9 | x.k = i # x[10] = i 10 | end 11 | loop_count: 1 12 | -------------------------------------------------------------------------------- /ruby/benchmark/vm1_gc_wb_ary.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | short_lived_ary = [] 3 | 4 | if RUBY_VERSION >= "2.2.0" 5 | GC.start(full_mark: false, immediate_mark: true, immediate_sweep: true) 6 | end 7 | 8 | short_lived = '' 9 | benchmark: 10 | vm1_gc_wb_ary: | 11 | short_lived_ary[0] = short_lived # write barrier 12 | loop_count: 30000000 13 | -------------------------------------------------------------------------------- /ruby/benchmark/string_capitalize.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | str1 = [*"a".."m",*"N".."Z",*"0".."9"].join("") 3 | str10 = str1 * 10 4 | str100 = str10 * 10 5 | str1000 = str100 * 10 6 | benchmark: 7 | capitalize-1: str1.capitalize 8 | capitalize-10: str10.capitalize 9 | capitalize-100: str100.capitalize 10 | capitalize-1000: str1000.capitalize 11 | -------------------------------------------------------------------------------- /ruby/benchmark/io_pipe_rw.rb: -------------------------------------------------------------------------------- 1 | # Measure uncontended GVL performance via read/write with 1:1 threading 2 | # If we switch to M:N threading, this will benchmark something else... 3 | r, w = IO.pipe 4 | src = '0'.freeze 5 | dst = String.new 6 | i = 0 7 | while i < 1_000_000 8 | i += 1 9 | w.write(src) 10 | r.read(1, dst) 11 | end 12 | w.close 13 | r.close 14 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_pipe.rb: -------------------------------------------------------------------------------- 1 | # Measure small and plenty pipe read/write. 2 | # A performance may depend on GVL implementation. 3 | 4 | lmax = 100_000 5 | r, w = IO.pipe 6 | [Thread.new{ 7 | lmax.times{ 8 | w.write('a') 9 | } 10 | p "w:exit" 11 | }, Thread.new{ 12 | lmax.times{ 13 | r.read(1) 14 | } 15 | p "r:exit" 16 | }].each{|t| t.join} 17 | 18 | -------------------------------------------------------------------------------- /support/setup/bm_save_setup.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | require "active_record" 3 | 4 | ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL')) 5 | ActiveRecord::Migration.verbose = false 6 | 7 | ActiveRecord::Schema.define do 8 | create_table :users, force: true do |t| 9 | t.string :name, :email 10 | t.timestamps null: false 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /support/setup/bm_destroy_setup.rb: -------------------------------------------------------------------------------- 1 | require "bundler/setup" 2 | require "active_record" 3 | 4 | ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL')) 5 | ActiveRecord::Migration.verbose = false 6 | 7 | ActiveRecord::Schema.define do 8 | create_table :users, force: true do |t| 9 | t.string :name, :email 10 | t.timestamps null: false 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /ruby/benchmark/array_shift.rb: -------------------------------------------------------------------------------- 1 | require 'benchmark' 2 | 3 | Benchmark.bm do |x| 4 | [10_000,1_000_000,100_000_000].each do |n| 5 | ary = Array.new(n,0) 6 | GC.start 7 | x.report("#{n}:shift"){ ary.shift } 8 | (0..4).each do |i| 9 | ary = Array.new(n,0) 10 | GC.start 11 | x.report("#{n}:shift(#{i})"){ ary.shift(i) } 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /ruby/benchmark/vm3_backtrace.rb: -------------------------------------------------------------------------------- 1 | # get last backtrace 2 | 3 | begin 4 | caller(0, 0) 5 | rescue ArgumentError 6 | alias caller_orig caller 7 | def caller lev, n 8 | caller_orig(lev)[0..n] 9 | end 10 | end 11 | 12 | def rec n 13 | if n < 0 14 | 100_000.times{ 15 | caller(0, 1) 16 | } 17 | else 18 | rec(n-1) 19 | end 20 | end 21 | 22 | rec 50 23 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_mutex3.rb: -------------------------------------------------------------------------------- 1 | # 1000 threads, one mutex 2 | 3 | require 'thread' 4 | m = Thread::Mutex.new 5 | r = 0 6 | max = 2000 7 | (1..max).map{ 8 | Thread.new{ 9 | i = 0 10 | while i<%= notice %>
2 | 3 |4 | Title: 5 | <%= @post.title %> 6 |
7 | 8 |9 | Body: 10 | <%= @post.body %> 11 |
12 | 13 |14 | Author: 15 | <%= @post.author %> 16 |
17 | 18 | <%= link_to 'Edit', edit_post_path(@post) %> | 19 | <%= link_to 'Back', posts_path %> 20 | -------------------------------------------------------------------------------- /ruby/benchmark/app_mandelbrot.rb: -------------------------------------------------------------------------------- 1 | require 'complex' 2 | 3 | def mandelbrot? z 4 | i = 0 5 | while i<100 6 | i += 1 7 | z = z * z 8 | return false if z.abs > 2 9 | end 10 | true 11 | end 12 | 13 | ary = [] 14 | 15 | (0..1000).each{|dx| 16 | (0..1000).each{|dy| 17 | x = dx / 50.0 18 | y = dy / 50.0 19 | c = Complex(x, y) 20 | ary << c if mandelbrot?(c) 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /ruby/benchmark/irb_color.yml: -------------------------------------------------------------------------------- 1 | prelude: | 2 | require 'irb/color' 3 | code = <<~'CODE' 4 | def self.foo # bar 5 | :"erb #{ERB.new("<%= self %>", trim_mode: ?-).result}" 6 | end 7 | CODE 8 | benchmark: 9 | irb_color_complete: | 10 | IRB::Color.colorize_code(code, complete: true) 11 | irb_color_incomplete: | 12 | IRB::Color.colorize_code(code, complete: false) 13 | loop_count: 2000000 14 | -------------------------------------------------------------------------------- /ruby/benchmark/vm_thread_mutex1.rb: -------------------------------------------------------------------------------- 1 | # one thread, one mutex (no contention) 2 | 3 | require 'thread' 4 | m = Thread::Mutex.new 5 | r = 0 6 | max = 2000 7 | lmax = max * max 8 | (1..1).map{ 9 | Thread.new{ 10 | i = 0 11 | while i13 | <%= content %> 14 |
15 | 16 |