From 8068d34cfe4f74784cba29e981e2d8437ff02a9f Mon Sep 17 00:00:00 2001 From: k0kubun Date: Tue, 10 Jul 2018 13:05:29 +0000 Subject: Revert "benchmark/*.yml: convert from benchmark/bm_*.rb" This reverts r63900. Having single-execution benchmark as a normal Ruby script is preferred by ko1. I'm not a big fan of having inconsistent benchmark formats, but I can understand some benefits of it. common.mk: remove obsolsted benchmark-each PHONY declaration, support running Ruby scripts added by this commit. README.md: follow ARGS change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/README.md | 4 +- benchmark/app_answer.yml | 18 - benchmark/app_aobench.yml | 295 --------------- benchmark/app_erb.yml | 28 -- benchmark/app_factorial.yml | 14 - benchmark/app_fib.yml | 12 - benchmark/app_lc_fizzbuzz.yml | 55 --- benchmark/app_mandelbrot.yml | 25 -- benchmark/app_pentomino.yml | 130 ------- benchmark/app_raise.yml | 11 - benchmark/app_strconcat.yml | 8 - benchmark/app_tak.yml | 15 - benchmark/app_tarai.yml | 13 - benchmark/app_uri.yml | 11 - benchmark/array_sample_100k_10.yml | 5 - benchmark/array_sample_100k_11.yml | 5 - benchmark/array_sample_100k__100.yml | 5 - benchmark/array_sample_100k__1k.yml | 5 - benchmark/array_sample_100k__6k.yml | 5 - benchmark/array_sample_100k___10k.yml | 5 - benchmark/array_sample_100k___50k.yml | 5 - benchmark/array_shift.yml | 17 - benchmark/array_small_and.yml | 20 - benchmark/array_small_diff.yml | 20 - benchmark/array_small_or.yml | 20 - benchmark/array_sort_block.yml | 5 - benchmark/array_sort_float.yml | 5 - benchmark/array_values_at_int.yml | 5 - benchmark/array_values_at_range.yml | 5 - benchmark/bighash.yml | 4 - benchmark/bm_app_answer.rb | 15 + benchmark/bm_app_aobench.rb | 291 ++++++++++++++ benchmark/bm_app_erb.rb | 25 ++ benchmark/bm_app_factorial.rb | 11 + benchmark/bm_app_fib.rb | 10 + benchmark/bm_app_lc_fizzbuzz.rb | 52 +++ benchmark/bm_app_mandelbrot.rb | 23 ++ benchmark/bm_app_pentomino.rb | 130 +++++++ benchmark/bm_app_raise.rb | 8 + benchmark/bm_app_strconcat.rb | 5 + benchmark/bm_app_tak.rb | 13 + benchmark/bm_app_tarai.rb | 10 + benchmark/bm_app_uri.rb | 8 + benchmark/bm_array_sample_100k_10.rb | 2 + benchmark/bm_array_sample_100k_11.rb | 2 + benchmark/bm_array_sample_100k__100.rb | 2 + benchmark/bm_array_sample_100k__1k.rb | 2 + benchmark/bm_array_sample_100k__6k.rb | 2 + benchmark/bm_array_sample_100k___10k.rb | 2 + benchmark/bm_array_sample_100k___50k.rb | 2 + benchmark/bm_array_shift.rb | 14 + benchmark/bm_array_small_and.rb | 17 + benchmark/bm_array_small_diff.rb | 17 + benchmark/bm_array_small_or.rb | 17 + benchmark/bm_array_sort_block.rb | 2 + benchmark/bm_array_sort_float.rb | 2 + benchmark/bm_array_values_at_int.rb | 2 + benchmark/bm_array_values_at_range.rb | 2 + benchmark/bm_bighash.rb | 1 + benchmark/bm_dir_empty_p.rb | 5 + benchmark/bm_erb_render.rb | 25 ++ benchmark/bm_file_chmod.rb | 9 + benchmark/bm_file_rename.rb | 11 + benchmark/bm_hash_aref_dsym.rb | 4 + benchmark/bm_hash_aref_dsym_long.rb | 21 ++ benchmark/bm_hash_aref_fix.rb | 4 + benchmark/bm_hash_aref_flo.rb | 4 + benchmark/bm_hash_aref_miss.rb | 5 + benchmark/bm_hash_aref_str.rb | 4 + benchmark/bm_hash_aref_sym.rb | 9 + benchmark/bm_hash_aref_sym_long.rb | 13 + benchmark/bm_hash_flatten.rb | 9 + benchmark/bm_hash_ident_flo.rb | 4 + benchmark/bm_hash_ident_num.rb | 4 + benchmark/bm_hash_ident_obj.rb | 4 + benchmark/bm_hash_ident_str.rb | 4 + benchmark/bm_hash_ident_sym.rb | 4 + benchmark/bm_hash_keys.rb | 9 + benchmark/bm_hash_long.rb | 4 + benchmark/bm_hash_shift.rb | 10 + benchmark/bm_hash_shift_u16.rb | 10 + benchmark/bm_hash_shift_u24.rb | 10 + benchmark/bm_hash_shift_u32.rb | 10 + benchmark/bm_hash_small2.rb | 1 + benchmark/bm_hash_small4.rb | 1 + benchmark/bm_hash_small8.rb | 1 + benchmark/bm_hash_to_proc.rb | 9 + benchmark/bm_hash_values.rb | 9 + benchmark/bm_int_quo.rb | 1 + benchmark/bm_io_copy_stream_write.rb | 24 ++ benchmark/bm_io_copy_stream_write_socket.rb | 35 ++ benchmark/bm_io_file_create.rb | 13 + benchmark/bm_io_file_read.rb | 15 + benchmark/bm_io_file_write.rb | 14 + benchmark/bm_io_nonblock_noex.rb | 22 ++ benchmark/bm_io_nonblock_noex2.rb | 21 ++ benchmark/bm_io_pipe_rw.rb | 13 + benchmark/bm_io_select.rb | 9 + benchmark/bm_io_select2.rb | 22 ++ benchmark/bm_io_select3.rb | 21 ++ benchmark/bm_loop_for.rb | 3 + benchmark/bm_loop_generator.rb | 14 + benchmark/bm_loop_times.rb | 1 + benchmark/bm_loop_whileloop.rb | 4 + benchmark/bm_loop_whileloop2.rb | 4 + benchmark/bm_marshal_dump_flo.rb | 2 + benchmark/bm_marshal_dump_load_geniv.rb | 10 + benchmark/bm_marshal_dump_load_time.rb | 1 + benchmark/bm_securerandom.rb | 5 + benchmark/bm_so_ackermann.rb | 19 + benchmark/bm_so_array.rb | 23 ++ benchmark/bm_so_binary_trees.rb | 62 +++ benchmark/bm_so_concatenate.rb | 18 + benchmark/bm_so_exception.rb | 61 +++ benchmark/bm_so_fannkuch.rb | 45 +++ benchmark/bm_so_fasta.rb | 81 ++++ benchmark/bm_so_lists.rb | 47 +++ benchmark/bm_so_mandelbrot.rb | 57 +++ benchmark/bm_so_matrix.rb | 48 +++ benchmark/bm_so_meteor_contest.rb | 563 +++++++++++++++++++++++++++ benchmark/bm_so_nbody.rb | 148 ++++++++ benchmark/bm_so_nested_loop.rb | 24 ++ benchmark/bm_so_nsieve.rb | 35 ++ benchmark/bm_so_nsieve_bits.rb | 43 +++ benchmark/bm_so_object.rb | 56 +++ benchmark/bm_so_partial_sums.rb | 31 ++ benchmark/bm_so_pidigits.rb | 92 +++++ benchmark/bm_so_random.rb | 20 + benchmark/bm_so_sieve.rb | 24 ++ benchmark/bm_so_spectralnorm.rb | 50 +++ benchmark/bm_string_index.rb | 3 + benchmark/bm_string_scan_re.rb | 2 + benchmark/bm_string_scan_str.rb | 2 + benchmark/bm_time_subsec.rb | 2 + benchmark/bm_vm3_backtrace.rb | 22 ++ benchmark/bm_vm3_clearmethodcache.rb | 8 + benchmark/bm_vm3_gc.rb | 6 + benchmark/bm_vm3_gc_old_full.rb | 4 + benchmark/bm_vm3_gc_old_immediate.rb | 4 + benchmark/bm_vm3_gc_old_lazy.rb | 4 + benchmark/bm_vm_symbol_block_pass.rb | 13 + benchmark/bm_vm_thread_alive_check1.rb | 6 + benchmark/bm_vm_thread_close.rb | 6 + benchmark/bm_vm_thread_condvar1.rb | 28 ++ benchmark/bm_vm_thread_condvar2.rb | 35 ++ benchmark/bm_vm_thread_create_join.rb | 6 + benchmark/bm_vm_thread_mutex1.rb | 21 ++ benchmark/bm_vm_thread_mutex2.rb | 21 ++ benchmark/bm_vm_thread_mutex3.rb | 20 + benchmark/bm_vm_thread_pass.rb | 15 + benchmark/bm_vm_thread_pass_flood.rb | 10 + benchmark/bm_vm_thread_pipe.rb | 17 + benchmark/bm_vm_thread_queue.rb | 18 + benchmark/bm_vm_thread_sized_queue.rb | 20 + benchmark/bm_vm_thread_sized_queue2.rb | 23 ++ benchmark/bm_vm_thread_sized_queue3.rb | 22 ++ benchmark/bm_vm_thread_sized_queue4.rb | 26 ++ benchmark/dir_empty_p.yml | 8 - benchmark/erb_render.yml | 28 -- benchmark/file_chmod.yml | 13 - benchmark/file_rename.yml | 15 - benchmark/hash_aref_dsym.yml | 7 - benchmark/hash_aref_dsym_long.yml | 25 -- benchmark/hash_aref_fix.yml | 7 - benchmark/hash_aref_flo.yml | 7 - benchmark/hash_aref_miss.yml | 8 - benchmark/hash_aref_str.yml | 7 - benchmark/hash_aref_sym.yml | 12 - benchmark/hash_aref_sym_long.yml | 16 - benchmark/hash_flatten.yml | 12 - benchmark/hash_ident_flo.yml | 7 - benchmark/hash_ident_num.yml | 7 - benchmark/hash_ident_obj.yml | 7 - benchmark/hash_ident_str.yml | 7 - benchmark/hash_ident_sym.yml | 7 - benchmark/hash_keys.yml | 12 - benchmark/hash_long.yml | 7 - benchmark/hash_shift.yml | 13 - benchmark/hash_shift_u16.yml | 13 - benchmark/hash_shift_u24.yml | 13 - benchmark/hash_shift_u32.yml | 13 - benchmark/hash_small2.yml | 4 - benchmark/hash_small4.yml | 4 - benchmark/hash_small8.yml | 4 - benchmark/hash_to_proc.yml | 12 - benchmark/hash_values.yml | 12 - benchmark/int_quo.yml | 4 - benchmark/io_copy_stream_write.yml | 28 -- benchmark/io_copy_stream_write_socket.yml | 39 -- benchmark/io_file_create.yml | 15 - benchmark/io_file_read.yml | 18 - benchmark/io_file_write.yml | 17 - benchmark/io_nonblock_noex.yml | 25 -- benchmark/io_nonblock_noex2.yml | 24 -- benchmark/io_pipe_rw.yml | 17 - benchmark/io_select.yml | 12 - benchmark/io_select2.yml | 25 -- benchmark/io_select3.yml | 24 -- benchmark/loop_for.yml | 6 - benchmark/loop_generator.yml | 17 - benchmark/loop_times.yml | 4 - benchmark/loop_whileloop.yml | 7 - benchmark/loop_whileloop2.yml | 7 - benchmark/marshal_dump_flo.yml | 5 - benchmark/marshal_dump_load_geniv.yml | 13 - benchmark/marshal_dump_load_time.yml | 4 - benchmark/securerandom.yml | 8 - benchmark/so_ackermann.yml | 21 -- benchmark/so_array.yml | 25 -- benchmark/so_binary_trees.yml | 66 ---- benchmark/so_concatenate.yml | 20 - benchmark/so_exception.yml | 65 ---- benchmark/so_fannkuch.yml | 48 --- benchmark/so_fasta.yml | 84 ----- benchmark/so_lists.yml | 51 --- benchmark/so_mandelbrot.yml | 61 --- benchmark/so_matrix.yml | 50 --- benchmark/so_meteor_contest.yml | 567 ---------------------------- benchmark/so_nbody.yml | 152 -------- benchmark/so_nested_loop.yml | 26 -- benchmark/so_nsieve.yml | 39 -- benchmark/so_nsieve_bits.yml | 46 --- benchmark/so_object.yml | 59 --- benchmark/so_partial_sums.yml | 34 -- benchmark/so_pidigits.yml | 95 ----- benchmark/so_random.yml | 24 -- benchmark/so_sieve.yml | 28 -- benchmark/so_spectralnorm.yml | 54 --- benchmark/string_index.yml | 6 - benchmark/string_scan_re.yml | 5 - benchmark/string_scan_str.yml | 5 - benchmark/time_subsec.yml | 5 - benchmark/vm3_backtrace.yml | 26 -- benchmark/vm3_clearmethodcache.yml | 11 - benchmark/vm3_gc.yml | 9 - benchmark/vm3_gc_old_full.yml | 7 - benchmark/vm3_gc_old_immediate.yml | 7 - benchmark/vm3_gc_old_lazy.yml | 7 - benchmark/vm_symbol_block_pass.yml | 16 - benchmark/vm_thread_alive_check1.yml | 9 - benchmark/vm_thread_close.yml | 9 - benchmark/vm_thread_condvar1.yml | 32 -- benchmark/vm_thread_condvar2.yml | 39 -- benchmark/vm_thread_create_join.yml | 9 - benchmark/vm_thread_mutex1.yml | 25 -- benchmark/vm_thread_mutex2.yml | 25 -- benchmark/vm_thread_mutex3.yml | 24 -- benchmark/vm_thread_pass.yml | 17 - benchmark/vm_thread_pass_flood.yml | 14 - benchmark/vm_thread_pipe.yml | 20 - benchmark/vm_thread_queue.yml | 21 -- benchmark/vm_thread_sized_queue.yml | 23 -- benchmark/vm_thread_sized_queue2.yml | 26 -- benchmark/vm_thread_sized_queue3.yml | 25 -- benchmark/vm_thread_sized_queue4.yml | 29 -- 255 files changed, 3073 insertions(+), 3465 deletions(-) delete mode 100644 benchmark/app_answer.yml delete mode 100644 benchmark/app_aobench.yml delete mode 100644 benchmark/app_erb.yml delete mode 100644 benchmark/app_factorial.yml delete mode 100644 benchmark/app_fib.yml delete mode 100644 benchmark/app_lc_fizzbuzz.yml delete mode 100644 benchmark/app_mandelbrot.yml delete mode 100644 benchmark/app_pentomino.yml delete mode 100644 benchmark/app_raise.yml delete mode 100644 benchmark/app_strconcat.yml delete mode 100644 benchmark/app_tak.yml delete mode 100644 benchmark/app_tarai.yml delete mode 100644 benchmark/app_uri.yml delete mode 100644 benchmark/array_sample_100k_10.yml delete mode 100644 benchmark/array_sample_100k_11.yml delete mode 100644 benchmark/array_sample_100k__100.yml delete mode 100644 benchmark/array_sample_100k__1k.yml delete mode 100644 benchmark/array_sample_100k__6k.yml delete mode 100644 benchmark/array_sample_100k___10k.yml delete mode 100644 benchmark/array_sample_100k___50k.yml delete mode 100644 benchmark/array_shift.yml delete mode 100644 benchmark/array_small_and.yml delete mode 100644 benchmark/array_small_diff.yml delete mode 100644 benchmark/array_small_or.yml delete mode 100644 benchmark/array_sort_block.yml delete mode 100644 benchmark/array_sort_float.yml delete mode 100644 benchmark/array_values_at_int.yml delete mode 100644 benchmark/array_values_at_range.yml delete mode 100644 benchmark/bighash.yml create mode 100644 benchmark/bm_app_answer.rb create mode 100644 benchmark/bm_app_aobench.rb create mode 100644 benchmark/bm_app_erb.rb create mode 100644 benchmark/bm_app_factorial.rb create mode 100644 benchmark/bm_app_fib.rb create mode 100644 benchmark/bm_app_lc_fizzbuzz.rb create mode 100644 benchmark/bm_app_mandelbrot.rb create mode 100644 benchmark/bm_app_pentomino.rb create mode 100644 benchmark/bm_app_raise.rb create mode 100644 benchmark/bm_app_strconcat.rb create mode 100644 benchmark/bm_app_tak.rb create mode 100644 benchmark/bm_app_tarai.rb create mode 100644 benchmark/bm_app_uri.rb create mode 100644 benchmark/bm_array_sample_100k_10.rb create mode 100644 benchmark/bm_array_sample_100k_11.rb create mode 100644 benchmark/bm_array_sample_100k__100.rb create mode 100644 benchmark/bm_array_sample_100k__1k.rb create mode 100644 benchmark/bm_array_sample_100k__6k.rb create mode 100644 benchmark/bm_array_sample_100k___10k.rb create mode 100644 benchmark/bm_array_sample_100k___50k.rb create mode 100644 benchmark/bm_array_shift.rb create mode 100644 benchmark/bm_array_small_and.rb create mode 100644 benchmark/bm_array_small_diff.rb create mode 100644 benchmark/bm_array_small_or.rb create mode 100644 benchmark/bm_array_sort_block.rb create mode 100644 benchmark/bm_array_sort_float.rb create mode 100644 benchmark/bm_array_values_at_int.rb create mode 100644 benchmark/bm_array_values_at_range.rb create mode 100644 benchmark/bm_bighash.rb create mode 100644 benchmark/bm_dir_empty_p.rb create mode 100644 benchmark/bm_erb_render.rb create mode 100644 benchmark/bm_file_chmod.rb create mode 100644 benchmark/bm_file_rename.rb create mode 100644 benchmark/bm_hash_aref_dsym.rb create mode 100644 benchmark/bm_hash_aref_dsym_long.rb create mode 100644 benchmark/bm_hash_aref_fix.rb create mode 100644 benchmark/bm_hash_aref_flo.rb create mode 100644 benchmark/bm_hash_aref_miss.rb create mode 100644 benchmark/bm_hash_aref_str.rb create mode 100644 benchmark/bm_hash_aref_sym.rb create mode 100644 benchmark/bm_hash_aref_sym_long.rb create mode 100644 benchmark/bm_hash_flatten.rb create mode 100644 benchmark/bm_hash_ident_flo.rb create mode 100644 benchmark/bm_hash_ident_num.rb create mode 100644 benchmark/bm_hash_ident_obj.rb create mode 100644 benchmark/bm_hash_ident_str.rb create mode 100644 benchmark/bm_hash_ident_sym.rb create mode 100644 benchmark/bm_hash_keys.rb create mode 100644 benchmark/bm_hash_long.rb create mode 100644 benchmark/bm_hash_shift.rb create mode 100644 benchmark/bm_hash_shift_u16.rb create mode 100644 benchmark/bm_hash_shift_u24.rb create mode 100644 benchmark/bm_hash_shift_u32.rb create mode 100644 benchmark/bm_hash_small2.rb create mode 100644 benchmark/bm_hash_small4.rb create mode 100644 benchmark/bm_hash_small8.rb create mode 100644 benchmark/bm_hash_to_proc.rb create mode 100644 benchmark/bm_hash_values.rb create mode 100644 benchmark/bm_int_quo.rb create mode 100644 benchmark/bm_io_copy_stream_write.rb create mode 100644 benchmark/bm_io_copy_stream_write_socket.rb create mode 100644 benchmark/bm_io_file_create.rb create mode 100644 benchmark/bm_io_file_read.rb create mode 100644 benchmark/bm_io_file_write.rb create mode 100644 benchmark/bm_io_nonblock_noex.rb create mode 100644 benchmark/bm_io_nonblock_noex2.rb create mode 100644 benchmark/bm_io_pipe_rw.rb create mode 100644 benchmark/bm_io_select.rb create mode 100644 benchmark/bm_io_select2.rb create mode 100644 benchmark/bm_io_select3.rb create mode 100644 benchmark/bm_loop_for.rb create mode 100644 benchmark/bm_loop_generator.rb create mode 100644 benchmark/bm_loop_times.rb create mode 100644 benchmark/bm_loop_whileloop.rb create mode 100644 benchmark/bm_loop_whileloop2.rb create mode 100644 benchmark/bm_marshal_dump_flo.rb create mode 100644 benchmark/bm_marshal_dump_load_geniv.rb create mode 100644 benchmark/bm_marshal_dump_load_time.rb create mode 100644 benchmark/bm_securerandom.rb create mode 100644 benchmark/bm_so_ackermann.rb create mode 100644 benchmark/bm_so_array.rb create mode 100644 benchmark/bm_so_binary_trees.rb create mode 100644 benchmark/bm_so_concatenate.rb create mode 100644 benchmark/bm_so_exception.rb create mode 100644 benchmark/bm_so_fannkuch.rb create mode 100644 benchmark/bm_so_fasta.rb create mode 100644 benchmark/bm_so_lists.rb create mode 100644 benchmark/bm_so_mandelbrot.rb create mode 100644 benchmark/bm_so_matrix.rb create mode 100755 benchmark/bm_so_meteor_contest.rb create mode 100644 benchmark/bm_so_nbody.rb create mode 100644 benchmark/bm_so_nested_loop.rb create mode 100644 benchmark/bm_so_nsieve.rb create mode 100644 benchmark/bm_so_nsieve_bits.rb create mode 100644 benchmark/bm_so_object.rb create mode 100644 benchmark/bm_so_partial_sums.rb create mode 100644 benchmark/bm_so_pidigits.rb create mode 100644 benchmark/bm_so_random.rb create mode 100644 benchmark/bm_so_sieve.rb create mode 100644 benchmark/bm_so_spectralnorm.rb create mode 100644 benchmark/bm_string_index.rb create mode 100644 benchmark/bm_string_scan_re.rb create mode 100644 benchmark/bm_string_scan_str.rb create mode 100644 benchmark/bm_time_subsec.rb create mode 100644 benchmark/bm_vm3_backtrace.rb create mode 100644 benchmark/bm_vm3_clearmethodcache.rb create mode 100644 benchmark/bm_vm3_gc.rb create mode 100644 benchmark/bm_vm3_gc_old_full.rb create mode 100644 benchmark/bm_vm3_gc_old_immediate.rb create mode 100644 benchmark/bm_vm3_gc_old_lazy.rb create mode 100644 benchmark/bm_vm_symbol_block_pass.rb create mode 100644 benchmark/bm_vm_thread_alive_check1.rb create mode 100644 benchmark/bm_vm_thread_close.rb create mode 100644 benchmark/bm_vm_thread_condvar1.rb create mode 100644 benchmark/bm_vm_thread_condvar2.rb create mode 100644 benchmark/bm_vm_thread_create_join.rb create mode 100644 benchmark/bm_vm_thread_mutex1.rb create mode 100644 benchmark/bm_vm_thread_mutex2.rb create mode 100644 benchmark/bm_vm_thread_mutex3.rb create mode 100644 benchmark/bm_vm_thread_pass.rb create mode 100644 benchmark/bm_vm_thread_pass_flood.rb create mode 100644 benchmark/bm_vm_thread_pipe.rb create mode 100644 benchmark/bm_vm_thread_queue.rb create mode 100644 benchmark/bm_vm_thread_sized_queue.rb create mode 100644 benchmark/bm_vm_thread_sized_queue2.rb create mode 100644 benchmark/bm_vm_thread_sized_queue3.rb create mode 100644 benchmark/bm_vm_thread_sized_queue4.rb delete mode 100644 benchmark/dir_empty_p.yml delete mode 100644 benchmark/erb_render.yml delete mode 100644 benchmark/file_chmod.yml delete mode 100644 benchmark/file_rename.yml delete mode 100644 benchmark/hash_aref_dsym.yml delete mode 100644 benchmark/hash_aref_dsym_long.yml delete mode 100644 benchmark/hash_aref_fix.yml delete mode 100644 benchmark/hash_aref_flo.yml delete mode 100644 benchmark/hash_aref_miss.yml delete mode 100644 benchmark/hash_aref_str.yml delete mode 100644 benchmark/hash_aref_sym.yml delete mode 100644 benchmark/hash_aref_sym_long.yml delete mode 100644 benchmark/hash_flatten.yml delete mode 100644 benchmark/hash_ident_flo.yml delete mode 100644 benchmark/hash_ident_num.yml delete mode 100644 benchmark/hash_ident_obj.yml delete mode 100644 benchmark/hash_ident_str.yml delete mode 100644 benchmark/hash_ident_sym.yml delete mode 100644 benchmark/hash_keys.yml delete mode 100644 benchmark/hash_long.yml delete mode 100644 benchmark/hash_shift.yml delete mode 100644 benchmark/hash_shift_u16.yml delete mode 100644 benchmark/hash_shift_u24.yml delete mode 100644 benchmark/hash_shift_u32.yml delete mode 100644 benchmark/hash_small2.yml delete mode 100644 benchmark/hash_small4.yml delete mode 100644 benchmark/hash_small8.yml delete mode 100644 benchmark/hash_to_proc.yml delete mode 100644 benchmark/hash_values.yml delete mode 100644 benchmark/int_quo.yml delete mode 100644 benchmark/io_copy_stream_write.yml delete mode 100644 benchmark/io_copy_stream_write_socket.yml delete mode 100644 benchmark/io_file_create.yml delete mode 100644 benchmark/io_file_read.yml delete mode 100644 benchmark/io_file_write.yml delete mode 100644 benchmark/io_nonblock_noex.yml delete mode 100644 benchmark/io_nonblock_noex2.yml delete mode 100644 benchmark/io_pipe_rw.yml delete mode 100644 benchmark/io_select.yml delete mode 100644 benchmark/io_select2.yml delete mode 100644 benchmark/io_select3.yml delete mode 100644 benchmark/loop_for.yml delete mode 100644 benchmark/loop_generator.yml delete mode 100644 benchmark/loop_times.yml delete mode 100644 benchmark/loop_whileloop.yml delete mode 100644 benchmark/loop_whileloop2.yml delete mode 100644 benchmark/marshal_dump_flo.yml delete mode 100644 benchmark/marshal_dump_load_geniv.yml delete mode 100644 benchmark/marshal_dump_load_time.yml delete mode 100644 benchmark/securerandom.yml delete mode 100644 benchmark/so_ackermann.yml delete mode 100644 benchmark/so_array.yml delete mode 100644 benchmark/so_binary_trees.yml delete mode 100644 benchmark/so_concatenate.yml delete mode 100644 benchmark/so_exception.yml delete mode 100644 benchmark/so_fannkuch.yml delete mode 100644 benchmark/so_fasta.yml delete mode 100644 benchmark/so_lists.yml delete mode 100644 benchmark/so_mandelbrot.yml delete mode 100644 benchmark/so_matrix.yml delete mode 100644 benchmark/so_meteor_contest.yml delete mode 100644 benchmark/so_nbody.yml delete mode 100644 benchmark/so_nested_loop.yml delete mode 100644 benchmark/so_nsieve.yml delete mode 100644 benchmark/so_nsieve_bits.yml delete mode 100644 benchmark/so_object.yml delete mode 100644 benchmark/so_partial_sums.yml delete mode 100644 benchmark/so_pidigits.yml delete mode 100644 benchmark/so_random.yml delete mode 100644 benchmark/so_sieve.yml delete mode 100644 benchmark/so_spectralnorm.yml delete mode 100644 benchmark/string_index.yml delete mode 100644 benchmark/string_scan_re.yml delete mode 100644 benchmark/string_scan_str.yml delete mode 100644 benchmark/time_subsec.yml delete mode 100644 benchmark/vm3_backtrace.yml delete mode 100644 benchmark/vm3_clearmethodcache.yml delete mode 100644 benchmark/vm3_gc.yml delete mode 100644 benchmark/vm3_gc_old_full.yml delete mode 100644 benchmark/vm3_gc_old_immediate.yml delete mode 100644 benchmark/vm3_gc_old_lazy.yml delete mode 100644 benchmark/vm_symbol_block_pass.yml delete mode 100644 benchmark/vm_thread_alive_check1.yml delete mode 100644 benchmark/vm_thread_close.yml delete mode 100644 benchmark/vm_thread_condvar1.yml delete mode 100644 benchmark/vm_thread_condvar2.yml delete mode 100644 benchmark/vm_thread_create_join.yml delete mode 100644 benchmark/vm_thread_mutex1.yml delete mode 100644 benchmark/vm_thread_mutex2.yml delete mode 100644 benchmark/vm_thread_mutex3.yml delete mode 100644 benchmark/vm_thread_pass.yml delete mode 100644 benchmark/vm_thread_pass_flood.yml delete mode 100644 benchmark/vm_thread_pipe.yml delete mode 100644 benchmark/vm_thread_queue.yml delete mode 100644 benchmark/vm_thread_sized_queue.yml delete mode 100644 benchmark/vm_thread_sized_queue2.yml delete mode 100644 benchmark/vm_thread_sized_queue3.yml delete mode 100644 benchmark/vm_thread_sized_queue4.yml (limited to 'benchmark') diff --git a/benchmark/README.md b/benchmark/README.md index 013de7904c..018198b4b5 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -37,8 +37,8 @@ make benchmark ITEM=vm1 # Run some limited benchmarks in ITEM-matched files make benchmark ITEM=vm1 OPTS=--filter=block -# You can specify the benchmark by an exact filename instead of using -# the default argument: ARGS=$(srcdir)/benchmark/*$(ITEM)*.yml +# You can specify the benchmark by an exact filename instead of using the default argument: +# ARGS = $$(find $(srcdir)/benchmark -maxdepth 1 -name '*$(ITEM)*.yml' -o -name '*$(ITEM)*.rb') make benchmark ARGS=../benchmark/erb_render.yml # You can specify any option via $OPTS diff --git a/benchmark/app_answer.yml b/benchmark/app_answer.yml deleted file mode 100644 index ad6bf3be16..0000000000 --- a/benchmark/app_answer.yml +++ /dev/null @@ -1,18 +0,0 @@ -benchmark: - app_answer: | - def ack(m, n) - if m == 0 then - n + 1 - elsif n == 0 then - ack(m - 1, 1) - else - ack(m - 1, ack(m, n - 1)) - end - end - - def the_answer_to_life_the_universe_and_everything - (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i - end - - answer = the_answer_to_life_the_universe_and_everything -loop_count: 1 diff --git a/benchmark/app_aobench.yml b/benchmark/app_aobench.yml deleted file mode 100644 index 5479d0a421..0000000000 --- a/benchmark/app_aobench.yml +++ /dev/null @@ -1,295 +0,0 @@ -prelude: | - # AO render benchmark - # Original program (C) Syoyo Fujita in Javascript (and other languages) - # https://code.google.com/p/aobench/ - # Ruby(yarv2llvm) version by Hideki Miura -benchmark: - app_aobench: | - # - - IMAGE_WIDTH = 256 - IMAGE_HEIGHT = 256 - NSUBSAMPLES = 2 - NAO_SAMPLES = 8 - - class Vec - def initialize(x, y, z) - @x = x - @y = y - @z = z - end - - attr_accessor :x, :y, :z - - def vadd(b) - Vec.new(@x + b.x, @y + b.y, @z + b.z) - end - - def vsub(b) - Vec.new(@x - b.x, @y - b.y, @z - b.z) - end - - def vcross(b) - Vec.new(@y * b.z - @z * b.y, - @z * b.x - @x * b.z, - @x * b.y - @y * b.x) - end - - def vdot(b) - @x * b.x + @y * b.y + @z * b.z - end - - def vlength - Math.sqrt(@x * @x + @y * @y + @z * @z) - end - - def vnormalize - len = vlength - v = Vec.new(@x, @y, @z) - if len > 1.0e-17 then - v.x = v.x / len - v.y = v.y / len - v.z = v.z / len - end - v - end - end - - - class Sphere - def initialize(center, radius) - @center = center - @radius = radius - end - - attr_reader :center, :radius - - def intersect(ray, isect) - rs = ray.org.vsub(@center) - b = rs.vdot(ray.dir) - c = rs.vdot(rs) - (@radius * @radius) - d = b * b - c - if d > 0.0 then - t = - b - Math.sqrt(d) - - if t > 0.0 and t < isect.t then - isect.t = t - isect.hit = true - isect.pl = Vec.new(ray.org.x + ray.dir.x * t, - ray.org.y + ray.dir.y * t, - ray.org.z + ray.dir.z * t) - n = isect.pl.vsub(@center) - isect.n = n.vnormalize - else - 0.0 - end - end - nil - end - end - - class Plane - def initialize(p, n) - @p = p - @n = n - end - - def intersect(ray, isect) - d = -@p.vdot(@n) - v = ray.dir.vdot(@n) - v0 = v - if v < 0.0 then - v0 = -v - end - if v0 < 1.0e-17 then - return - end - - t = -(ray.org.vdot(@n) + d) / v - - if t > 0.0 and t < isect.t then - isect.hit = true - isect.t = t - isect.n = @n - isect.pl = Vec.new(ray.org.x + t * ray.dir.x, - ray.org.y + t * ray.dir.y, - ray.org.z + t * ray.dir.z) - end - nil - end - end - - class Ray - def initialize(org, dir) - @org = org - @dir = dir - end - - attr_accessor :org, :dir - end - - class Isect - def initialize - @t = 10000000.0 - @hit = false - @pl = Vec.new(0.0, 0.0, 0.0) - @n = Vec.new(0.0, 0.0, 0.0) - end - - attr_accessor :t, :hit, :pl, :n - end - - def clamp(f) - i = f * 255.5 - if i > 255.0 then - i = 255.0 - end - if i < 0.0 then - i = 0.0 - end - i.to_i - end - - def otherBasis(basis, n) - basis[2] = Vec.new(n.x, n.y, n.z) - basis[1] = Vec.new(0.0, 0.0, 0.0) - - if n.x < 0.6 and n.x > -0.6 then - basis[1].x = 1.0 - elsif n.y < 0.6 and n.y > -0.6 then - basis[1].y = 1.0 - elsif n.z < 0.6 and n.z > -0.6 then - basis[1].z = 1.0 - else - basis[1].x = 1.0 - end - - basis[0] = basis[1].vcross(basis[2]) - basis[0] = basis[0].vnormalize - - basis[1] = basis[2].vcross(basis[0]) - basis[1] = basis[1].vnormalize - end - - class Scene - def initialize - @spheres = Array.new - @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5) - @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5) - @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5) - @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0)) - end - - def ambient_occlusion(isect) - basis = Array.new - otherBasis(basis, isect.n) - - ntheta = NAO_SAMPLES - nphi = NAO_SAMPLES - eps = 0.0001 - occlusion = 0.0 - - p0 = Vec.new(isect.pl.x + eps * isect.n.x, - isect.pl.y + eps * isect.n.y, - isect.pl.z + eps * isect.n.z) - nphi.times do |j| - ntheta.times do |i| - r = rand - phi = 2.0 * 3.14159265 * rand - x = Math.cos(phi) * Math.sqrt(1.0 - r) - y = Math.sin(phi) * Math.sqrt(1.0 - r) - z = Math.sqrt(r) - - rx = x * basis[0].x + y * basis[1].x + z * basis[2].x - ry = x * basis[0].y + y * basis[1].y + z * basis[2].y - rz = x * basis[0].z + y * basis[1].z + z * basis[2].z - - raydir = Vec.new(rx, ry, rz) - ray = Ray.new(p0, raydir) - - occisect = Isect.new - @spheres[0].intersect(ray, occisect) - @spheres[1].intersect(ray, occisect) - @spheres[2].intersect(ray, occisect) - @plane.intersect(ray, occisect) - if occisect.hit then - occlusion = occlusion + 1.0 - else - 0.0 - end - end - end - - occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f) - - Vec.new(occlusion, occlusion, occlusion) - end - - def render(w, h, nsubsamples) - cnt = 0 - nsf = nsubsamples.to_f - h.times do |y| - w.times do |x| - rad = Vec.new(0.0, 0.0, 0.0) - - # Subsampling - nsubsamples.times do |v| - nsubsamples.times do |u| - - cnt = cnt + 1 - wf = w.to_f - hf = h.to_f - xf = x.to_f - yf = y.to_f - uf = u.to_f - vf = v.to_f - - px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0) - py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0) - - eye = Vec.new(px, py, -1.0).vnormalize - - ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye) - - isect = Isect.new - @spheres[0].intersect(ray, isect) - @spheres[1].intersect(ray, isect) - @spheres[2].intersect(ray, isect) - @plane.intersect(ray, isect) - if isect.hit then - col = ambient_occlusion(isect) - rad.x = rad.x + col.x - rad.y = rad.y + col.y - rad.z = rad.z + col.z - end - end - end - - r = rad.x / (nsf * nsf) - g = rad.y / (nsf * nsf) - b = rad.z / (nsf * nsf) - printf("%c", clamp(r)) - printf("%c", clamp(g)) - printf("%c", clamp(b)) - end - nil - end - - nil - end - end - - alias printf_orig printf - def printf *args - end - - # File.open("ao.ppm", "w") do |fp| - printf("P6\n") - printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT) - printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT) - Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES) - # end - - undef printf - alias printf printf_orig -loop_count: 1 diff --git a/benchmark/app_erb.yml b/benchmark/app_erb.yml deleted file mode 100644 index df0630585f..0000000000 --- a/benchmark/app_erb.yml +++ /dev/null @@ -1,28 +0,0 @@ -benchmark: - app_erb: | - # - # Create many HTML strings with ERB. - # - - require 'erb' - - data = < - <%= title %> - -

<%= title %>

-

- <%= content %> -

- - - erb - - max = 15_000 - title = "hello world!" - content = "hello world!\n" * 10 - - max.times{ - ERB.new(data).result(binding) - } -loop_count: 1 diff --git a/benchmark/app_factorial.yml b/benchmark/app_factorial.yml deleted file mode 100644 index 9db58e1a3c..0000000000 --- a/benchmark/app_factorial.yml +++ /dev/null @@ -1,14 +0,0 @@ -benchmark: - app_factorial: | - def fact(n) - if(n > 1) - n * fact(n-1) - else - 1 - end - end - - 100.times { - fact(5000) - } -loop_count: 1 diff --git a/benchmark/app_fib.yml b/benchmark/app_fib.yml deleted file mode 100644 index d1c6671e9d..0000000000 --- a/benchmark/app_fib.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - app_fib: | - def fib n - if n < 3 - 1 - else - fib(n-1) + fib(n-2) - end - end - - fib(34) -loop_count: 1 diff --git a/benchmark/app_lc_fizzbuzz.yml b/benchmark/app_lc_fizzbuzz.yml deleted file mode 100644 index e17024c87b..0000000000 --- a/benchmark/app_lc_fizzbuzz.yml +++ /dev/null @@ -1,55 +0,0 @@ -benchmark: - app_lc_fizzbuzz: | - # - # FizzBuzz program using only lambda calculus - # - # This program is quoted from - # "Understanding Computation" by Tom Stuart - # http://computationbook.com/ - # - # You can understand why this program works fine by reading this book. - # - - solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }] - - FIRST = -> l { LEFT[RIGHT[l]] } - IF = -> b { b } - LEFT = -> p { p[-> x { -> y { x } } ] } - RIGHT = -> p { p[-> x { -> y { y } } ] } - IS_EMPTY = LEFT - REST = -> l { RIGHT[RIGHT[l]] } - - def to_integer(proc) - proc[-> n { n + 1 }][0] - end - - def to_boolean(proc) - IF[proc][true][false] - end - - def to_array(proc) - array = [] - - until to_boolean(IS_EMPTY[proc]) - array.push(FIRST[proc]) - proc = REST[proc] - end - - array - end - - def to_char(c) - '0123456789BFiuz'.slice(to_integer(c)) - end - - def to_string(s) - to_array(s).map { |c| to_char(c) }.join - end - - answer = to_array(solution).map do |p| - to_string(p) - end - - answer_ary = answer.to_a - # puts answer_ary -loop_count: 1 diff --git a/benchmark/app_mandelbrot.yml b/benchmark/app_mandelbrot.yml deleted file mode 100644 index d0ec9db010..0000000000 --- a/benchmark/app_mandelbrot.yml +++ /dev/null @@ -1,25 +0,0 @@ -benchmark: - app_mandelbrot: | - require 'complex' - - def mandelbrot? z - i = 0 - while i<100 - i += 1 - z = z * z - return false if z.abs > 2 - end - true - end - - ary = [] - - (0..1000).each{|dx| - (0..1000).each{|dy| - x = dx / 50.0 - y = dy / 50.0 - c = Complex(x, y) - ary << c if mandelbrot?(c) - } - } -loop_count: 1 diff --git a/benchmark/app_pentomino.yml b/benchmark/app_pentomino.yml deleted file mode 100644 index ab6e19bf1a..0000000000 --- a/benchmark/app_pentomino.yml +++ /dev/null @@ -1,130 +0,0 @@ -benchmark: - app_pentomino: | - # This program is contributed by Shin Nishiyama - # modified by K.Sasada - - NP = 5 - ROW = 8 + NP - COL = 8 - - $p = [] - $b = [] - $no = 0 - - def piece(n, a, nb) - nb.each{|x| - a[n] = x - if n == NP-1 - $p << [a.sort] - else - nbc=nb.dup - [-ROW, -1, 1, ROW].each{|d| - if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) - nbc << x+d - end - } - nbc.delete x - piece(n+1,a[0..n],nbc) - end - } - end - - def kikaku(a) - a.collect {|x| x - a[0]} - end - def ud(a) - kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) - end - def rl(a) - kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) - end - def xy(a) - kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) - end - - def mkpieces - piece(0,[],[0]) - $p.each do |a| - a0 = a[0] - a[1] = ud(a0) - a[2] = rl(a0) - a[3] = ud(rl(a0)) - a[4] = xy(a0) - a[5] = ud(xy(a0)) - a[6] = rl(xy(a0)) - a[7] = ud(rl(xy(a0))) - a.sort! - a.uniq! - end - $p.uniq!.sort! {|x,y| x[0] <=> y[0] } - end - - def mkboard - (0...ROW*COL).each{|i| - if i % ROW >= ROW-NP - $b[i] = -2 - else - $b[i] = -1 - end - $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 - } - end - - def pboard - return # skip print - print "No. #$no\n" - (0...COL).each{|i| - print "|" - (0...ROW-NP).each{|j| - x = $b[i*ROW+j] - if x < 0 - print "..|" - else - printf "%2d|",x+1 - end - } - print "\n" - } - print "\n" - end - - $pnum=[] - def setpiece(a,pos) - if a.length == $p.length then - $no += 1 - pboard - return - end - while $b[pos] != -1 - pos += 1 - end - ($pnum - a).each do |i| - $p[i].each do |x| - f = 0 - x.each{|s| - if $b[pos+s] != -1 - f=1 - break - end - } - if f == 0 then - x.each{|s| - $b[pos+s] = i - } - a << i - setpiece(a.dup, pos) - a.pop - x.each{|s| - $b[pos+s] = -1 - } - end - end - end - end - - mkpieces - mkboard - $p[4] = [$p[4][0]] - $pnum = (0...$p.length).to_a - setpiece([],0) -loop_count: 1 diff --git a/benchmark/app_raise.yml b/benchmark/app_raise.yml deleted file mode 100644 index 3b7826c34f..0000000000 --- a/benchmark/app_raise.yml +++ /dev/null @@ -1,11 +0,0 @@ -benchmark: - app_raise: | - i = 0 - while i<300000 - i += 1 - begin - raise - rescue - end - end -loop_count: 1 diff --git a/benchmark/app_strconcat.yml b/benchmark/app_strconcat.yml deleted file mode 100644 index 2762bf4aa2..0000000000 --- a/benchmark/app_strconcat.yml +++ /dev/null @@ -1,8 +0,0 @@ -benchmark: - app_strconcat: | - i = 0 - while i<2_000_000 - "#{1+1} #{1+1} #{1+1}" - i += 1 - end -loop_count: 1 diff --git a/benchmark/app_tak.yml b/benchmark/app_tak.yml deleted file mode 100644 index 0b67558b32..0000000000 --- a/benchmark/app_tak.yml +++ /dev/null @@ -1,15 +0,0 @@ -benchmark: - app_tak: | - - def tak x, y, z - unless y < x - z - else - tak( tak(x-1, y, z), - tak(y-1, z, x), - tak(z-1, x, y)) - end - end - - tak(18, 9, 0) -loop_count: 1 diff --git a/benchmark/app_tarai.yml b/benchmark/app_tarai.yml deleted file mode 100644 index 1f53db68a0..0000000000 --- a/benchmark/app_tarai.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - app_tarai: | - def tarai( x, y, z ) - if x <= y - then y - else tarai(tarai(x-1, y, z), - tarai(y-1, z, x), - tarai(z-1, x, y)) - end - end - - tarai(12, 6, 0) -loop_count: 1 diff --git a/benchmark/app_uri.yml b/benchmark/app_uri.yml deleted file mode 100644 index 1f7e49de51..0000000000 --- a/benchmark/app_uri.yml +++ /dev/null @@ -1,11 +0,0 @@ -benchmark: - app_uri: | - require 'uri' - - 100_000.times{ - uri = URI.parse('http://www.ruby-lang.org') - uri.scheme - uri.host - uri.port - } -loop_count: 1 diff --git a/benchmark/array_sample_100k_10.yml b/benchmark/array_sample_100k_10.yml deleted file mode 100644 index 043e2fdf1c..0000000000 --- a/benchmark/array_sample_100k_10.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k_10: | - arr = [*0...100000] - 10_000.times {arr.sample 10} -loop_count: 1 diff --git a/benchmark/array_sample_100k_11.yml b/benchmark/array_sample_100k_11.yml deleted file mode 100644 index 0072c46930..0000000000 --- a/benchmark/array_sample_100k_11.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k_11: | - arr = [*0...100000] - 10_000.times {arr.sample 11} -loop_count: 1 diff --git a/benchmark/array_sample_100k__100.yml b/benchmark/array_sample_100k__100.yml deleted file mode 100644 index 93d25b3053..0000000000 --- a/benchmark/array_sample_100k__100.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k__100: | - arr = [*0...100000] - 10_000.times {arr.sample 100} -loop_count: 1 diff --git a/benchmark/array_sample_100k__1k.yml b/benchmark/array_sample_100k__1k.yml deleted file mode 100644 index a6a66ef5dc..0000000000 --- a/benchmark/array_sample_100k__1k.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k__1k: | - arr = [*0...100000] - 10_000.times {arr.sample 1000} -loop_count: 1 diff --git a/benchmark/array_sample_100k__6k.yml b/benchmark/array_sample_100k__6k.yml deleted file mode 100644 index 438a345b8f..0000000000 --- a/benchmark/array_sample_100k__6k.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k__6k: | - arr = [*0...100000] - 10_000.times {arr.sample 6000} -loop_count: 1 diff --git a/benchmark/array_sample_100k___10k.yml b/benchmark/array_sample_100k___10k.yml deleted file mode 100644 index 13da9ccd83..0000000000 --- a/benchmark/array_sample_100k___10k.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k___10k: | - arr = [*0...100000] - 10_000.times {arr.sample 10_000} -loop_count: 1 diff --git a/benchmark/array_sample_100k___50k.yml b/benchmark/array_sample_100k___50k.yml deleted file mode 100644 index 579312dc3f..0000000000 --- a/benchmark/array_sample_100k___50k.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sample_100k___50k: | - arr = [*0...100000] - 10_000.times {arr.sample 50_000} -loop_count: 1 diff --git a/benchmark/array_shift.yml b/benchmark/array_shift.yml deleted file mode 100644 index 713c542024..0000000000 --- a/benchmark/array_shift.yml +++ /dev/null @@ -1,17 +0,0 @@ -benchmark: - array_shift: | - require 'benchmark' - - Benchmark.bm do |x| - [10_000,1_000_000,100_000_000].each do |n| - ary = Array.new(n,0) - GC.start - x.report("#{n}:shift"){ ary.shift } - (0..4).each do |i| - ary = Array.new(n,0) - GC.start - x.report("#{n}:shift(#{i})"){ ary.shift(i) } - end - end - end -loop_count: 1 diff --git a/benchmark/array_small_and.yml b/benchmark/array_small_and.yml deleted file mode 100644 index 34d2e8ff58..0000000000 --- a/benchmark/array_small_and.yml +++ /dev/null @@ -1,20 +0,0 @@ -benchmark: - array_small_and: | - MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i - MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i - ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i - - ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| - (MIN_SIZE..MAX_SIZE).map do |size2| - [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] - end - end - - ITERATIONS.times do - ARRAYS.each do |group| - group.each do |arr1, arr2| - arr1 & arr2 - end - end - end -loop_count: 1 diff --git a/benchmark/array_small_diff.yml b/benchmark/array_small_diff.yml deleted file mode 100644 index 64710e96bf..0000000000 --- a/benchmark/array_small_diff.yml +++ /dev/null @@ -1,20 +0,0 @@ -benchmark: - array_small_diff: | - MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i - MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i - ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i - - ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| - (MIN_SIZE..MAX_SIZE).map do |size2| - [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] - end - end - - ITERATIONS.times do - ARRAYS.each do |group| - group.each do |arr1, arr2| - arr1 - arr2 - end - end - end -loop_count: 1 diff --git a/benchmark/array_small_or.yml b/benchmark/array_small_or.yml deleted file mode 100644 index 9338bd5dbd..0000000000 --- a/benchmark/array_small_or.yml +++ /dev/null @@ -1,20 +0,0 @@ -benchmark: - array_small_or: | - MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i - MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i - ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i - - ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| - (MIN_SIZE..MAX_SIZE).map do |size2| - [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] - end - end - - ITERATIONS.times do - ARRAYS.each do |group| - group.each do |arr1, arr2| - arr1 | arr2 - end - end - end -loop_count: 1 diff --git a/benchmark/array_sort_block.yml b/benchmark/array_sort_block.yml deleted file mode 100644 index 775db90f4b..0000000000 --- a/benchmark/array_sort_block.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sort_block: | - ary = Array.new(1000) { rand(1000) } - 10000.times { ary.sort { |a, b| a <=> b } } -loop_count: 1 diff --git a/benchmark/array_sort_float.yml b/benchmark/array_sort_float.yml deleted file mode 100644 index 2aa2bd5fec..0000000000 --- a/benchmark/array_sort_float.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_sort_float: | - arr = Array.new(1000) { rand } - 10000.times { arr.sort } -loop_count: 1 diff --git a/benchmark/array_values_at_int.yml b/benchmark/array_values_at_int.yml deleted file mode 100644 index 48bb0f7492..0000000000 --- a/benchmark/array_values_at_int.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_values_at_int: | - ary = Array.new(10000) {|i| i} - 100000.times { ary.values_at(500) } -loop_count: 1 diff --git a/benchmark/array_values_at_range.yml b/benchmark/array_values_at_range.yml deleted file mode 100644 index 9de66261bb..0000000000 --- a/benchmark/array_values_at_range.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - array_values_at_range: | - ary = Array.new(10000) {|i| i} - 100000.times { ary.values_at(1..2000) } -loop_count: 1 diff --git a/benchmark/bighash.yml b/benchmark/bighash.yml deleted file mode 100644 index 65d74049e7..0000000000 --- a/benchmark/bighash.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - bighash: | - h = {}; 5000000.times {|n| h[n] = n } -loop_count: 1 diff --git a/benchmark/bm_app_answer.rb b/benchmark/bm_app_answer.rb new file mode 100644 index 0000000000..3cd8a8fd37 --- /dev/null +++ b/benchmark/bm_app_answer.rb @@ -0,0 +1,15 @@ +def ack(m, n) + if m == 0 then + n + 1 + elsif n == 0 then + ack(m - 1, 1) + else + ack(m - 1, ack(m, n - 1)) + end +end + +def the_answer_to_life_the_universe_and_everything + (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i +end + +answer = the_answer_to_life_the_universe_and_everything diff --git a/benchmark/bm_app_aobench.rb b/benchmark/bm_app_aobench.rb new file mode 100644 index 0000000000..2bd6acfaf8 --- /dev/null +++ b/benchmark/bm_app_aobench.rb @@ -0,0 +1,291 @@ +# AO render benchmark +# Original program (C) Syoyo Fujita in Javascript (and other languages) +# https://code.google.com/p/aobench/ +# Ruby(yarv2llvm) version by Hideki Miura +# + +IMAGE_WIDTH = 256 +IMAGE_HEIGHT = 256 +NSUBSAMPLES = 2 +NAO_SAMPLES = 8 + +class Vec + def initialize(x, y, z) + @x = x + @y = y + @z = z + end + + attr_accessor :x, :y, :z + + def vadd(b) + Vec.new(@x + b.x, @y + b.y, @z + b.z) + end + + def vsub(b) + Vec.new(@x - b.x, @y - b.y, @z - b.z) + end + + def vcross(b) + Vec.new(@y * b.z - @z * b.y, + @z * b.x - @x * b.z, + @x * b.y - @y * b.x) + end + + def vdot(b) + @x * b.x + @y * b.y + @z * b.z + end + + def vlength + Math.sqrt(@x * @x + @y * @y + @z * @z) + end + + def vnormalize + len = vlength + v = Vec.new(@x, @y, @z) + if len > 1.0e-17 then + v.x = v.x / len + v.y = v.y / len + v.z = v.z / len + end + v + end +end + + +class Sphere + def initialize(center, radius) + @center = center + @radius = radius + end + + attr_reader :center, :radius + + def intersect(ray, isect) + rs = ray.org.vsub(@center) + b = rs.vdot(ray.dir) + c = rs.vdot(rs) - (@radius * @radius) + d = b * b - c + if d > 0.0 then + t = - b - Math.sqrt(d) + + if t > 0.0 and t < isect.t then + isect.t = t + isect.hit = true + isect.pl = Vec.new(ray.org.x + ray.dir.x * t, + ray.org.y + ray.dir.y * t, + ray.org.z + ray.dir.z * t) + n = isect.pl.vsub(@center) + isect.n = n.vnormalize + else + 0.0 + end + end + nil + end +end + +class Plane + def initialize(p, n) + @p = p + @n = n + end + + def intersect(ray, isect) + d = -@p.vdot(@n) + v = ray.dir.vdot(@n) + v0 = v + if v < 0.0 then + v0 = -v + end + if v0 < 1.0e-17 then + return + end + + t = -(ray.org.vdot(@n) + d) / v + + if t > 0.0 and t < isect.t then + isect.hit = true + isect.t = t + isect.n = @n + isect.pl = Vec.new(ray.org.x + t * ray.dir.x, + ray.org.y + t * ray.dir.y, + ray.org.z + t * ray.dir.z) + end + nil + end +end + +class Ray + def initialize(org, dir) + @org = org + @dir = dir + end + + attr_accessor :org, :dir +end + +class Isect + def initialize + @t = 10000000.0 + @hit = false + @pl = Vec.new(0.0, 0.0, 0.0) + @n = Vec.new(0.0, 0.0, 0.0) + end + + attr_accessor :t, :hit, :pl, :n +end + +def clamp(f) + i = f * 255.5 + if i > 255.0 then + i = 255.0 + end + if i < 0.0 then + i = 0.0 + end + i.to_i +end + +def otherBasis(basis, n) + basis[2] = Vec.new(n.x, n.y, n.z) + basis[1] = Vec.new(0.0, 0.0, 0.0) + + if n.x < 0.6 and n.x > -0.6 then + basis[1].x = 1.0 + elsif n.y < 0.6 and n.y > -0.6 then + basis[1].y = 1.0 + elsif n.z < 0.6 and n.z > -0.6 then + basis[1].z = 1.0 + else + basis[1].x = 1.0 + end + + basis[0] = basis[1].vcross(basis[2]) + basis[0] = basis[0].vnormalize + + basis[1] = basis[2].vcross(basis[0]) + basis[1] = basis[1].vnormalize +end + +class Scene + def initialize + @spheres = Array.new + @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5) + @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5) + @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5) + @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0)) + end + + def ambient_occlusion(isect) + basis = Array.new + otherBasis(basis, isect.n) + + ntheta = NAO_SAMPLES + nphi = NAO_SAMPLES + eps = 0.0001 + occlusion = 0.0 + + p0 = Vec.new(isect.pl.x + eps * isect.n.x, + isect.pl.y + eps * isect.n.y, + isect.pl.z + eps * isect.n.z) + nphi.times do |j| + ntheta.times do |i| + r = rand + phi = 2.0 * 3.14159265 * rand + x = Math.cos(phi) * Math.sqrt(1.0 - r) + y = Math.sin(phi) * Math.sqrt(1.0 - r) + z = Math.sqrt(r) + + rx = x * basis[0].x + y * basis[1].x + z * basis[2].x + ry = x * basis[0].y + y * basis[1].y + z * basis[2].y + rz = x * basis[0].z + y * basis[1].z + z * basis[2].z + + raydir = Vec.new(rx, ry, rz) + ray = Ray.new(p0, raydir) + + occisect = Isect.new + @spheres[0].intersect(ray, occisect) + @spheres[1].intersect(ray, occisect) + @spheres[2].intersect(ray, occisect) + @plane.intersect(ray, occisect) + if occisect.hit then + occlusion = occlusion + 1.0 + else + 0.0 + end + end + end + + occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f) + + Vec.new(occlusion, occlusion, occlusion) + end + + def render(w, h, nsubsamples) + cnt = 0 + nsf = nsubsamples.to_f + h.times do |y| + w.times do |x| + rad = Vec.new(0.0, 0.0, 0.0) + + # Subsampling + nsubsamples.times do |v| + nsubsamples.times do |u| + + cnt = cnt + 1 + wf = w.to_f + hf = h.to_f + xf = x.to_f + yf = y.to_f + uf = u.to_f + vf = v.to_f + + px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0) + py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0) + + eye = Vec.new(px, py, -1.0).vnormalize + + ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye) + + isect = Isect.new + @spheres[0].intersect(ray, isect) + @spheres[1].intersect(ray, isect) + @spheres[2].intersect(ray, isect) + @plane.intersect(ray, isect) + if isect.hit then + col = ambient_occlusion(isect) + rad.x = rad.x + col.x + rad.y = rad.y + col.y + rad.z = rad.z + col.z + end + end + end + + r = rad.x / (nsf * nsf) + g = rad.y / (nsf * nsf) + b = rad.z / (nsf * nsf) + printf("%c", clamp(r)) + printf("%c", clamp(g)) + printf("%c", clamp(b)) + end + nil + end + + nil + end +end + +alias printf_orig printf +def printf *args +end + +# File.open("ao.ppm", "w") do |fp| + printf("P6\n") + printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT) + printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT) + Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES) +# end + +undef printf +alias printf printf_orig diff --git a/benchmark/bm_app_erb.rb b/benchmark/bm_app_erb.rb new file mode 100644 index 0000000000..9a1cb2707f --- /dev/null +++ b/benchmark/bm_app_erb.rb @@ -0,0 +1,25 @@ +# +# Create many HTML strings with ERB. +# + +require 'erb' + +data = < + <%= title %> + +

<%= title %>

+

+ <%= content %> +

+ + +erb + +max = 15_000 +title = "hello world!" +content = "hello world!\n" * 10 + +max.times{ + ERB.new(data).result(binding) +} diff --git a/benchmark/bm_app_factorial.rb b/benchmark/bm_app_factorial.rb new file mode 100644 index 0000000000..45f471dfdb --- /dev/null +++ b/benchmark/bm_app_factorial.rb @@ -0,0 +1,11 @@ +def fact(n) + if(n > 1) + n * fact(n-1) + else + 1 + end +end + +100.times { + fact(5000) +} diff --git a/benchmark/bm_app_fib.rb b/benchmark/bm_app_fib.rb new file mode 100644 index 0000000000..34a7b2e725 --- /dev/null +++ b/benchmark/bm_app_fib.rb @@ -0,0 +1,10 @@ +def fib n + if n < 3 + 1 + else + fib(n-1) + fib(n-2) + end +end + +fib(34) + diff --git a/benchmark/bm_app_lc_fizzbuzz.rb b/benchmark/bm_app_lc_fizzbuzz.rb new file mode 100644 index 0000000000..f09574bbeb --- /dev/null +++ b/benchmark/bm_app_lc_fizzbuzz.rb @@ -0,0 +1,52 @@ +# +# FizzBuzz program using only lambda calculus +# +# This program is quoted from +# "Understanding Computation" by Tom Stuart +# http://computationbook.com/ +# +# You can understand why this program works fine by reading this book. +# + +solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }] + +FIRST = -> l { LEFT[RIGHT[l]] } +IF = -> b { b } +LEFT = -> p { p[-> x { -> y { x } } ] } +RIGHT = -> p { p[-> x { -> y { y } } ] } +IS_EMPTY = LEFT +REST = -> l { RIGHT[RIGHT[l]] } + +def to_integer(proc) + proc[-> n { n + 1 }][0] +end + +def to_boolean(proc) + IF[proc][true][false] +end + +def to_array(proc) + array = [] + + until to_boolean(IS_EMPTY[proc]) + array.push(FIRST[proc]) + proc = REST[proc] + end + + array +end + +def to_char(c) + '0123456789BFiuz'.slice(to_integer(c)) +end + +def to_string(s) + to_array(s).map { |c| to_char(c) }.join +end + +answer = to_array(solution).map do |p| + to_string(p) +end + +answer_ary = answer.to_a +# puts answer_ary diff --git a/benchmark/bm_app_mandelbrot.rb b/benchmark/bm_app_mandelbrot.rb new file mode 100644 index 0000000000..801b75e8e2 --- /dev/null +++ b/benchmark/bm_app_mandelbrot.rb @@ -0,0 +1,23 @@ +require 'complex' + +def mandelbrot? z + i = 0 + while i<100 + i += 1 + z = z * z + return false if z.abs > 2 + end + true +end + +ary = [] + +(0..1000).each{|dx| + (0..1000).each{|dy| + x = dx / 50.0 + y = dy / 50.0 + c = Complex(x, y) + ary << c if mandelbrot?(c) + } +} + diff --git a/benchmark/bm_app_pentomino.rb b/benchmark/bm_app_pentomino.rb new file mode 100644 index 0000000000..47be7b203f --- /dev/null +++ b/benchmark/bm_app_pentomino.rb @@ -0,0 +1,130 @@ +#!/usr/local/bin/ruby +# This program is contributed by Shin Nishiyama + + +# modified by K.Sasada + +NP = 5 +ROW = 8 + NP +COL = 8 + +$p = [] +$b = [] +$no = 0 + +def piece(n, a, nb) + nb.each{|x| + a[n] = x + if n == NP-1 + $p << [a.sort] + else + nbc=nb.dup + [-ROW, -1, 1, ROW].each{|d| + if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d) + nbc << x+d + end + } + nbc.delete x + piece(n+1,a[0..n],nbc) + end + } +end + +def kikaku(a) + a.collect {|x| x - a[0]} +end +def ud(a) + kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort) +end +def rl(a) + kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort) +end +def xy(a) + kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort) +end + +def mkpieces + piece(0,[],[0]) + $p.each do |a| + a0 = a[0] + a[1] = ud(a0) + a[2] = rl(a0) + a[3] = ud(rl(a0)) + a[4] = xy(a0) + a[5] = ud(xy(a0)) + a[6] = rl(xy(a0)) + a[7] = ud(rl(xy(a0))) + a.sort! + a.uniq! + end + $p.uniq!.sort! {|x,y| x[0] <=> y[0] } +end + +def mkboard + (0...ROW*COL).each{|i| + if i % ROW >= ROW-NP + $b[i] = -2 + else + $b[i] = -1 + end + $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2 + } +end + +def pboard + return # skip print + print "No. #$no\n" + (0...COL).each{|i| + print "|" + (0...ROW-NP).each{|j| + x = $b[i*ROW+j] + if x < 0 + print "..|" + else + printf "%2d|",x+1 + end + } + print "\n" + } + print "\n" +end + +$pnum=[] +def setpiece(a,pos) + if a.length == $p.length then + $no += 1 + pboard + return + end + while $b[pos] != -1 + pos += 1 + end + ($pnum - a).each do |i| + $p[i].each do |x| + f = 0 + x.each{|s| + if $b[pos+s] != -1 + f=1 + break + end + } + if f == 0 then + x.each{|s| + $b[pos+s] = i + } + a << i + setpiece(a.dup, pos) + a.pop + x.each{|s| + $b[pos+s] = -1 + } + end + end + end +end + +mkpieces +mkboard +$p[4] = [$p[4][0]] +$pnum = (0...$p.length).to_a +setpiece([],0) diff --git a/benchmark/bm_app_raise.rb b/benchmark/bm_app_raise.rb new file mode 100644 index 0000000000..5db8f95d50 --- /dev/null +++ b/benchmark/bm_app_raise.rb @@ -0,0 +1,8 @@ +i = 0 +while i<300000 + i += 1 + begin + raise + rescue + end +end diff --git a/benchmark/bm_app_strconcat.rb b/benchmark/bm_app_strconcat.rb new file mode 100644 index 0000000000..7eed7c1aed --- /dev/null +++ b/benchmark/bm_app_strconcat.rb @@ -0,0 +1,5 @@ +i = 0 +while i<2_000_000 + "#{1+1} #{1+1} #{1+1}" + i += 1 +end diff --git a/benchmark/bm_app_tak.rb b/benchmark/bm_app_tak.rb new file mode 100644 index 0000000000..efe5380f4e --- /dev/null +++ b/benchmark/bm_app_tak.rb @@ -0,0 +1,13 @@ + +def tak x, y, z + unless y < x + z + else + tak( tak(x-1, y, z), + tak(y-1, z, x), + tak(z-1, x, y)) + end +end + +tak(18, 9, 0) + diff --git a/benchmark/bm_app_tarai.rb b/benchmark/bm_app_tarai.rb new file mode 100644 index 0000000000..4c146f5ccf --- /dev/null +++ b/benchmark/bm_app_tarai.rb @@ -0,0 +1,10 @@ +def tarai( x, y, z ) + if x <= y + then y + else tarai(tarai(x-1, y, z), + tarai(y-1, z, x), + tarai(z-1, x, y)) + end +end + +tarai(12, 6, 0) diff --git a/benchmark/bm_app_uri.rb b/benchmark/bm_app_uri.rb new file mode 100644 index 0000000000..586edfd5dc --- /dev/null +++ b/benchmark/bm_app_uri.rb @@ -0,0 +1,8 @@ +require 'uri' + +100_000.times{ + uri = URI.parse('http://www.ruby-lang.org') + uri.scheme + uri.host + uri.port +} diff --git a/benchmark/bm_array_sample_100k_10.rb b/benchmark/bm_array_sample_100k_10.rb new file mode 100644 index 0000000000..5f41ecc32b --- /dev/null +++ b/benchmark/bm_array_sample_100k_10.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 10} diff --git a/benchmark/bm_array_sample_100k_11.rb b/benchmark/bm_array_sample_100k_11.rb new file mode 100644 index 0000000000..18b1715319 --- /dev/null +++ b/benchmark/bm_array_sample_100k_11.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 11} diff --git a/benchmark/bm_array_sample_100k__100.rb b/benchmark/bm_array_sample_100k__100.rb new file mode 100644 index 0000000000..22863afe89 --- /dev/null +++ b/benchmark/bm_array_sample_100k__100.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 100} diff --git a/benchmark/bm_array_sample_100k__1k.rb b/benchmark/bm_array_sample_100k__1k.rb new file mode 100644 index 0000000000..4cd79e6c67 --- /dev/null +++ b/benchmark/bm_array_sample_100k__1k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 1000} diff --git a/benchmark/bm_array_sample_100k__6k.rb b/benchmark/bm_array_sample_100k__6k.rb new file mode 100644 index 0000000000..b3d264249e --- /dev/null +++ b/benchmark/bm_array_sample_100k__6k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 6000} diff --git a/benchmark/bm_array_sample_100k___10k.rb b/benchmark/bm_array_sample_100k___10k.rb new file mode 100644 index 0000000000..5dd55ec058 --- /dev/null +++ b/benchmark/bm_array_sample_100k___10k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 10_000} diff --git a/benchmark/bm_array_sample_100k___50k.rb b/benchmark/bm_array_sample_100k___50k.rb new file mode 100644 index 0000000000..1506732c3c --- /dev/null +++ b/benchmark/bm_array_sample_100k___50k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 50_000} diff --git a/benchmark/bm_array_shift.rb b/benchmark/bm_array_shift.rb new file mode 100644 index 0000000000..798bb9e3f4 --- /dev/null +++ b/benchmark/bm_array_shift.rb @@ -0,0 +1,14 @@ +require 'benchmark' + +Benchmark.bm do |x| + [10_000,1_000_000,100_000_000].each do |n| + ary = Array.new(n,0) + GC.start + x.report("#{n}:shift"){ ary.shift } + (0..4).each do |i| + ary = Array.new(n,0) + GC.start + x.report("#{n}:shift(#{i})"){ ary.shift(i) } + end + end +end diff --git a/benchmark/bm_array_small_and.rb b/benchmark/bm_array_small_and.rb new file mode 100644 index 0000000000..e53a6edae6 --- /dev/null +++ b/benchmark/bm_array_small_and.rb @@ -0,0 +1,17 @@ +MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i +MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i +ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i + +ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| + (MIN_SIZE..MAX_SIZE).map do |size2| + [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] + end +end + +ITERATIONS.times do + ARRAYS.each do |group| + group.each do |arr1, arr2| + arr1 & arr2 + end + end +end diff --git a/benchmark/bm_array_small_diff.rb b/benchmark/bm_array_small_diff.rb new file mode 100644 index 0000000000..9661ee48db --- /dev/null +++ b/benchmark/bm_array_small_diff.rb @@ -0,0 +1,17 @@ +MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i +MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i +ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i + +ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| + (MIN_SIZE..MAX_SIZE).map do |size2| + [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] + end +end + +ITERATIONS.times do + ARRAYS.each do |group| + group.each do |arr1, arr2| + arr1 - arr2 + end + end +end diff --git a/benchmark/bm_array_small_or.rb b/benchmark/bm_array_small_or.rb new file mode 100644 index 0000000000..c58b5fd1ff --- /dev/null +++ b/benchmark/bm_array_small_or.rb @@ -0,0 +1,17 @@ +MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i +MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i +ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i + +ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1| + (MIN_SIZE..MAX_SIZE).map do |size2| + [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }] + end +end + +ITERATIONS.times do + ARRAYS.each do |group| + group.each do |arr1, arr2| + arr1 | arr2 + end + end +end diff --git a/benchmark/bm_array_sort_block.rb b/benchmark/bm_array_sort_block.rb new file mode 100644 index 0000000000..3579786056 --- /dev/null +++ b/benchmark/bm_array_sort_block.rb @@ -0,0 +1,2 @@ +ary = Array.new(1000) { rand(1000) } +10000.times { ary.sort { |a, b| a <=> b } } diff --git a/benchmark/bm_array_sort_float.rb b/benchmark/bm_array_sort_float.rb new file mode 100644 index 0000000000..9a6e2f8bd2 --- /dev/null +++ b/benchmark/bm_array_sort_float.rb @@ -0,0 +1,2 @@ +arr = Array.new(1000) { rand } +10000.times { arr.sort } diff --git a/benchmark/bm_array_values_at_int.rb b/benchmark/bm_array_values_at_int.rb new file mode 100644 index 0000000000..6cb394cb9f --- /dev/null +++ b/benchmark/bm_array_values_at_int.rb @@ -0,0 +1,2 @@ +ary = Array.new(10000) {|i| i} +100000.times { ary.values_at(500) } diff --git a/benchmark/bm_array_values_at_range.rb b/benchmark/bm_array_values_at_range.rb new file mode 100644 index 0000000000..5b53806d1c --- /dev/null +++ b/benchmark/bm_array_values_at_range.rb @@ -0,0 +1,2 @@ +ary = Array.new(10000) {|i| i} +100000.times { ary.values_at(1..2000) } diff --git a/benchmark/bm_bighash.rb b/benchmark/bm_bighash.rb new file mode 100644 index 0000000000..e2ad5a5c94 --- /dev/null +++ b/benchmark/bm_bighash.rb @@ -0,0 +1 @@ +h = {}; 5000000.times {|n| h[n] = n } diff --git a/benchmark/bm_dir_empty_p.rb b/benchmark/bm_dir_empty_p.rb new file mode 100644 index 0000000000..8329c757cf --- /dev/null +++ b/benchmark/bm_dir_empty_p.rb @@ -0,0 +1,5 @@ +require 'tmpdir' +max = 100_000 +Dir.mktmpdir('bm_dir_empty_p') do |dir| + max.times { Dir.empty?(dir) } +end diff --git a/benchmark/bm_erb_render.rb b/benchmark/bm_erb_render.rb new file mode 100644 index 0000000000..7dc0816c43 --- /dev/null +++ b/benchmark/bm_erb_render.rb @@ -0,0 +1,25 @@ +require 'erb' + +data = < + <%= title %> + +

<%= title %>

+

+ <%= content %> +

+ + +erb + +max = 1_500_000 +title = "hello world!" +content = "hello world!\n" * 10 + +src = "def self.render(title, content); #{ERB.new(data).src}; end" +mod = Module.new +mod.instance_eval(src, "(ERB)") + +max.times do + mod.render(title, content) +end diff --git a/benchmark/bm_file_chmod.rb b/benchmark/bm_file_chmod.rb new file mode 100644 index 0000000000..1cd4760c9d --- /dev/null +++ b/benchmark/bm_file_chmod.rb @@ -0,0 +1,9 @@ +# chmod file +require 'tempfile' +max = 200_000 +tmp = Tempfile.new('chmod') +path = tmp.path +max.times do + File.chmod(0777, path) +end +tmp.close! diff --git a/benchmark/bm_file_rename.rb b/benchmark/bm_file_rename.rb new file mode 100644 index 0000000000..bbb44aebac --- /dev/null +++ b/benchmark/bm_file_rename.rb @@ -0,0 +1,11 @@ +# rename file +require 'tempfile' + +max = 100_000 +tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ] +a, b = tmp.map { |x| x.path } +tmp.each { |t| t.close } # Windows can't rename files without closing them +max.times do + File.rename(a, b) + File.rename(b, a) +end diff --git a/benchmark/bm_hash_aref_dsym.rb b/benchmark/bm_hash_aref_dsym.rb new file mode 100644 index 0000000000..af4f8c36d4 --- /dev/null +++ b/benchmark/bm_hash_aref_dsym.rb @@ -0,0 +1,4 @@ +h = {} +syms = ('a'..'z').map { |s| s.to_sym } +syms.each { |s| h[s] = 1 } +200_000.times { syms.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_dsym_long.rb b/benchmark/bm_hash_aref_dsym_long.rb new file mode 100644 index 0000000000..9d7759379e --- /dev/null +++ b/benchmark/bm_hash_aref_dsym_long.rb @@ -0,0 +1,21 @@ +# [ruby-core:70129] [Bug #11396] +collection_size = 200000 +sample_size = 10000 + +values = (1..collection_size).to_a.map do |x| + "THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}" +end + +symbol_hash = {} + +values.each do |x| + symbol_hash[x.to_sym] = 1 +end + +# use the same samples each time to minimize deviations +rng = Random.new(0) +symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym) + +3000.times do + symbol_sample_array.each { |x| symbol_hash[x] } +end diff --git a/benchmark/bm_hash_aref_fix.rb b/benchmark/bm_hash_aref_fix.rb new file mode 100644 index 0000000000..1346890582 --- /dev/null +++ b/benchmark/bm_hash_aref_fix.rb @@ -0,0 +1,4 @@ +h = {} +nums = (1..26).to_a +nums.each { |i| h[i] = i } +200_000.times { nums.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_flo.rb b/benchmark/bm_hash_aref_flo.rb new file mode 100644 index 0000000000..2217274c82 --- /dev/null +++ b/benchmark/bm_hash_aref_flo.rb @@ -0,0 +1,4 @@ +h = {} +strs = [*1..10000].map! {|i| i.fdiv(10)} +strs.each { |s| h[s] = s } +50.times { strs.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_miss.rb b/benchmark/bm_hash_aref_miss.rb new file mode 100644 index 0000000000..b0913dd4bb --- /dev/null +++ b/benchmark/bm_hash_aref_miss.rb @@ -0,0 +1,5 @@ +h = {} +strs = ('a'..'z').to_a.map!(&:freeze) +strs.each { |s| h[s] = s } +strs = ('A'..'Z').to_a +200_000.times { strs.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_str.rb b/benchmark/bm_hash_aref_str.rb new file mode 100644 index 0000000000..19439b061b --- /dev/null +++ b/benchmark/bm_hash_aref_str.rb @@ -0,0 +1,4 @@ +h = {} +strs = ('a'..'z').to_a.map!(&:freeze) +strs.each { |s| h[s] = s } +200_000.times { strs.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_sym.rb b/benchmark/bm_hash_aref_sym.rb new file mode 100644 index 0000000000..f75d163fe6 --- /dev/null +++ b/benchmark/bm_hash_aref_sym.rb @@ -0,0 +1,9 @@ +h = {} +syms = ('a'..'z').to_a +begin + syms = eval("%i[#{syms.join(' ')}]") +rescue SyntaxError # <= 1.9.3 + syms.map!(&:to_sym) +end +syms.each { |s| h[s] = s } +200_000.times { syms.each { |s| h[s] } } diff --git a/benchmark/bm_hash_aref_sym_long.rb b/benchmark/bm_hash_aref_sym_long.rb new file mode 100644 index 0000000000..9dab8df7be --- /dev/null +++ b/benchmark/bm_hash_aref_sym_long.rb @@ -0,0 +1,13 @@ +h = {} +syms = %w[puts warn syswrite write stat bacon lettuce tomato +some symbols in this array may already be interned others should not be +hash browns make good breakfast but not cooked using prime numbers +shift for division entries delete_if keys exist? +] +begin + syms = eval("%i[#{syms.join(' ')}]") +rescue SyntaxError # <= 1.9.3 + syms.map!(&:to_sym) +end +syms.each { |s| h[s] = s } +200_000.times { syms.each { |s| h[s] } } diff --git a/benchmark/bm_hash_flatten.rb b/benchmark/bm_hash_flatten.rb new file mode 100644 index 0000000000..e944aae9f2 --- /dev/null +++ b/benchmark/bm_hash_flatten.rb @@ -0,0 +1,9 @@ +h = {} + +10000.times do |i| + h[i] = nil +end + +1000.times do + h.flatten +end diff --git a/benchmark/bm_hash_ident_flo.rb b/benchmark/bm_hash_ident_flo.rb new file mode 100644 index 0000000000..0c7edfed3e --- /dev/null +++ b/benchmark/bm_hash_ident_flo.rb @@ -0,0 +1,4 @@ +h = {}.compare_by_identity +strs = (1..10000).to_a.map!(&:to_f) +strs.each { |s| h[s] = s } +50.times { strs.each { |s| h[s] } } diff --git a/benchmark/bm_hash_ident_num.rb b/benchmark/bm_hash_ident_num.rb new file mode 100644 index 0000000000..b226736c6f --- /dev/null +++ b/benchmark/bm_hash_ident_num.rb @@ -0,0 +1,4 @@ +h = {}.compare_by_identity +nums = (1..26).to_a +nums.each { |n| h[n] = n } +200_000.times { nums.each { |n| h[n] } } diff --git a/benchmark/bm_hash_ident_obj.rb b/benchmark/bm_hash_ident_obj.rb new file mode 100644 index 0000000000..4b3b58edec --- /dev/null +++ b/benchmark/bm_hash_ident_obj.rb @@ -0,0 +1,4 @@ +h = {}.compare_by_identity +objs = 26.times.map { Object.new } +objs.each { |o| h[o] = o } +200_000.times { objs.each { |o| h[o] } } diff --git a/benchmark/bm_hash_ident_str.rb b/benchmark/bm_hash_ident_str.rb new file mode 100644 index 0000000000..8582b38e31 --- /dev/null +++ b/benchmark/bm_hash_ident_str.rb @@ -0,0 +1,4 @@ +h = {}.compare_by_identity +strs = ('a'..'z').to_a +strs.each { |s| h[s] = s } +200_000.times { strs.each { |s| h[s] } } diff --git a/benchmark/bm_hash_ident_sym.rb b/benchmark/bm_hash_ident_sym.rb new file mode 100644 index 0000000000..4c81e3d28e --- /dev/null +++ b/benchmark/bm_hash_ident_sym.rb @@ -0,0 +1,4 @@ +h = {}.compare_by_identity +syms = ('a'..'z').to_a.map(&:to_sym) +syms.each { |s| h[s] = s } +200_000.times { syms.each { |s| h[s] } } diff --git a/benchmark/bm_hash_keys.rb b/benchmark/bm_hash_keys.rb new file mode 100644 index 0000000000..6863cd01f9 --- /dev/null +++ b/benchmark/bm_hash_keys.rb @@ -0,0 +1,9 @@ +h = {} + +10000.times do |i| + h[i] = nil +end + +5000.times do + h.keys +end diff --git a/benchmark/bm_hash_long.rb b/benchmark/bm_hash_long.rb new file mode 100644 index 0000000000..03d9109602 --- /dev/null +++ b/benchmark/bm_hash_long.rb @@ -0,0 +1,4 @@ +k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong"; +k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping"; +h = {k1 => 0, k2 => 0}; +3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1} diff --git a/benchmark/bm_hash_shift.rb b/benchmark/bm_hash_shift.rb new file mode 100644 index 0000000000..a645671a5b --- /dev/null +++ b/benchmark/bm_hash_shift.rb @@ -0,0 +1,10 @@ +h = {} + +10000.times do |i| + h[i] = nil +end + +50000.times do + k, v = h.shift + h[k] = v +end diff --git a/benchmark/bm_hash_shift_u16.rb b/benchmark/bm_hash_shift_u16.rb new file mode 100644 index 0000000000..ec800d0342 --- /dev/null +++ b/benchmark/bm_hash_shift_u16.rb @@ -0,0 +1,10 @@ +h = {} + +(16384..65536).each do |i| + h[i] = nil +end + +300000.times do + k, v = h.shift + h[k] = v +end diff --git a/benchmark/bm_hash_shift_u24.rb b/benchmark/bm_hash_shift_u24.rb new file mode 100644 index 0000000000..de4e0fa696 --- /dev/null +++ b/benchmark/bm_hash_shift_u24.rb @@ -0,0 +1,10 @@ +h = {} + +(0xff4000..0xffffff).each do |i| + h[i] = nil +end + +300000.times do + k, v = h.shift + h[k] = v +end diff --git a/benchmark/bm_hash_shift_u32.rb b/benchmark/bm_hash_shift_u32.rb new file mode 100644 index 0000000000..656aa55583 --- /dev/null +++ b/benchmark/bm_hash_shift_u32.rb @@ -0,0 +1,10 @@ +h = {} + +(0xffff4000..0xffffffff).each do |i| + h[i] = nil +end + +300000.times do + k, v = h.shift + h[k] = v +end diff --git a/benchmark/bm_hash_small2.rb b/benchmark/bm_hash_small2.rb new file mode 100644 index 0000000000..45485d9c71 --- /dev/null +++ b/benchmark/bm_hash_small2.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a} diff --git a/benchmark/bm_hash_small4.rb b/benchmark/bm_hash_small4.rb new file mode 100644 index 0000000000..acd4084334 --- /dev/null +++ b/benchmark/bm_hash_small4.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a} diff --git a/benchmark/bm_hash_small8.rb b/benchmark/bm_hash_small8.rb new file mode 100644 index 0000000000..9cffcc91b6 --- /dev/null +++ b/benchmark/bm_hash_small8.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a} diff --git a/benchmark/bm_hash_to_proc.rb b/benchmark/bm_hash_to_proc.rb new file mode 100644 index 0000000000..2b675bf509 --- /dev/null +++ b/benchmark/bm_hash_to_proc.rb @@ -0,0 +1,9 @@ +h = {} + +10000.times do |i| + h[i] = nil +end + +5000.times do |i| + [i].map(&h) +end diff --git a/benchmark/bm_hash_values.rb b/benchmark/bm_hash_values.rb new file mode 100644 index 0000000000..069441302f --- /dev/null +++ b/benchmark/bm_hash_values.rb @@ -0,0 +1,9 @@ +h = {} + +10000.times do |i| + h[i] = nil +end + +5000.times do + h.values +end diff --git a/benchmark/bm_int_quo.rb b/benchmark/bm_int_quo.rb new file mode 100644 index 0000000000..e22a3f8c30 --- /dev/null +++ b/benchmark/bm_int_quo.rb @@ -0,0 +1 @@ +5000000.times { 42.quo(3) } diff --git a/benchmark/bm_io_copy_stream_write.rb b/benchmark/bm_io_copy_stream_write.rb new file mode 100644 index 0000000000..3fd87250a4 --- /dev/null +++ b/benchmark/bm_io_copy_stream_write.rb @@ -0,0 +1,24 @@ +# The goal of this is to use a synthetic (non-IO) reader +# to trigger the read/write loop of IO.copy_stream, +# bypassing in-kernel mechanisms like sendfile for zero copy, +# so we wrap the /dev/zero IO object: + +class Zero + def initialize + @n = 100000 + @in = File.open('/dev/zero', 'rb') + end + + def read(len, buf) + return if (@n -= 1) == 0 + @in.read(len, buf) + end +end + +begin + src = Zero.new + dst = File.open(IO::NULL, 'wb') + n = IO.copy_stream(src, dst) +rescue Errno::ENOENT + # not *nix +end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL) diff --git a/benchmark/bm_io_copy_stream_write_socket.rb b/benchmark/bm_io_copy_stream_write_socket.rb new file mode 100644 index 0000000000..11f369bd0d --- /dev/null +++ b/benchmark/bm_io_copy_stream_write_socket.rb @@ -0,0 +1,35 @@ +# The goal of this is to use a synthetic (non-IO) reader +# to trigger the read/write loop of IO.copy_stream, +# bypassing in-kernel mechanisms like sendfile for zero copy, +# so we wrap the /dev/zero IO object: +class Zero + def initialize + @n = 100000 + @in = File.open('/dev/zero', 'rb') + end + + def read(len, buf) + return if (@n -= 1) == 0 + @in.read(len, buf) + end +end + +begin + require 'socket' + src = Zero.new + rd, wr = UNIXSocket.pair + pid = fork do + wr.close + buf = String.new + while rd.read(16384, buf) + end + end + rd.close + IO.copy_stream(src, wr) +rescue Errno::ENOENT, NotImplementedError, NameError + # not *nix: missing /dev/zero, fork, or UNIXSocket +rescue LoadError # no socket? +ensure + wr.close if wr + Process.waitpid(pid) if pid +end if IO.respond_to?(:copy_stream) diff --git a/benchmark/bm_io_file_create.rb b/benchmark/bm_io_file_create.rb new file mode 100644 index 0000000000..2f205c1333 --- /dev/null +++ b/benchmark/bm_io_file_create.rb @@ -0,0 +1,13 @@ +# +# Create files +# + +max = 200_000 +file = './tmpfile_of_bm_io_file_create' + +max.times{ + f = open(file, 'w') + f.close#(true) +} +File.unlink(file) + diff --git a/benchmark/bm_io_file_read.rb b/benchmark/bm_io_file_read.rb new file mode 100644 index 0000000000..b9e796ed30 --- /dev/null +++ b/benchmark/bm_io_file_read.rb @@ -0,0 +1,15 @@ +# +# Seek and Read file. +# + +require 'tempfile' + +max = 200_000 +str = "Hello world! " * 1000 +f = Tempfile.new('yarv-benchmark') +f.write str + +max.times{ + f.seek 0 + f.read +} diff --git a/benchmark/bm_io_file_write.rb b/benchmark/bm_io_file_write.rb new file mode 100644 index 0000000000..aa1be0e5fe --- /dev/null +++ b/benchmark/bm_io_file_write.rb @@ -0,0 +1,14 @@ +# +# Seek and Write file. +# + +require 'tempfile' + +max = 200_000 +str = "Hello world! " * 1000 +f = Tempfile.new('yarv-benchmark') + +max.times{ + f.seek 0 + f.write str +} diff --git a/benchmark/bm_io_nonblock_noex.rb b/benchmark/bm_io_nonblock_noex.rb new file mode 100644 index 0000000000..da9357fdc6 --- /dev/null +++ b/benchmark/bm_io_nonblock_noex.rb @@ -0,0 +1,22 @@ +nr = 1_000_000 +i = 0 +msg = '.' +buf = '.' +noex = { exception: false } +begin + r, w = IO.pipe + while i < nr + i += 1 + w.write_nonblock(msg, noex) + r.read_nonblock(1, buf, noex) + end +rescue ArgumentError # old Rubies + while i < nr + i += 1 + w.write_nonblock(msg) + r.read_nonblock(1, buf) + end +ensure + r.close + w.close +end diff --git a/benchmark/bm_io_nonblock_noex2.rb b/benchmark/bm_io_nonblock_noex2.rb new file mode 100644 index 0000000000..56819d049b --- /dev/null +++ b/benchmark/bm_io_nonblock_noex2.rb @@ -0,0 +1,21 @@ +nr = 1_000_000 +i = 0 +msg = '.' +buf = '.' +begin + r, w = IO.pipe + while i < nr + i += 1 + w.write_nonblock(msg, exception: false) + r.read_nonblock(1, buf, exception: false) + end +rescue ArgumentError # old Rubies + while i < nr + i += 1 + w.write_nonblock(msg) + r.read_nonblock(1, buf) + end +ensure + r.close + w.close +end diff --git a/benchmark/bm_io_pipe_rw.rb b/benchmark/bm_io_pipe_rw.rb new file mode 100644 index 0000000000..6862a8ae61 --- /dev/null +++ b/benchmark/bm_io_pipe_rw.rb @@ -0,0 +1,13 @@ +# Measure uncontended GVL performance via read/write with 1:1 threading +# If we switch to M:N threading, this will benchmark something else... +r, w = IO.pipe +src = '0'.freeze +dst = String.new +i = 0 +while i < 1_000_000 + i += 1 + w.write(src) + r.read(1, dst) +end +w.close +r.close diff --git a/benchmark/bm_io_select.rb b/benchmark/bm_io_select.rb new file mode 100644 index 0000000000..19248daeb1 --- /dev/null +++ b/benchmark/bm_io_select.rb @@ -0,0 +1,9 @@ +# IO.select performance + +w = [ IO.pipe[1] ]; + +nr = 1000000 +nr.times { + IO.select nil, w +} + diff --git a/benchmark/bm_io_select2.rb b/benchmark/bm_io_select2.rb new file mode 100644 index 0000000000..10e37d71b2 --- /dev/null +++ b/benchmark/bm_io_select2.rb @@ -0,0 +1,22 @@ +# IO.select performance. worst case of single fd. + +ios = [] +nr = 1000000 +if defined?(Process::RLIMIT_NOFILE) + max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] +else + max = 64 +end +puts "max fd: #{max} (results not apparent with <= 1024 max fd)" + +((max / 2) - 10).times do + ios.concat IO.pipe +end + +last = [ ios[-1] ] +puts "last IO: #{last[0].inspect}" + +nr.times do + IO.select nil, last +end + diff --git a/benchmark/bm_io_select3.rb b/benchmark/bm_io_select3.rb new file mode 100644 index 0000000000..7d0ba1f092 --- /dev/null +++ b/benchmark/bm_io_select3.rb @@ -0,0 +1,21 @@ +# IO.select performance. a lot of fd + +ios = [] +nr = 100 +if defined?(Process::RLIMIT_NOFILE) + max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] +else + max = 64 +end +puts "max fd: #{max} (results not apparent with <= 1024 max fd)" + +(max - 10).times do + r, w = IO.pipe + r.close + ios.push w +end + +nr.times do + IO.select nil, ios +end + diff --git a/benchmark/bm_loop_for.rb b/benchmark/bm_loop_for.rb new file mode 100644 index 0000000000..0fc4cc1511 --- /dev/null +++ b/benchmark/bm_loop_for.rb @@ -0,0 +1,3 @@ +for i in 1..30_000_000 + # +end diff --git a/benchmark/bm_loop_generator.rb b/benchmark/bm_loop_generator.rb new file mode 100644 index 0000000000..d3375c744c --- /dev/null +++ b/benchmark/bm_loop_generator.rb @@ -0,0 +1,14 @@ +max = 600000 + +if defined? Fiber + gen = (1..max).each + loop do + gen.next + end +else + require 'generator' + gen = Generator.new((0..max)) + while gen.next? + gen.next + end +end diff --git a/benchmark/bm_loop_times.rb b/benchmark/bm_loop_times.rb new file mode 100644 index 0000000000..521f72ad1a --- /dev/null +++ b/benchmark/bm_loop_times.rb @@ -0,0 +1 @@ +30_000_000.times{|e|} diff --git a/benchmark/bm_loop_whileloop.rb b/benchmark/bm_loop_whileloop.rb new file mode 100644 index 0000000000..0072822c06 --- /dev/null +++ b/benchmark/bm_loop_whileloop.rb @@ -0,0 +1,4 @@ +i = 0 +while i<30_000_000 # benchmark loop 1 + i += 1 +end diff --git a/benchmark/bm_loop_whileloop2.rb b/benchmark/bm_loop_whileloop2.rb new file mode 100644 index 0000000000..47d02dffc4 --- /dev/null +++ b/benchmark/bm_loop_whileloop2.rb @@ -0,0 +1,4 @@ +i = 0 +while i< 6_000_000 # benchmark loop 2 + i += 1 +end diff --git a/benchmark/bm_marshal_dump_flo.rb b/benchmark/bm_marshal_dump_flo.rb new file mode 100644 index 0000000000..9b8d0c6afb --- /dev/null +++ b/benchmark/bm_marshal_dump_flo.rb @@ -0,0 +1,2 @@ +bug10761 = 10000.times.map { |x| x.to_f } +100.times { Marshal.dump(bug10761) } diff --git a/benchmark/bm_marshal_dump_load_geniv.rb b/benchmark/bm_marshal_dump_load_geniv.rb new file mode 100644 index 0000000000..8252ad90fa --- /dev/null +++ b/benchmark/bm_marshal_dump_load_geniv.rb @@ -0,0 +1,10 @@ +a = '' +a.instance_eval do + @a = :a + @b = :b + @c = :c +end +100000.times do + a = Marshal.load(Marshal.dump(a)) +end +#p(a.instance_eval { @a == :a && @b == :b && @c == :c }) diff --git a/benchmark/bm_marshal_dump_load_time.rb b/benchmark/bm_marshal_dump_load_time.rb new file mode 100644 index 0000000000..e29743b791 --- /dev/null +++ b/benchmark/bm_marshal_dump_load_time.rb @@ -0,0 +1 @@ +100000.times { Marshal.load(Marshal.dump(Time.now)) } diff --git a/benchmark/bm_securerandom.rb b/benchmark/bm_securerandom.rb new file mode 100644 index 0000000000..a082ea6d5b --- /dev/null +++ b/benchmark/bm_securerandom.rb @@ -0,0 +1,5 @@ +require "securerandom" + +20_0000.times do + SecureRandom.random_number(100) +end diff --git a/benchmark/bm_so_ackermann.rb b/benchmark/bm_so_ackermann.rb new file mode 100644 index 0000000000..7db5be9050 --- /dev/null +++ b/benchmark/bm_so_ackermann.rb @@ -0,0 +1,19 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ + +def ack(m, n) + if m == 0 then + n + 1 + elsif n == 0 then + ack(m - 1, 1) + else + ack(m - 1, ack(m, n - 1)) + end +end + +NUM = 9 +ack(3, NUM) + + diff --git a/benchmark/bm_so_array.rb b/benchmark/bm_so_array.rb new file mode 100644 index 0000000000..2b8fce8f99 --- /dev/null +++ b/benchmark/bm_so_array.rb @@ -0,0 +1,23 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ +# with help from Paul Brannan and Mark Hubbart + +n = 9000 # Integer(ARGV.shift || 1) + +x = Array.new(n) +y = Array.new(n, 0) + +n.times{|bi| + x[bi] = bi + 1 +} + +(0 .. 999).each do |e| + (n-1).step(0,-1) do |bi| + y[bi] += x.at(bi) + end +end +# puts "#{y.first} #{y.last}" + + diff --git a/benchmark/bm_so_binary_trees.rb b/benchmark/bm_so_binary_trees.rb new file mode 100644 index 0000000000..b1693e4109 --- /dev/null +++ b/benchmark/bm_so_binary_trees.rb @@ -0,0 +1,62 @@ +# The Computer Language Shootout Benchmarks +# http://shootout.alioth.debian.org +# +# contributed by Jesse Millikan + +# disable output +alias puts_orig puts +def puts str + # disable puts +end + +def item_check(tree) + if tree[0] == nil + tree[1] + else + tree[1] + item_check(tree[0]) - item_check(tree[2]) + end +end + +def bottom_up_tree(item, depth) + if depth > 0 + item_item = 2 * item + depth -= 1 + [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)] + else + [nil, item, nil] + end +end + +max_depth = 16 # ARGV[0].to_i +min_depth = 4 + +max_depth = min_depth + 2 if min_depth + 2 > max_depth + +stretch_depth = max_depth + 1 +stretch_tree = bottom_up_tree(0, stretch_depth) + +puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}" +stretch_tree = nil + +long_lived_tree = bottom_up_tree(0, max_depth) + +min_depth.step(max_depth + 1, 2) do |depth| + iterations = 2**(max_depth - depth + min_depth) + + check = 0 + + for i in 1..iterations + temp_tree = bottom_up_tree(i, depth) + check += item_check(temp_tree) + + temp_tree = bottom_up_tree(-i, depth) + check += item_check(temp_tree) + end + + puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}" +end + +puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}" + +undef puts +alias puts puts_orig diff --git a/benchmark/bm_so_concatenate.rb b/benchmark/bm_so_concatenate.rb new file mode 100644 index 0000000000..873214de7c --- /dev/null +++ b/benchmark/bm_so_concatenate.rb @@ -0,0 +1,18 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ +# based on code from Aristarkh A Zagorodnikov and Dat Nguyen + +STUFF = "hello\n" +i = 0 +while i<10 + i += 1 + hello = '' + 4_000_000.times do |e| + hello << STUFF + end +end +# puts hello.length + + diff --git a/benchmark/bm_so_exception.rb b/benchmark/bm_so_exception.rb new file mode 100644 index 0000000000..deb003a594 --- /dev/null +++ b/benchmark/bm_so_exception.rb @@ -0,0 +1,61 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ + +$HI = 0 +$LO = 0 +NUM = 250000 # Integer(ARGV[0] || 1) + + +class Lo_Exception < Exception + def initialize(num) + @value = num + end +end + +class Hi_Exception < Exception + def initialize(num) + @value = num + end +end + +def some_function(num) + begin + hi_function(num) + rescue + print "We shouldn't get here, exception is: #{$!.type}\n" + end +end + +def hi_function(num) + begin + lo_function(num) + rescue Hi_Exception + $HI = $HI + 1 + end +end + +def lo_function(num) + begin + blowup(num) + rescue Lo_Exception + $LO = $LO + 1 + end +end + +def blowup(num) + if num % 2 == 0 + raise Lo_Exception.new(num) + else + raise Hi_Exception.new(num) + end +end + + +i = 1 +max = NUM+1 +while i < max + i += 1 + some_function(i+1) +end diff --git a/benchmark/bm_so_fannkuch.rb b/benchmark/bm_so_fannkuch.rb new file mode 100644 index 0000000000..bac5ecd44c --- /dev/null +++ b/benchmark/bm_so_fannkuch.rb @@ -0,0 +1,45 @@ +# The Computer Language Shootout +# http://shootout.alioth.debian.org/ +# Contributed by Sokolov Yura +# Modified by Ryan Williams + +def fannkuch(n) + maxFlips, m, r, check = 0, n-1, n, 0 + count = (1..n).to_a + perm = (1..n).to_a + + while true + if check < 30 + puts "#{perm}" + check += 1 + end + + while r != 1 + count[r-1] = r + r -= 1 + end + + if perm[0] != 1 and perm[m] != n + perml = perm.clone #.dup + flips = 0 + while (k = perml.first ) != 1 + perml = perml.slice!(0, k).reverse + perml + flips += 1 + end + maxFlips = flips if flips > maxFlips + end + while true + if r==n then return maxFlips end + perm.insert r,perm.shift + break if (count[r] -= 1) > 0 + r += 1 + end + end +end + +def puts *args +end + +N = 9 # (ARGV[0] || 1).to_i +puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" + diff --git a/benchmark/bm_so_fasta.rb b/benchmark/bm_so_fasta.rb new file mode 100644 index 0000000000..dcc6b39507 --- /dev/null +++ b/benchmark/bm_so_fasta.rb @@ -0,0 +1,81 @@ +# The Computer Language Shootout +# http://shootout.alioth.debian.org/ +# Contributed by Sokolov Yura + +$last = 42.0 +def gen_random(max, im=139968, ia=3877, ic=29573) + (max * ($last = ($last * ia + ic) % im)) / im +end + +alu = + "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ + "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ + "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ + "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ + "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ + "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ + "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" + +iub = [ + ["a", 0.27], + ["c", 0.12], + ["g", 0.12], + ["t", 0.27], + + ["B", 0.02], + ["D", 0.02], + ["H", 0.02], + ["K", 0.02], + ["M", 0.02], + ["N", 0.02], + ["R", 0.02], + ["S", 0.02], + ["V", 0.02], + ["W", 0.02], + ["Y", 0.02], +] +homosapiens = [ + ["a", 0.3029549426680], + ["c", 0.1979883004921], + ["g", 0.1975473066391], + ["t", 0.3015094502008], +] + +def make_repeat_fasta(id, desc, src, n) + puts ">#{id} #{desc}" + v = nil + width = 60 + l = src.length + s = src * ((n / l) + 1) + s.slice!(n, l) + puts(s.scan(/.{1,#{width}}/).join("\n")) +end + +def make_random_fasta(id, desc, table, n) + puts ">#{id} #{desc}" + rand, v = nil,nil + width = 60 + chunk = 1 * width + prob = 0.0 + table.each{|v| v[1]= (prob += v[1])} + for i in 1..(n/width) + puts((1..width).collect{ + rand = gen_random(1.0) + table.find{|v| v[1]>rand}[0] + }.join) + end + if n%width != 0 + puts((1..(n%width)).collect{ + rand = gen_random(1.0) + table.find{|v| v[1]>rand}[0] + }.join) + end +end + + +n = (ARGV[0] or 250_000).to_i + +make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2) +make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3) +make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5) + diff --git a/benchmark/bm_so_lists.rb b/benchmark/bm_so_lists.rb new file mode 100644 index 0000000000..e8f4a2a5f7 --- /dev/null +++ b/benchmark/bm_so_lists.rb @@ -0,0 +1,47 @@ +#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby + +NUM = 300 +SIZE = 10000 + +def test_lists() + # create a list of integers (Li1) from 1 to SIZE + li1 = (1..SIZE).to_a + # copy the list to li2 (not by individual items) + li2 = li1.dup + # remove each individual item from left side of li2 and + # append to right side of li3 (preserving order) + li3 = Array.new + while (not li2.empty?) + li3.push(li2.shift) + end + # li2 must now be empty + # remove each individual item from right side of li3 and + # append to right side of li2 (reversing list) + while (not li3.empty?) + li2.push(li3.pop) + end + # li3 must now be empty + # reverse li1 in place + li1.reverse! + # check that first item is now SIZE + if li1[0] != SIZE then + p "not SIZE" + 0 + else + # compare li1 and li2 for equality + if li1 != li2 then + return(0) + else + # return the length of the list + li1.length + end + end +end + +i = 0 +while i LIMIT_SQUARED + escape = true + break + end + end + + byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) + bit_num += 1 + + # Code is very similar for these cases, but using separate blocks + # ensures we skip the shifting when it's unnecessary, which is most cases. + if (bit_num == 8) + print byte_acc.chr + byte_acc = 0 + bit_num = 0 + elsif (x == count_size) + byte_acc <<= (8 - bit_num) + print byte_acc.chr + byte_acc = 0 + bit_num = 0 + end + end +end diff --git a/benchmark/bm_so_matrix.rb b/benchmark/bm_so_matrix.rb new file mode 100644 index 0000000000..e2c5c8e559 --- /dev/null +++ b/benchmark/bm_so_matrix.rb @@ -0,0 +1,48 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ + +n = 60 #Integer(ARGV.shift || 1) + +size = 40 + +def mkmatrix(rows, cols) + count = 1 + mx = Array.new(rows) + (0 .. (rows - 1)).each do |bi| + row = Array.new(cols, 0) + (0 .. (cols - 1)).each do |j| + row[j] = count + count += 1 + end + mx[bi] = row + end + mx +end + +def mmult(rows, cols, m1, m2) + m3 = Array.new(rows) + (0 .. (rows - 1)).each do |bi| + row = Array.new(cols, 0) + (0 .. (cols - 1)).each do |j| + val = 0 + (0 .. (cols - 1)).each do |k| + val += m1.at(bi).at(k) * m2.at(k).at(j) + end + row[j] = val + end + m3[bi] = row + end + m3 +end + +m1 = mkmatrix(size, size) +m2 = mkmatrix(size, size) +mm = Array.new +n.times do + mm = mmult(size, size, m1, m2) +end +# puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" + + diff --git a/benchmark/bm_so_meteor_contest.rb b/benchmark/bm_so_meteor_contest.rb new file mode 100755 index 0000000000..8c136baa6c --- /dev/null +++ b/benchmark/bm_so_meteor_contest.rb @@ -0,0 +1,563 @@ +#!/usr/bin/env ruby +# +# The Computer Language Shootout +# http://shootout.alioth.debian.org +# contributed by Kevin Barnes (Ruby novice) + +# PROGRAM: the main body is at the bottom. +# 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ +# 2) see how I represent a board as a bitmask by reading the blank_board comments +# 3) read as your mental paths take you + +def print *args +end + +# class to represent all information about a particular rotation of a particular piece +class Rotation + # an array (by location) containing a bit mask for how the piece maps at the given location. + # if the rotation is invalid at that location the mask will contain false + attr_reader :start_masks + + # maps a direction to a relative location. these differ depending on whether it is an even or + # odd row being mapped from + @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 } + @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 } + + def initialize( directions ) + @even_offsets, @odd_offsets = normalize_offsets( get_values( directions )) + + @even_mask = mask_for_offsets( @even_offsets) + @odd_mask = mask_for_offsets( @odd_offsets) + + @start_masks = Array.new(60) + + # create the rotational masks by placing the base mask at the location and seeing if + # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these + # is true the piece cannot be placed + 0.upto(59) do | offset | + mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset) + if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then + imask = compute_required( mask, offset) + @start_masks[offset] = [ mask, imask, imask | mask ] + else + @start_masks[offset] = false + end + end + end + + def compute_required( mask, offset ) + board = blank_board + 0.upto(offset) { | i | board |= 1 << i } + board |= mask + return 0 if (!prunable(board | mask, offset)) + board = flood_fill(board,58) + count = 0 + imask = 0 + 0.upto(59) do | i | + if (board[i] == 0) then + imask |= (1 << i) + count += 1 + end + end + (count > 0 && count < 5) ? imask : 0 + end + + def flood_fill( board, location) + return board if (board[location] == 1) + board |= 1 << location + row, col = location.divmod(6) + board = flood_fill( board, location - 1) if (col > 0) + board = flood_fill( board, location + 1) if (col < 4) + if (row % 2 == 0) then + board = flood_fill( board, location - 7) if (col > 0 && row > 0) + board = flood_fill( board, location - 6) if (row > 0) + board = flood_fill( board, location + 6) if (row < 9) + board = flood_fill( board, location + 5) if (col > 0 && row < 9) + else + board = flood_fill( board, location - 5) if (col < 4 && row > 0) + board = flood_fill( board, location - 6) if (row > 0) + board = flood_fill( board, location + 6) if (row < 9) + board = flood_fill( board, location + 7) if (col < 4 && row < 9) + end + board + end + + # given a location, produces a list of relative locations covered by the piece at this rotation + def offsets( location) + if is_even( location) then + @even_offsets.collect { | value | value + location } + else + @odd_offsets.collect { | value | value + location } + end + end + + # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows) + # this is hard to explain. imagine we have this partial board: + # 0 0 0 0 0 x [positions 0-5] + # 0 0 1 1 0 x [positions 6-11] + # 0 0 1 0 0 x [positions 12-17] + # 0 1 0 0 0 x [positions 18-23] + # 0 1 0 0 0 x [positions 24-29] + # 0 0 0 0 0 x [positions 30-35] + # ... + # The top-left of the piece is at position 8, the + # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that + # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained + # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row: + # 0 0 0 1 1 x [positions 0-5] + # 0 0 1 0 0 x [positions 6-11] + # 0 0 1 0 0 x [positions 12-17] + # 0 1 0 0 0 x [positions 18-23] + # 0 0 0 0 0 x [positions 24-29] + # 0 0 0 0 0 x [positions 30-35] + # ... + # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the + # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what + # this function would return + def normalize_offsets( values) + min = values.min + even_min = is_even(min) + other_min = even_min ? min + 6 : min + 7 + other_values = values.collect do | value | + if is_even(value) then + value + 6 - other_min + else + value + 7 - other_min + end + end + values.collect! { | value | value - min } + + if even_min then + [values, other_values] + else + [other_values, values] + end + end + + # produce a bitmask representation of an array of offset locations + def mask_for_offsets( offsets ) + mask = 0 + offsets.each { | value | mask = mask + ( 1 << value ) } + mask + end + + # finds a "safe" position that a position as described by a list of directions can be placed + # without falling off any edge of the board. the values returned a location to place the first piece + # at so it will fit after making the described moves + def start_adjust( directions ) + south = east = 0; + directions.each do | direction | + east += 1 if ( direction == :sw || direction == :nw || direction == :west ) + south += 1 if ( direction == :nw || direction == :ne ) + end + south * 6 + east + end + + # given a set of directions places the piece (as defined by a set of directions) on the board at + # a location that will not take it off the edge + def get_values( directions ) + start = start_adjust(directions) + values = [ start ] + directions.each do | direction | + if (start % 12 >= 6) then + start += @@rotation_odd_adder[direction] + else + start += @@rotation_even_adder[direction] + end + values += [ start ] + end + + # some moves take you back to an existing location, we'll strip duplicates + values.uniq + end +end + +# describes a piece and caches information about its rotations to as to be efficient for iteration +# ATTRIBUTES: +# rotations -- all the rotations of the piece +# type -- a numeic "name" of the piece +# masks -- an array by location of all legal rotational masks (a n inner array) for that location +# placed -- the mask that this piece was last placed at (not a location, but the actual mask used) +class Piece + attr_reader :rotations, :type, :masks + attr_accessor :placed + + # transform hashes that change one direction into another when you either flip or rotate a set of directions + @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne } + @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw } + + def initialize( directions, type ) + @type = type + @rotations = Array.new(); + @map = {} + + generate_rotations( directions ) + directions.collect! { | value | @@flip_converter[value] } + generate_rotations( directions ) + + # creates the masks AND a map that returns [location, rotation] for any given mask + # this is used when a board is found and we want to draw it, otherwise the map is unused + @masks = Array.new(); + 0.upto(59) do | i | + even = true + @masks[i] = @rotations.collect do | rotation | + mask = rotation.start_masks[i] + @map[mask[0]] = [ i, rotation ] if (mask) + mask || nil + end + @masks[i].compact! + end + end + + # rotates a set of directions through all six angles and adds a Rotation to the list for each one + def generate_rotations( directions ) + 6.times do + rotations.push( Rotation.new(directions)) + directions.collect! { | value | @@rotate_converter[value] } + end + end + + # given a board string, adds this piece to the board at whatever location/rotation + # important: the outbound board string is 5 wide, the normal location notation is six wide (padded) + def fill_string( board_string) + location, rotation = @map[@placed] + rotation.offsets(location).each do | offset | + row, col = offset.divmod(6) + board_string[ row*5 + col, 1 ] = @type.to_s + end + end +end + +# a blank bit board having this form: +# +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 0 0 0 0 0 1 +# 1 1 1 1 1 1 +# +# where left lest significant bit is the top left and the most significant is the lower right +# the actual board only consists of the 0 places, the 1 places are blockers to keep things from running +# off the edges or bottom +def blank_board + 0b111111100000100000100000100000100000100000100000100000100000100000 +end + +def full_board + 0b111111111111111111111111111111111111111111111111111111111111111111 +end + +# determines if a location (bit position) is in an even row +def is_even( location) + (location % 12) < 6 +end + +# support function that create three utility maps: +# $converter -- for each row an array that maps a five bit row (via array mapping) +# to the a five bit representation of the bits below it +# $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row +# @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays +# a region array has three values the first is a mask of bits in the region, +# the second is the count of those bits and the third is identical to the first +# examples: +# 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001] +# 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001] +# 0b10001 => [ 0b01110, 3, 0b01110 ] +def create_collector_support + odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000] + even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000] + + all_odds = Array.new(0b100000) + all_evens = Array.new(0b100000) + bit_counts = Array.new(0b100000) + new_regions = Array.new(0b100000) + 0.upto(0b11111) do | i | + bit_count = odd = even = 0 + 0.upto(4) do | bit | + if (i[bit] == 1) then + bit_count += 1 + odd |= odd_map[bit] + even |= even_map[bit] + end + end + all_odds[i] = odd + all_evens[i] = even + bit_counts[i] = bit_count + new_regions[i] = create_regions( i) + end + + $converter = [] + 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) } + $bit_counts = bit_counts + $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } } +end + +# determines if a board is punable, meaning that there is no possibility that it +# can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces +# that are not a multiple of five. The following board is an example of a prunable board: +# 0 0 1 0 0 +# 0 1 0 0 0 +# 1 1 0 0 0 +# 0 1 0 0 0 +# 0 0 0 0 0 +# ... +# +# This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it +# parameters: +# board -- an initial bit board (6 bit padded rows, see blank_board for format) +# location -- starting location, everything above and to the left is already full +# slotting -- set to true only when testing initial pieces, when filling normally +# additional assumptions are possible +# +# Algorithm: +# The algorithm starts at the top row (as determined by location) and iterates a row at a time +# maintainng counts of active open areas (kept in the collector array) each collector contains +# three values at the start of an iteration: +# 0: mask of bits that would be adjacent to the collector in this row +# 1: the number of bits collected so far +# 2: a scratch space starting as zero, but used during the computation to represent +# the empty bits in the new row that are adjacent (position 0) +# The exact procedure is described in-code +def prunable( board, location, slotting = false) + collectors = [] + # loop across the rows + (location / 6).to_i.upto(9) do | row_on | + # obtain a set of regions representing the bits of the current row. + regions = $regions[(board >> (row_on * 6)) & 0b11111] + converter = $converter[row_on] + + # track the number of collectors at the start of the cycle so that + # we don't compute against newly created collectors, only existing collectors + initial_collector_count = collectors.length + + # loop against the regions. For each region of the row + # we will see if it connects to one or more existing collectors. + # if it connects to 1 collector, the bits from the region are added to the + # bits of the collector and the mask is placed in collector[2] + # If the region overlaps more than one collector then all the collectors + # it overlaps with are merged into the first one (the others are set to nil in the array) + # if NO collectors are found then the region is copied as a new collector + regions.each do | region | + collector_found = nil + region_mask = region[2] + initial_collector_count.times do | collector_num | + collector = collectors[collector_num] + if (collector) then + collector_mask = collector[0] + if (collector_mask & region_mask != 0) then + if (collector_found) then + collector_found[0] |= collector_mask + collector_found[1] += collector[1] + collector_found[2] |= collector[2] + collectors[collector_num] = nil + else + collector_found = collector + collector[1] += region[1] + collector[2] |= region_mask + end + end + end + end + if (collector_found == nil) then + collectors.push(Array.new(region)) + end + end + + # check the existing collectors, if any collector overlapped no bits in the region its [2] value will + # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since + # the board is prunable. if it is a multiple of five it is removed. + # Collector that are still active have a new adjacent value [0] set based n the matched bits + # and have [2] cleared out for the next cycle. + collectors.length.times do | collector_num | + collector = collectors[collector_num] + if (collector) then + if (collector[2] == 0) then + return true if (collector[1] % 5 != 0) + collectors[collector_num] = nil + else + # if a collector matches all bits in the row then we can return unprunable early for the + # following reasons: + # 1) there can be no more unavailable bits bince we fill from the top left downward + # 2) all previous regions have been closed or joined so only this region can fail + # 3) this region must be good since there can never be only 1 region that is nuot + # a multiple of five + # this rule only applies when filling normally, so we ignore the rule if we are "slotting" + # in pieces to see what configurations work for them (the only other time this algorithm is used). + return false if (collector[2] == 0b11111 && !slotting) + collector[0] = converter[collector[2]] + collector[2] = 0 + end + end + end + + # get rid of all the empty converters for the next round + collectors.compact! + end + return false if (collectors.length <= 1) # 1 collector or less and the region is fine + collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size +end + +# creates a region given a row mask. see prunable for what a "region" is +def create_regions( value ) + regions = [] + cur_region = 0 + 5.times do | bit | + if (value[bit] == 0) then + cur_region |= 1 << bit + else + if (cur_region != 0 ) then + regions.push( cur_region) + cur_region = 0; + end + end + end + regions.push(cur_region) if (cur_region != 0) + regions +end + +# find up to the counted number of solutions (or all solutions) and prints the final result +def find_all + find_top( 1) + find_top( 0) + print_results +end + +# show the board +def print_results + print "#{@boards_found} solutions found\n\n" + print_full_board( @min_board) + print "\n" + print_full_board( @max_board) + print "\n" +end + +# finds solutions. This special version of the main function is only used for the top level +# the reason for it is basically to force a particular ordering on how the rotations are tested for +# the first piece. It is called twice, first looking for placements of the odd rotations and then +# looking for placements of the even locations. +# +# WHY? +# Since any found solution has an inverse we want to maximize finding solutions that are not already found +# as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away +# (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier +# in the cycle. We still need to keep checking all the permutations, but our probability of finding one will +# diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces +# this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the +# maximum number +def find_top( rotation_skip) + board = blank_board + (@pieces.length-1).times do + piece = @pieces.shift + piece.masks[0].each do | mask, imask, cmask | + if ((rotation_skip += 1) % 2 == 0) then + piece.placed = mask + find( 1, 1, board | mask) + end + end + @pieces.push(piece) + end + piece = @pieces.shift + @pieces.push(piece) +end + +# the normail find routine, iterates through the available pieces, checks all rotations at the current location +# and adds any boards found. depth is achieved via recursion. the overall approach is described +# here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ +# parameters: +# start_location -- where to start looking for place for the next piece at +# placed -- number of pieces placed +# board -- current state of the board +# +# see in-code comments +def find( start_location, placed, board) + # find the next location to place a piece by looking for an empty bit + while board[start_location] == 1 + start_location += 1 + end + + @pieces.length.times do + piece = @pieces.shift + piece.masks[start_location].each do | mask, imask, cmask | + if ( board & cmask == imask) then + piece.placed = mask + if (placed == 9) then + add_board + else + find( start_location + 1, placed + 1, board | mask) + end + end + end + @pieces.push(piece) + end +end + +# print the board +def print_full_board( board_string) + 10.times do | row | + print " " if (row % 2 == 1) + 5.times do | col | + print "#{board_string[row*5 + col,1]} " + end + print "\n" + end +end + +# when a board is found we "draw it" into a string and then flip that string, adding both to +# the list (hash) of solutions if they are unique. +def add_board + board_string = "99999999999999999999999999999999999999999999999999" + @all_pieces.each { | piece | piece.fill_string( board_string ) } + save( board_string) + save( board_string.reverse) +end + +# adds a board string to the list (if new) and updates the current best/worst board +def save( board_string) + if (@all_boards[board_string] == nil) then + @min_board = board_string if (board_string < @min_board) + @max_board = board_string if (board_string > @max_board) + @all_boards.store(board_string,true) + @boards_found += 1 + + # the exit motif is a time saver. Ideally the function should return, but those tests + # take noticeable time (performance). + if (@boards_found == @stop_count) then + print_results + exit(0) + end + end +end + + +## +## MAIN BODY :) +## +create_collector_support +@pieces = [ + Piece.new( [ :nw, :ne, :east, :east ], 2), + Piece.new( [ :ne, :se, :east, :ne ], 7), + Piece.new( [ :ne, :east, :ne, :nw ], 1), + Piece.new( [ :east, :sw, :sw, :se ], 6), + Piece.new( [ :east, :ne, :se, :ne ], 5), + Piece.new( [ :east, :east, :east, :se ], 0), + Piece.new( [ :ne, :nw, :se, :east, :se ], 4), + Piece.new( [ :se, :se, :se, :west ], 9), + Piece.new( [ :se, :se, :east, :se ], 8), + Piece.new( [ :east, :east, :sw, :se ], 3) + ]; + +@all_pieces = Array.new( @pieces) + +@min_board = "99999999999999999999999999999999999999999999999999" +@max_board = "00000000000000000000000000000000000000000000000000" +@stop_count = ARGV[0].to_i || 2089 +@all_boards = {} +@boards_found = 0 + +find_all ######## DO IT!!! diff --git a/benchmark/bm_so_nbody.rb b/benchmark/bm_so_nbody.rb new file mode 100644 index 0000000000..d6c5bb9e61 --- /dev/null +++ b/benchmark/bm_so_nbody.rb @@ -0,0 +1,148 @@ +# The Computer Language Shootout +# http://shootout.alioth.debian.org +# +# Optimized for Ruby by Jesse Millikan +# From version ported by Michael Neumann from the C gcc version, +# which was written by Christoph Bauer. + +SOLAR_MASS = 4 * Math::PI**2 +DAYS_PER_YEAR = 365.24 + +def _puts *args +end + +class Planet + attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass + + def initialize(x, y, z, vx, vy, vz, mass) + @x, @y, @z = x, y, z + @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR + @mass = mass * SOLAR_MASS + end + + def move_from_i(bodies, nbodies, dt, i) + while i < nbodies + b2 = bodies[i] + dx = @x - b2.x + dy = @y - b2.y + dz = @z - b2.z + + distance = Math.sqrt(dx * dx + dy * dy + dz * dz) + mag = dt / (distance * distance * distance) + b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag + + @vx -= dx * b2_mass_mag + @vy -= dy * b2_mass_mag + @vz -= dz * b2_mass_mag + b2.vx += dx * b_mass_mag + b2.vy += dy * b_mass_mag + b2.vz += dz * b_mass_mag + i += 1 + end + + @x += dt * @vx + @y += dt * @vy + @z += dt * @vz + end +end + +def energy(bodies) + e = 0.0 + nbodies = bodies.size + + for i in 0 ... nbodies + b = bodies[i] + e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) + for j in (i + 1) ... nbodies + b2 = bodies[j] + dx = b.x - b2.x + dy = b.y - b2.y + dz = b.z - b2.z + distance = Math.sqrt(dx * dx + dy * dy + dz * dz) + e -= (b.mass * b2.mass) / distance + end + end + e +end + +def offset_momentum(bodies) + px, py, pz = 0.0, 0.0, 0.0 + + for b in bodies + m = b.mass + px += b.vx * m + py += b.vy * m + pz += b.vz * m + end + + b = bodies[0] + b.vx = - px / SOLAR_MASS + b.vy = - py / SOLAR_MASS + b.vz = - pz / SOLAR_MASS +end + +BODIES = [ + # sun + Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), + + # jupiter + Planet.new( + 4.84143144246472090e+00, + -1.16032004402742839e+00, + -1.03622044471123109e-01, + 1.66007664274403694e-03, + 7.69901118419740425e-03, + -6.90460016972063023e-05, + 9.54791938424326609e-04), + + # saturn + Planet.new( + 8.34336671824457987e+00, + 4.12479856412430479e+00, + -4.03523417114321381e-01, + -2.76742510726862411e-03, + 4.99852801234917238e-03, + 2.30417297573763929e-05, + 2.85885980666130812e-04), + + # uranus + Planet.new( + 1.28943695621391310e+01, + -1.51111514016986312e+01, + -2.23307578892655734e-01, + 2.96460137564761618e-03, + 2.37847173959480950e-03, + -2.96589568540237556e-05, + 4.36624404335156298e-05), + + # neptune + Planet.new( + 1.53796971148509165e+01, + -2.59193146099879641e+01, + 1.79258772950371181e-01, + 2.68067772490389322e-03, + 1.62824170038242295e-03, + -9.51592254519715870e-05, + 5.15138902046611451e-05) +] + +init = 200_000 # ARGV[0] +n = Integer(init) + +offset_momentum(BODIES) + +puts "%.9f" % energy(BODIES) + +nbodies = BODIES.size +dt = 0.01 + +n.times do + i = 0 + while i < nbodies + b = BODIES[i] + b.move_from_i(BODIES, nbodies, dt, i + 1) + i += 1 + end +end + +puts "%.9f" % energy(BODIES) diff --git a/benchmark/bm_so_nested_loop.rb b/benchmark/bm_so_nested_loop.rb new file mode 100644 index 0000000000..a0513f8c47 --- /dev/null +++ b/benchmark/bm_so_nested_loop.rb @@ -0,0 +1,24 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ +# from Avi Bryant + +n = 16 # Integer(ARGV.shift || 1) +x = 0 +n.times do + n.times do + n.times do + n.times do + n.times do + n.times do + x += 1 + end + end + end + end + end +end +# puts x + + diff --git a/benchmark/bm_so_nsieve.rb b/benchmark/bm_so_nsieve.rb new file mode 100644 index 0000000000..a65cc78233 --- /dev/null +++ b/benchmark/bm_so_nsieve.rb @@ -0,0 +1,35 @@ +# The Computer Language Shootout +# http://shootout.alioth.debian.org/ +# +# contributed by Glenn Parker, March 2005 +# modified by Evan Phoenix, Sept 2006 + +def sieve(m) + flags = Flags.dup[0,m] + count = 0 + pmax = m - 1 + p = 2 + while p <= pmax + unless flags[p].zero? + count += 1 + mult = p + while mult <= pmax + flags[mult] = 0 + mult += p + end + end + p += 1 + end + count +end + +n = 9 # (ARGV[0] || 2).to_i +Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*") + +n.downto(n-2) do |exponent| + break if exponent < 0 + m = (1 << exponent) * 10_000 + # m = (2 ** exponent) * 10_000 + count = sieve(m) + printf "Primes up to %8d %8d\n", m, count +end diff --git a/benchmark/bm_so_nsieve_bits.rb b/benchmark/bm_so_nsieve_bits.rb new file mode 100644 index 0000000000..6f958ee44e --- /dev/null +++ b/benchmark/bm_so_nsieve_bits.rb @@ -0,0 +1,43 @@ +#!/usr/bin/ruby +#coding: us-ascii +# +# The Great Computer Language Shootout +# http://shootout.alioth.debian.org/ +# +# nsieve-bits in Ruby +# Contributed by Glenn Parker, March 2005 + +CharExponent = 3 +BitsPerChar = 1 << CharExponent +LowMask = BitsPerChar - 1 + +def sieve(m) + items = "\xFF" * ((m / BitsPerChar) + 1) + masks = "" + BitsPerChar.times do |b| + masks << (1 << b).chr + end + + count = 0 + pmax = m - 1 + 2.step(pmax, 1) do |p| + if items[p >> CharExponent][p & LowMask] == 1 + count += 1 + p.step(pmax, p) do |mult| + a = mult >> CharExponent + b = mult & LowMask + items[a] -= masks[b] if items[a][b] != 0 + end + end + end + count +end + +n = 9 # (ARGV[0] || 2).to_i +n.step(n - 2, -1) do |exponent| + break if exponent < 0 + m = 2 ** exponent * 10_000 + count = sieve(m) + printf "Primes up to %8d %8d\n", m, count +end + diff --git a/benchmark/bm_so_object.rb b/benchmark/bm_so_object.rb new file mode 100644 index 0000000000..e8607c7199 --- /dev/null +++ b/benchmark/bm_so_object.rb @@ -0,0 +1,56 @@ +#!/usr/bin/ruby +# -*- mode: ruby -*- +# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ +# http://www.bagley.org/~doug/shootout/ +# with help from Aristarkh Zagorodnikov + +class Toggle + def initialize(start_state) + @bool = start_state + end + + def value + @bool + end + + def activate + @bool = !@bool + self + end +end + +class NthToggle < Toggle + def initialize(start_state, max_counter) + super start_state + @count_max = max_counter + @counter = 0 + end + + def activate + @counter += 1 + if @counter >= @count_max + @bool = !@bool + @counter = 0 + end + self + end +end + +n = 1500000 # (ARGV.shift || 1).to_i + +toggle = Toggle.new 1 +5.times do + toggle.activate.value ? 'true' : 'false' +end +n.times do + toggle = Toggle.new 1 +end + +ntoggle = NthToggle.new 1, 3 +8.times do + ntoggle.activate.value ? 'true' : 'false' +end +n.times do + ntoggle = NthToggle.new 1, 3 +end + diff --git a/benchmark/bm_so_partial_sums.rb b/benchmark/bm_so_partial_sums.rb new file mode 100644 index 0000000000..630b45cb8d --- /dev/null +++ b/benchmark/bm_so_partial_sums.rb @@ -0,0 +1,31 @@ +n = 2_500_000 # (ARGV.shift || 1).to_i + +alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0 + +1.upto(n) do |d| + d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d) + + s0 += (2.0 / 3.0) ** (d - 1.0) + s1 += 1.0 / Math.sqrt(d) + s2 += 1.0 / (d * (d + 1.0)) + s3 += 1.0 / (d3 * ds * ds) + s4 += 1.0 / (d3 * dc * dc) + s5 += 1.0 / d + s6 += 1.0 / d2 + s7 += alt / d + s8 += alt / (2.0 * d - 1.0) + + alt = -alt +end + +if false + printf("%.9f\t(2/3)^k\n", s0) + printf("%.9f\tk^-0.5\n", s1) + printf("%.9f\t1/k(k+1)\n", s2) + printf("%.9f\tFlint Hills\n", s3) + printf("%.9f\tCookson Hills\n", s4) + printf("%.9f\tHarmonic\n", s5) + printf("%.9f\tRiemann Zeta\n", s6) + printf("%.9f\tAlternating Harmonic\n", s7) + printf("%.9f\tGregory\n", s8) +end diff --git a/benchmark/bm_so_pidigits.rb b/benchmark/bm_so_pidigits.rb new file mode 100644 index 0000000000..9a537b2d1c --- /dev/null +++ b/benchmark/bm_so_pidigits.rb @@ -0,0 +1,92 @@ +# The Great Computer Language Shootout +# http://shootout.alioth.debian.org/ +# +# contributed by Gabriele Renzi + +class PiDigitSpigot + + def initialize() + @z = Transformation.new 1,0,0,1 + @x = Transformation.new 0,0,0,0 + @inverse = Transformation.new 0,0,0,0 + end + + def next! + @y = @z.extract(3) + if safe? @y + @z = produce(@y) + @y + else + @z = consume @x.next!() + next!() + end + end + + def safe?(digit) + digit == @z.extract(4) + end + + def produce(i) + @inverse.qrst(10,-10*i,0,1).compose(@z) + end + + def consume(a) + @z.compose(a) + end +end + + +class Transformation + attr_reader :q, :r, :s, :t + def initialize(q, r, s, t) + @q,@r,@s,@t,@k = q,r,s,t,0 + end + + def next!() + @q = @k = @k + 1 + @r = 4 * @k + 2 + @s = 0 + @t = 2 * @k + 1 + self + end + + def extract(j) + (@q * j + @r) / (@s * j + @t) + end + + def compose(a) + self.class.new( @q * a.q, + @q * a.r + r * a.t, + @s * a.q + t * a.s, + @s * a.r + t * a.t + ) + end + + def qrst *args + initialize *args + self + end + + +end + + +WIDTH = 10 +n = 2_500 # Integer(ARGV[0]) +j = 0 + +digits = PiDigitSpigot.new + +while n > 0 + if n >= WIDTH + WIDTH.times {print digits.next!} + j += WIDTH + else + n.times {print digits.next!} + (WIDTH-n).times {print " "} + j += n + end + puts "\t:"+j.to_s + n -= WIDTH +end + diff --git a/benchmark/bm_so_random.rb b/benchmark/bm_so_random.rb new file mode 100644 index 0000000000..a66b9e8e63 --- /dev/null +++ b/benchmark/bm_so_random.rb @@ -0,0 +1,20 @@ +# from http://www.bagley.org/~doug/shootout/bench/random/random.ruby + +IM = 139968.0 +IA = 3877.0 +IC = 29573.0 + +$last = 42.0 + +def gen_random(max) + (max * ($last = ($last * IA + IC) % IM)) / IM +end + +N = 3_000_000 + +i = 0 +while i"yyyy"} + end + GC.start +end diff --git a/benchmark/bm_vm3_gc_old_full.rb b/benchmark/bm_vm3_gc_old_full.rb new file mode 100644 index 0000000000..cfdfc8c5a5 --- /dev/null +++ b/benchmark/bm_vm3_gc_old_full.rb @@ -0,0 +1,4 @@ +old_object = Array.new(1_000_000){''} +100.times do + GC.start +end diff --git a/benchmark/bm_vm3_gc_old_immediate.rb b/benchmark/bm_vm3_gc_old_immediate.rb new file mode 100644 index 0000000000..ad22feb655 --- /dev/null +++ b/benchmark/bm_vm3_gc_old_immediate.rb @@ -0,0 +1,4 @@ +old_object = Array.new(1_000_000){''} +30_000.times do + GC.start(full_mark: false, immediate_sweep: true) +end diff --git a/benchmark/bm_vm3_gc_old_lazy.rb b/benchmark/bm_vm3_gc_old_lazy.rb new file mode 100644 index 0000000000..b74d44baf1 --- /dev/null +++ b/benchmark/bm_vm3_gc_old_lazy.rb @@ -0,0 +1,4 @@ +old_object = Array.new(1_000_000){''} +30_000.times do + GC.start(full_mark: false, immediate_sweep: false) +end diff --git a/benchmark/bm_vm_symbol_block_pass.rb b/benchmark/bm_vm_symbol_block_pass.rb new file mode 100644 index 0000000000..1d433353e1 --- /dev/null +++ b/benchmark/bm_vm_symbol_block_pass.rb @@ -0,0 +1,13 @@ +class C + 1000.times {|i| + eval("def i#{i};end") + } +end + +c = C.new +m = C.instance_methods(false) +5_000.times do + m.each do |n| + c.tap(&n) + end +end diff --git a/benchmark/bm_vm_thread_alive_check1.rb b/benchmark/bm_vm_thread_alive_check1.rb new file mode 100644 index 0000000000..c993accdda --- /dev/null +++ b/benchmark/bm_vm_thread_alive_check1.rb @@ -0,0 +1,6 @@ +5_000.times{ + t = Thread.new{} + while t.alive? + Thread.pass + end +} diff --git a/benchmark/bm_vm_thread_close.rb b/benchmark/bm_vm_thread_close.rb new file mode 100644 index 0000000000..3e9a265ce8 --- /dev/null +++ b/benchmark/bm_vm_thread_close.rb @@ -0,0 +1,6 @@ +1000.times { Thread.new { sleep } } +i = 0 +while i<100_000 # benchmark loop 3 + i += 1 + IO.pipe.each(&:close) +end diff --git a/benchmark/bm_vm_thread_condvar1.rb b/benchmark/bm_vm_thread_condvar1.rb new file mode 100644 index 0000000000..cf5706b23e --- /dev/null +++ b/benchmark/bm_vm_thread_condvar1.rb @@ -0,0 +1,28 @@ +# two threads, two mutex, two condvar ping-pong +require 'thread' +m1 = Mutex.new +m2 = Mutex.new +cv1 = ConditionVariable.new +cv2 = ConditionVariable.new +max = 100000 +i = 0 +wait = nil +m2.synchronize do + wait = Thread.new do + m1.synchronize do + m2.synchronize { cv2.signal } + while (i += 1) < max + cv1.wait(m1) + cv2.signal + end + end + end + cv2.wait(m2) +end +m1.synchronize do + while i < max + cv1.signal + cv2.wait(m1) + end +end +wait.join diff --git a/benchmark/bm_vm_thread_condvar2.rb b/benchmark/bm_vm_thread_condvar2.rb new file mode 100644 index 0000000000..7c8dc19481 --- /dev/null +++ b/benchmark/bm_vm_thread_condvar2.rb @@ -0,0 +1,35 @@ +# many threads, one mutex, many condvars +require 'thread' +m = Mutex.new +cv1 = ConditionVariable.new +cv2 = ConditionVariable.new +max = 1000 +n = 100 +waiting = 0 +scvs = [] +waiters = n.times.map do |i| + start_cv = ConditionVariable.new + scvs << start_cv + start_mtx = Mutex.new + start_mtx.synchronize do + th = Thread.new(start_mtx, start_cv) do |sm, scv| + m.synchronize do + sm.synchronize { scv.signal } + max.times do + cv2.signal if (waiting += 1) == n + cv1.wait(m) + end + end + end + start_cv.wait(start_mtx) + th + end +end +m.synchronize do + max.times do + cv2.wait(m) until waiting == n + waiting = 0 + cv1.broadcast + end +end +waiters.each(&:join) diff --git a/benchmark/bm_vm_thread_create_join.rb b/benchmark/bm_vm_thread_create_join.rb new file mode 100644 index 0000000000..393cd45df9 --- /dev/null +++ b/benchmark/bm_vm_thread_create_join.rb @@ -0,0 +1,6 @@ +i = 0 +while i<100_000 # benchmark loop 3 + i += 1 + Thread.new{ + }.join +end diff --git a/benchmark/bm_vm_thread_mutex1.rb b/benchmark/bm_vm_thread_mutex1.rb new file mode 100644 index 0000000000..66e42c85e1 --- /dev/null +++ b/benchmark/bm_vm_thread_mutex1.rb @@ -0,0 +1,21 @@ +# one thread, one mutex (no contention) + +require 'thread' +m = Thread::Mutex.new +r = 0 +max = 2000 +lmax = max * max +(1..1).map{ + Thread.new{ + i = 0 + while i 0 + q.push true + n -= 1 + end + q.push nil +} + +consumer.join diff --git a/benchmark/bm_vm_thread_sized_queue2.rb b/benchmark/bm_vm_thread_sized_queue2.rb new file mode 100644 index 0000000000..de9f55e978 --- /dev/null +++ b/benchmark/bm_vm_thread_sized_queue2.rb @@ -0,0 +1,23 @@ +require 'thread' +# one producer, many consumers +n = 1_000_000 +m = 10 +q = Thread::SizedQueue.new(100) +consumers = m.times.map do + Thread.new do + while q.pop + # consuming + end + end +end + +producer = Thread.new do + while n > 0 + q.push true + n -= 1 + end + m.times { q.push nil } +end + +producer.join +consumers.each(&:join) diff --git a/benchmark/bm_vm_thread_sized_queue3.rb b/benchmark/bm_vm_thread_sized_queue3.rb new file mode 100644 index 0000000000..ce5f1796d8 --- /dev/null +++ b/benchmark/bm_vm_thread_sized_queue3.rb @@ -0,0 +1,22 @@ +require 'thread' +# many producers, one consumer +n = 1_000_000 +m = 10 +q = Thread::SizedQueue.new(100) +consumer = Thread.new do + while q.pop + # consuming + end +end + +producers = m.times.map do + Thread.new do + while n > 0 + q.push true + n -= 1 + end + end +end +producers.each(&:join) +q.push nil +consumer.join diff --git a/benchmark/bm_vm_thread_sized_queue4.rb b/benchmark/bm_vm_thread_sized_queue4.rb new file mode 100644 index 0000000000..a9b7d80ec0 --- /dev/null +++ b/benchmark/bm_vm_thread_sized_queue4.rb @@ -0,0 +1,26 @@ +require 'thread' +# many producers, many consumers +nr = 1_000_000 +n = 10 +m = 10 +q = Thread::SizedQueue.new(100) +consumers = n.times.map do + Thread.new do + while q.pop + # consuming + end + end +end + +producers = m.times.map do + Thread.new do + while nr > 0 + q.push true + nr -= 1 + end + end +end + +producers.each(&:join) +n.times { q.push nil } +consumers.each(&:join) diff --git a/benchmark/dir_empty_p.yml b/benchmark/dir_empty_p.yml deleted file mode 100644 index 73e59bec98..0000000000 --- a/benchmark/dir_empty_p.yml +++ /dev/null @@ -1,8 +0,0 @@ -benchmark: - dir_empty_p: | - require 'tmpdir' - max = 100_000 - Dir.mktmpdir('bm_dir_empty_p') do |dir| - max.times { Dir.empty?(dir) } - end -loop_count: 1 diff --git a/benchmark/erb_render.yml b/benchmark/erb_render.yml deleted file mode 100644 index 33f23b2761..0000000000 --- a/benchmark/erb_render.yml +++ /dev/null @@ -1,28 +0,0 @@ -benchmark: - erb_render: | - require 'erb' - - data = < - <%= title %> - -

<%= title %>

-

- <%= content %> -

- - - erb - - max = 1_500_000 - title = "hello world!" - content = "hello world!\n" * 10 - - src = "def self.render(title, content); #{ERB.new(data).src}; end" - mod = Module.new - mod.instance_eval(src, "(ERB)") - - max.times do - mod.render(title, content) - end -loop_count: 1 diff --git a/benchmark/file_chmod.yml b/benchmark/file_chmod.yml deleted file mode 100644 index baa43ddd42..0000000000 --- a/benchmark/file_chmod.yml +++ /dev/null @@ -1,13 +0,0 @@ -prelude: | - # chmod file -benchmark: - file_chmod: | - require 'tempfile' - max = 200_000 - tmp = Tempfile.new('chmod') - path = tmp.path - max.times do - File.chmod(0777, path) - end - tmp.close! -loop_count: 1 diff --git a/benchmark/file_rename.yml b/benchmark/file_rename.yml deleted file mode 100644 index f337026c14..0000000000 --- a/benchmark/file_rename.yml +++ /dev/null @@ -1,15 +0,0 @@ -prelude: | - # rename file -benchmark: - file_rename: | - require 'tempfile' - - max = 100_000 - tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ] - a, b = tmp.map { |x| x.path } - tmp.each { |t| t.close } # Windows can't rename files without closing them - max.times do - File.rename(a, b) - File.rename(b, a) - end -loop_count: 1 diff --git a/benchmark/hash_aref_dsym.yml b/benchmark/hash_aref_dsym.yml deleted file mode 100644 index e862b5689c..0000000000 --- a/benchmark/hash_aref_dsym.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_aref_dsym: | - h = {} - syms = ('a'..'z').map { |s| s.to_sym } - syms.each { |s| h[s] = 1 } - 200_000.times { syms.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_dsym_long.yml b/benchmark/hash_aref_dsym_long.yml deleted file mode 100644 index 5488e052cd..0000000000 --- a/benchmark/hash_aref_dsym_long.yml +++ /dev/null @@ -1,25 +0,0 @@ -prelude: | - # [ruby-core:70129] [Bug #11396] -benchmark: - hash_aref_dsym_long: | - collection_size = 200000 - sample_size = 10000 - - values = (1..collection_size).to_a.map do |x| - "THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}" - end - - symbol_hash = {} - - values.each do |x| - symbol_hash[x.to_sym] = 1 - end - - # use the same samples each time to minimize deviations - rng = Random.new(0) - symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym) - - 3000.times do - symbol_sample_array.each { |x| symbol_hash[x] } - end -loop_count: 1 diff --git a/benchmark/hash_aref_fix.yml b/benchmark/hash_aref_fix.yml deleted file mode 100644 index 5469d2a2db..0000000000 --- a/benchmark/hash_aref_fix.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_aref_fix: | - h = {} - nums = (1..26).to_a - nums.each { |i| h[i] = i } - 200_000.times { nums.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_flo.yml b/benchmark/hash_aref_flo.yml deleted file mode 100644 index 2e3d8c887b..0000000000 --- a/benchmark/hash_aref_flo.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_aref_flo: | - h = {} - strs = [*1..10000].map! {|i| i.fdiv(10)} - strs.each { |s| h[s] = s } - 50.times { strs.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_miss.yml b/benchmark/hash_aref_miss.yml deleted file mode 100644 index 4bd541e2ff..0000000000 --- a/benchmark/hash_aref_miss.yml +++ /dev/null @@ -1,8 +0,0 @@ -benchmark: - hash_aref_miss: | - h = {} - strs = ('a'..'z').to_a.map!(&:freeze) - strs.each { |s| h[s] = s } - strs = ('A'..'Z').to_a - 200_000.times { strs.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_str.yml b/benchmark/hash_aref_str.yml deleted file mode 100644 index 0790320ec5..0000000000 --- a/benchmark/hash_aref_str.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_aref_str: | - h = {} - strs = ('a'..'z').to_a.map!(&:freeze) - strs.each { |s| h[s] = s } - 200_000.times { strs.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_sym.yml b/benchmark/hash_aref_sym.yml deleted file mode 100644 index e289d4aff3..0000000000 --- a/benchmark/hash_aref_sym.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - hash_aref_sym: | - h = {} - syms = ('a'..'z').to_a - begin - syms = eval("%i[#{syms.join(' ')}]") - rescue SyntaxError # <= 1.9.3 - syms.map!(&:to_sym) - end - syms.each { |s| h[s] = s } - 200_000.times { syms.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_aref_sym_long.yml b/benchmark/hash_aref_sym_long.yml deleted file mode 100644 index 4edccc12dd..0000000000 --- a/benchmark/hash_aref_sym_long.yml +++ /dev/null @@ -1,16 +0,0 @@ -benchmark: - hash_aref_sym_long: | - h = {} - syms = %w[puts warn syswrite write stat bacon lettuce tomato - some symbols in this array may already be interned others should not be - hash browns make good breakfast but not cooked using prime numbers - shift for division entries delete_if keys exist? - ] - begin - syms = eval("%i[#{syms.join(' ')}]") - rescue SyntaxError # <= 1.9.3 - syms.map!(&:to_sym) - end - syms.each { |s| h[s] = s } - 200_000.times { syms.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_flatten.yml b/benchmark/hash_flatten.yml deleted file mode 100644 index 0412388417..0000000000 --- a/benchmark/hash_flatten.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - hash_flatten: | - h = {} - - 10000.times do |i| - h[i] = nil - end - - 1000.times do - h.flatten - end -loop_count: 1 diff --git a/benchmark/hash_ident_flo.yml b/benchmark/hash_ident_flo.yml deleted file mode 100644 index ee2a78db44..0000000000 --- a/benchmark/hash_ident_flo.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_ident_flo: | - h = {}.compare_by_identity - strs = (1..10000).to_a.map!(&:to_f) - strs.each { |s| h[s] = s } - 50.times { strs.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_ident_num.yml b/benchmark/hash_ident_num.yml deleted file mode 100644 index c9b58bd0c6..0000000000 --- a/benchmark/hash_ident_num.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_ident_num: | - h = {}.compare_by_identity - nums = (1..26).to_a - nums.each { |n| h[n] = n } - 200_000.times { nums.each { |n| h[n] } } -loop_count: 1 diff --git a/benchmark/hash_ident_obj.yml b/benchmark/hash_ident_obj.yml deleted file mode 100644 index 95c310985f..0000000000 --- a/benchmark/hash_ident_obj.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_ident_obj: | - h = {}.compare_by_identity - objs = 26.times.map { Object.new } - objs.each { |o| h[o] = o } - 200_000.times { objs.each { |o| h[o] } } -loop_count: 1 diff --git a/benchmark/hash_ident_str.yml b/benchmark/hash_ident_str.yml deleted file mode 100644 index c2423778f7..0000000000 --- a/benchmark/hash_ident_str.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_ident_str: | - h = {}.compare_by_identity - strs = ('a'..'z').to_a - strs.each { |s| h[s] = s } - 200_000.times { strs.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_ident_sym.yml b/benchmark/hash_ident_sym.yml deleted file mode 100644 index e49bdba7f4..0000000000 --- a/benchmark/hash_ident_sym.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_ident_sym: | - h = {}.compare_by_identity - syms = ('a'..'z').to_a.map(&:to_sym) - syms.each { |s| h[s] = s } - 200_000.times { syms.each { |s| h[s] } } -loop_count: 1 diff --git a/benchmark/hash_keys.yml b/benchmark/hash_keys.yml deleted file mode 100644 index 18e9078640..0000000000 --- a/benchmark/hash_keys.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - hash_keys: | - h = {} - - 10000.times do |i| - h[i] = nil - end - - 5000.times do - h.keys - end -loop_count: 1 diff --git a/benchmark/hash_long.yml b/benchmark/hash_long.yml deleted file mode 100644 index 33c0c38f49..0000000000 --- a/benchmark/hash_long.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - hash_long: | - k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong"; - k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping"; - h = {k1 => 0, k2 => 0}; - 3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1} -loop_count: 1 diff --git a/benchmark/hash_shift.yml b/benchmark/hash_shift.yml deleted file mode 100644 index 954c1eb6fe..0000000000 --- a/benchmark/hash_shift.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - hash_shift: | - h = {} - - 10000.times do |i| - h[i] = nil - end - - 50000.times do - k, v = h.shift - h[k] = v - end -loop_count: 1 diff --git a/benchmark/hash_shift_u16.yml b/benchmark/hash_shift_u16.yml deleted file mode 100644 index b8e1ae75f4..0000000000 --- a/benchmark/hash_shift_u16.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - hash_shift_u16: | - h = {} - - (16384..65536).each do |i| - h[i] = nil - end - - 300000.times do - k, v = h.shift - h[k] = v - end -loop_count: 1 diff --git a/benchmark/hash_shift_u24.yml b/benchmark/hash_shift_u24.yml deleted file mode 100644 index 743d3cefc3..0000000000 --- a/benchmark/hash_shift_u24.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - hash_shift_u24: | - h = {} - - (0xff4000..0xffffff).each do |i| - h[i] = nil - end - - 300000.times do - k, v = h.shift - h[k] = v - end -loop_count: 1 diff --git a/benchmark/hash_shift_u32.yml b/benchmark/hash_shift_u32.yml deleted file mode 100644 index 96e9753dde..0000000000 --- a/benchmark/hash_shift_u32.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - hash_shift_u32: | - h = {} - - (0xffff4000..0xffffffff).each do |i| - h[i] = nil - end - - 300000.times do - k, v = h.shift - h[k] = v - end -loop_count: 1 diff --git a/benchmark/hash_small2.yml b/benchmark/hash_small2.yml deleted file mode 100644 index 0bf7ab6a1b..0000000000 --- a/benchmark/hash_small2.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - hash_small2: | - 1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a} -loop_count: 1 diff --git a/benchmark/hash_small4.yml b/benchmark/hash_small4.yml deleted file mode 100644 index 24bc334c63..0000000000 --- a/benchmark/hash_small4.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - hash_small4: | - 1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a} -loop_count: 1 diff --git a/benchmark/hash_small8.yml b/benchmark/hash_small8.yml deleted file mode 100644 index 30b50a789c..0000000000 --- a/benchmark/hash_small8.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - hash_small8: | - 1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a} -loop_count: 1 diff --git a/benchmark/hash_to_proc.yml b/benchmark/hash_to_proc.yml deleted file mode 100644 index 2ae8588b27..0000000000 --- a/benchmark/hash_to_proc.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - hash_to_proc: | - h = {} - - 10000.times do |i| - h[i] = nil - end - - 5000.times do |i| - [i].map(&h) - end -loop_count: 1 diff --git a/benchmark/hash_values.yml b/benchmark/hash_values.yml deleted file mode 100644 index b645bcf4f8..0000000000 --- a/benchmark/hash_values.yml +++ /dev/null @@ -1,12 +0,0 @@ -benchmark: - hash_values: | - h = {} - - 10000.times do |i| - h[i] = nil - end - - 5000.times do - h.values - end -loop_count: 1 diff --git a/benchmark/int_quo.yml b/benchmark/int_quo.yml deleted file mode 100644 index 1527de3dfc..0000000000 --- a/benchmark/int_quo.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - int_quo: | - 5000000.times { 42.quo(3) } -loop_count: 1 diff --git a/benchmark/io_copy_stream_write.yml b/benchmark/io_copy_stream_write.yml deleted file mode 100644 index 32fa920951..0000000000 --- a/benchmark/io_copy_stream_write.yml +++ /dev/null @@ -1,28 +0,0 @@ -prelude: | - # The goal of this is to use a synthetic (non-IO) reader - # to trigger the read/write loop of IO.copy_stream, - # bypassing in-kernel mechanisms like sendfile for zero copy, - # so we wrap the /dev/zero IO object: -benchmark: - io_copy_stream_write: | - - class Zero - def initialize - @n = 100000 - @in = File.open('/dev/zero', 'rb') - end - - def read(len, buf) - return if (@n -= 1) == 0 - @in.read(len, buf) - end - end - - begin - src = Zero.new - dst = File.open(IO::NULL, 'wb') - n = IO.copy_stream(src, dst) - rescue Errno::ENOENT - # not *nix - end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL) -loop_count: 1 diff --git a/benchmark/io_copy_stream_write_socket.yml b/benchmark/io_copy_stream_write_socket.yml deleted file mode 100644 index 2207eca8c6..0000000000 --- a/benchmark/io_copy_stream_write_socket.yml +++ /dev/null @@ -1,39 +0,0 @@ -prelude: | - # The goal of this is to use a synthetic (non-IO) reader - # to trigger the read/write loop of IO.copy_stream, - # bypassing in-kernel mechanisms like sendfile for zero copy, - # so we wrap the /dev/zero IO object: -benchmark: - io_copy_stream_write_socket: | - class Zero - def initialize - @n = 100000 - @in = File.open('/dev/zero', 'rb') - end - - def read(len, buf) - return if (@n -= 1) == 0 - @in.read(len, buf) - end - end - - begin - require 'socket' - src = Zero.new - rd, wr = UNIXSocket.pair - pid = fork do - wr.close - buf = String.new - while rd.read(16384, buf) - end - end - rd.close - IO.copy_stream(src, wr) - rescue Errno::ENOENT, NotImplementedError, NameError - # not *nix: missing /dev/zero, fork, or UNIXSocket - rescue LoadError # no socket? - ensure - wr.close if wr - Process.waitpid(pid) if pid - end if IO.respond_to?(:copy_stream) -loop_count: 1 diff --git a/benchmark/io_file_create.yml b/benchmark/io_file_create.yml deleted file mode 100644 index ece11cc332..0000000000 --- a/benchmark/io_file_create.yml +++ /dev/null @@ -1,15 +0,0 @@ -benchmark: - io_file_create: | - # - # Create files - # - - max = 200_000 - file = './tmpfile_of_bm_io_file_create' - - max.times{ - f = open(file, 'w') - f.close#(true) - } - File.unlink(file) -loop_count: 1 diff --git a/benchmark/io_file_read.yml b/benchmark/io_file_read.yml deleted file mode 100644 index f8f0c1c871..0000000000 --- a/benchmark/io_file_read.yml +++ /dev/null @@ -1,18 +0,0 @@ -benchmark: - io_file_read: | - # - # Seek and Read file. - # - - require 'tempfile' - - max = 200_000 - str = "Hello world! " * 1000 - f = Tempfile.new('yarv-benchmark') - f.write str - - max.times{ - f.seek 0 - f.read - } -loop_count: 1 diff --git a/benchmark/io_file_write.yml b/benchmark/io_file_write.yml deleted file mode 100644 index 68af6d588c..0000000000 --- a/benchmark/io_file_write.yml +++ /dev/null @@ -1,17 +0,0 @@ -benchmark: - io_file_write: | - # - # Seek and Write file. - # - - require 'tempfile' - - max = 200_000 - str = "Hello world! " * 1000 - f = Tempfile.new('yarv-benchmark') - - max.times{ - f.seek 0 - f.write str - } -loop_count: 1 diff --git a/benchmark/io_nonblock_noex.yml b/benchmark/io_nonblock_noex.yml deleted file mode 100644 index 6e29240bd7..0000000000 --- a/benchmark/io_nonblock_noex.yml +++ /dev/null @@ -1,25 +0,0 @@ -benchmark: - io_nonblock_noex: | - nr = 1_000_000 - i = 0 - msg = '.' - buf = '.' - noex = { exception: false } - begin - r, w = IO.pipe - while i < nr - i += 1 - w.write_nonblock(msg, noex) - r.read_nonblock(1, buf, noex) - end - rescue ArgumentError # old Rubies - while i < nr - i += 1 - w.write_nonblock(msg) - r.read_nonblock(1, buf) - end - ensure - r.close - w.close - end -loop_count: 1 diff --git a/benchmark/io_nonblock_noex2.yml b/benchmark/io_nonblock_noex2.yml deleted file mode 100644 index eda8687028..0000000000 --- a/benchmark/io_nonblock_noex2.yml +++ /dev/null @@ -1,24 +0,0 @@ -benchmark: - io_nonblock_noex2: | - nr = 1_000_000 - i = 0 - msg = '.' - buf = '.' - begin - r, w = IO.pipe - while i < nr - i += 1 - w.write_nonblock(msg, exception: false) - r.read_nonblock(1, buf, exception: false) - end - rescue ArgumentError # old Rubies - while i < nr - i += 1 - w.write_nonblock(msg) - r.read_nonblock(1, buf) - end - ensure - r.close - w.close - end -loop_count: 1 diff --git a/benchmark/io_pipe_rw.yml b/benchmark/io_pipe_rw.yml deleted file mode 100644 index cd9e6c3826..0000000000 --- a/benchmark/io_pipe_rw.yml +++ /dev/null @@ -1,17 +0,0 @@ -prelude: | - # Measure uncontended GVL performance via read/write with 1:1 threading - # If we switch to M:N threading, this will benchmark something else... -benchmark: - io_pipe_rw: | - r, w = IO.pipe - src = '0'.freeze - dst = String.new - i = 0 - while i < 1_000_000 - i += 1 - w.write(src) - r.read(1, dst) - end - w.close - r.close -loop_count: 1 diff --git a/benchmark/io_select.yml b/benchmark/io_select.yml deleted file mode 100644 index bcea6b9a70..0000000000 --- a/benchmark/io_select.yml +++ /dev/null @@ -1,12 +0,0 @@ -prelude: | - # IO.select performance -benchmark: - io_select: | - - w = [ IO.pipe[1] ]; - - nr = 1000000 - nr.times { - IO.select nil, w - } -loop_count: 1 diff --git a/benchmark/io_select2.yml b/benchmark/io_select2.yml deleted file mode 100644 index 3c8078dc11..0000000000 --- a/benchmark/io_select2.yml +++ /dev/null @@ -1,25 +0,0 @@ -prelude: | - # IO.select performance. worst case of single fd. -benchmark: - io_select2: | - - ios = [] - nr = 1000000 - if defined?(Process::RLIMIT_NOFILE) - max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] - else - max = 64 - end - puts "max fd: #{max} (results not apparent with <= 1024 max fd)" - - ((max / 2) - 10).times do - ios.concat IO.pipe - end - - last = [ ios[-1] ] - puts "last IO: #{last[0].inspect}" - - nr.times do - IO.select nil, last - end -loop_count: 1 diff --git a/benchmark/io_select3.yml b/benchmark/io_select3.yml deleted file mode 100644 index c97d0e0cd1..0000000000 --- a/benchmark/io_select3.yml +++ /dev/null @@ -1,24 +0,0 @@ -prelude: | - # IO.select performance. a lot of fd -benchmark: - io_select3: | - - ios = [] - nr = 100 - if defined?(Process::RLIMIT_NOFILE) - max = Process.getrlimit(Process::RLIMIT_NOFILE)[0] - else - max = 64 - end - puts "max fd: #{max} (results not apparent with <= 1024 max fd)" - - (max - 10).times do - r, w = IO.pipe - r.close - ios.push w - end - - nr.times do - IO.select nil, ios - end -loop_count: 1 diff --git a/benchmark/loop_for.yml b/benchmark/loop_for.yml deleted file mode 100644 index 99279f014a..0000000000 --- a/benchmark/loop_for.yml +++ /dev/null @@ -1,6 +0,0 @@ -benchmark: - loop_for: | - for i in 1..30_000_000 - # - end -loop_count: 1 diff --git a/benchmark/loop_generator.yml b/benchmark/loop_generator.yml deleted file mode 100644 index a5a39c085a..0000000000 --- a/benchmark/loop_generator.yml +++ /dev/null @@ -1,17 +0,0 @@ -benchmark: - loop_generator: | - max = 600000 - - if defined? Fiber - gen = (1..max).each - loop do - gen.next - end - else - require 'generator' - gen = Generator.new((0..max)) - while gen.next? - gen.next - end - end -loop_count: 1 diff --git a/benchmark/loop_times.yml b/benchmark/loop_times.yml deleted file mode 100644 index 8d50d6edda..0000000000 --- a/benchmark/loop_times.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - loop_times: | - 30_000_000.times{|e|} -loop_count: 1 diff --git a/benchmark/loop_whileloop.yml b/benchmark/loop_whileloop.yml deleted file mode 100644 index 0fa797aed4..0000000000 --- a/benchmark/loop_whileloop.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - loop_whileloop: | - i = 0 - while i<30_000_000 # benchmark loop 1 - i += 1 - end -loop_count: 1 diff --git a/benchmark/loop_whileloop2.yml b/benchmark/loop_whileloop2.yml deleted file mode 100644 index 2cf83908b3..0000000000 --- a/benchmark/loop_whileloop2.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - loop_whileloop2: | - i = 0 - while i< 6_000_000 # benchmark loop 2 - i += 1 - end -loop_count: 1 diff --git a/benchmark/marshal_dump_flo.yml b/benchmark/marshal_dump_flo.yml deleted file mode 100644 index 0e3cc1394a..0000000000 --- a/benchmark/marshal_dump_flo.yml +++ /dev/null @@ -1,5 +0,0 @@ -benchmark: - marshal_dump_flo: | - bug10761 = 10000.times.map { |x| x.to_f } - 100.times { Marshal.dump(bug10761) } -loop_count: 1 diff --git a/benchmark/marshal_dump_load_geniv.yml b/benchmark/marshal_dump_load_geniv.yml deleted file mode 100644 index 6395c1d1cd..0000000000 --- a/benchmark/marshal_dump_load_geniv.yml +++ /dev/null @@ -1,13 +0,0 @@ -benchmark: - marshal_dump_load_geniv: | - a = '' - a.instance_eval do - @a = :a - @b = :b - @c = :c - end - 100000.times do - a = Marshal.load(Marshal.dump(a)) - end - #p(a.instance_eval { @a == :a && @b == :b && @c == :c }) -loop_count: 1 diff --git a/benchmark/marshal_dump_load_time.yml b/benchmark/marshal_dump_load_time.yml deleted file mode 100644 index 0c25c2d677..0000000000 --- a/benchmark/marshal_dump_load_time.yml +++ /dev/null @@ -1,4 +0,0 @@ -benchmark: - marshal_dump_load_time: | - 100000.times { Marshal.load(Marshal.dump(Time.now)) } -loop_count: 1 diff --git a/benchmark/securerandom.yml b/benchmark/securerandom.yml deleted file mode 100644 index 187ca2e294..0000000000 --- a/benchmark/securerandom.yml +++ /dev/null @@ -1,8 +0,0 @@ -benchmark: - securerandom: | - require "securerandom" - - 20_0000.times do - SecureRandom.random_number(100) - end -loop_count: 1 diff --git a/benchmark/so_ackermann.yml b/benchmark/so_ackermann.yml deleted file mode 100644 index 4082169f5e..0000000000 --- a/benchmark/so_ackermann.yml +++ /dev/null @@ -1,21 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ -benchmark: - so_ackermann: | - - def ack(m, n) - if m == 0 then - n + 1 - elsif n == 0 then - ack(m - 1, 1) - else - ack(m - 1, ack(m, n - 1)) - end - end - - NUM = 9 - ack(3, NUM) -loop_count: 1 diff --git a/benchmark/so_array.yml b/benchmark/so_array.yml deleted file mode 100644 index e68643879e..0000000000 --- a/benchmark/so_array.yml +++ /dev/null @@ -1,25 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ - # with help from Paul Brannan and Mark Hubbart -benchmark: - so_array: | - - n = 9000 # Integer(ARGV.shift || 1) - - x = Array.new(n) - y = Array.new(n, 0) - - n.times{|bi| - x[bi] = bi + 1 - } - - (0 .. 999).each do |e| - (n-1).step(0,-1) do |bi| - y[bi] += x.at(bi) - end - end - # puts "#{y.first} #{y.last}" -loop_count: 1 diff --git a/benchmark/so_binary_trees.yml b/benchmark/so_binary_trees.yml deleted file mode 100644 index 9e943d50ff..0000000000 --- a/benchmark/so_binary_trees.yml +++ /dev/null @@ -1,66 +0,0 @@ -prelude: | - # The Computer Language Shootout Benchmarks - # http://shootout.alioth.debian.org -benchmark: - so_binary_trees: | - # - # contributed by Jesse Millikan - - # disable output - alias puts_orig puts - def puts str - # disable puts - end - - def item_check(tree) - if tree[0] == nil - tree[1] - else - tree[1] + item_check(tree[0]) - item_check(tree[2]) - end - end - - def bottom_up_tree(item, depth) - if depth > 0 - item_item = 2 * item - depth -= 1 - [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)] - else - [nil, item, nil] - end - end - - max_depth = 16 # ARGV[0].to_i - min_depth = 4 - - max_depth = min_depth + 2 if min_depth + 2 > max_depth - - stretch_depth = max_depth + 1 - stretch_tree = bottom_up_tree(0, stretch_depth) - - puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}" - stretch_tree = nil - - long_lived_tree = bottom_up_tree(0, max_depth) - - min_depth.step(max_depth + 1, 2) do |depth| - iterations = 2**(max_depth - depth + min_depth) - - check = 0 - - for i in 1..iterations - temp_tree = bottom_up_tree(i, depth) - check += item_check(temp_tree) - - temp_tree = bottom_up_tree(-i, depth) - check += item_check(temp_tree) - end - - puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}" - end - - puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}" - - undef puts - alias puts puts_orig -loop_count: 1 diff --git a/benchmark/so_concatenate.yml b/benchmark/so_concatenate.yml deleted file mode 100644 index 13d6559745..0000000000 --- a/benchmark/so_concatenate.yml +++ /dev/null @@ -1,20 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ - # based on code from Aristarkh A Zagorodnikov and Dat Nguyen -benchmark: - so_concatenate: | - - STUFF = "hello\n" - i = 0 - while i<10 - i += 1 - hello = '' - 4_000_000.times do |e| - hello << STUFF - end - end - # puts hello.length -loop_count: 1 diff --git a/benchmark/so_exception.yml b/benchmark/so_exception.yml deleted file mode 100644 index 0bfe3718eb..0000000000 --- a/benchmark/so_exception.yml +++ /dev/null @@ -1,65 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ -benchmark: - so_exception: | - - $HI = 0 - $LO = 0 - NUM = 250000 # Integer(ARGV[0] || 1) - - - class Lo_Exception < Exception - def initialize(num) - @value = num - end - end - - class Hi_Exception < Exception - def initialize(num) - @value = num - end - end - - def some_function(num) - begin - hi_function(num) - rescue - print "We shouldn't get here, exception is: #{$!.type}\n" - end - end - - def hi_function(num) - begin - lo_function(num) - rescue Hi_Exception - $HI = $HI + 1 - end - end - - def lo_function(num) - begin - blowup(num) - rescue Lo_Exception - $LO = $LO + 1 - end - end - - def blowup(num) - if num % 2 == 0 - raise Lo_Exception.new(num) - else - raise Hi_Exception.new(num) - end - end - - - i = 1 - max = NUM+1 - while i < max - i += 1 - some_function(i+1) - end -loop_count: 1 diff --git a/benchmark/so_fannkuch.yml b/benchmark/so_fannkuch.yml deleted file mode 100644 index 3d7a2b43bd..0000000000 --- a/benchmark/so_fannkuch.yml +++ /dev/null @@ -1,48 +0,0 @@ -prelude: | - # The Computer Language Shootout - # http://shootout.alioth.debian.org/ - # Contributed by Sokolov Yura - # Modified by Ryan Williams -benchmark: - so_fannkuch: | - - def fannkuch(n) - maxFlips, m, r, check = 0, n-1, n, 0 - count = (1..n).to_a - perm = (1..n).to_a - - while true - if check < 30 - puts "#{perm}" - check += 1 - end - - while r != 1 - count[r-1] = r - r -= 1 - end - - if perm[0] != 1 and perm[m] != n - perml = perm.clone #.dup - flips = 0 - while (k = perml.first ) != 1 - perml = perml.slice!(0, k).reverse + perml - flips += 1 - end - maxFlips = flips if flips > maxFlips - end - while true - if r==n then return maxFlips end - perm.insert r,perm.shift - break if (count[r] -= 1) > 0 - r += 1 - end - end - end - - def puts *args - end - - N = 9 # (ARGV[0] || 1).to_i - puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" -loop_count: 1 diff --git a/benchmark/so_fasta.yml b/benchmark/so_fasta.yml deleted file mode 100644 index c7c6a92958..0000000000 --- a/benchmark/so_fasta.yml +++ /dev/null @@ -1,84 +0,0 @@ -prelude: | - # The Computer Language Shootout - # http://shootout.alioth.debian.org/ - # Contributed by Sokolov Yura -benchmark: - so_fasta: | - - $last = 42.0 - def gen_random(max, im=139968, ia=3877, ic=29573) - (max * ($last = ($last * ia + ic) % im)) / im - end - - alu = - "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+ - "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+ - "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+ - "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+ - "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+ - "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+ - "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" - - iub = [ - ["a", 0.27], - ["c", 0.12], - ["g", 0.12], - ["t", 0.27], - - ["B", 0.02], - ["D", 0.02], - ["H", 0.02], - ["K", 0.02], - ["M", 0.02], - ["N", 0.02], - ["R", 0.02], - ["S", 0.02], - ["V", 0.02], - ["W", 0.02], - ["Y", 0.02], - ] - homosapiens = [ - ["a", 0.3029549426680], - ["c", 0.1979883004921], - ["g", 0.1975473066391], - ["t", 0.3015094502008], - ] - - def make_repeat_fasta(id, desc, src, n) - puts ">#{id} #{desc}" - v = nil - width = 60 - l = src.length - s = src * ((n / l) + 1) - s.slice!(n, l) - puts(s.scan(/.{1,#{width}}/).join("\n")) - end - - def make_random_fasta(id, desc, table, n) - puts ">#{id} #{desc}" - rand, v = nil,nil - width = 60 - chunk = 1 * width - prob = 0.0 - table.each{|v| v[1]= (prob += v[1])} - for i in 1..(n/width) - puts((1..width).collect{ - rand = gen_random(1.0) - table.find{|v| v[1]>rand}[0] - }.join) - end - if n%width != 0 - puts((1..(n%width)).collect{ - rand = gen_random(1.0) - table.find{|v| v[1]>rand}[0] - }.join) - end - end - - - n = (ARGV[0] or 250_000).to_i - - make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2) - make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3) - make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5) -loop_count: 1 diff --git a/benchmark/so_lists.yml b/benchmark/so_lists.yml deleted file mode 100644 index 44a7495a2f..0000000000 --- a/benchmark/so_lists.yml +++ /dev/null @@ -1,51 +0,0 @@ -prelude: | - #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby -benchmark: - so_lists: | - - NUM = 300 - SIZE = 10000 - - def test_lists() - # create a list of integers (Li1) from 1 to SIZE - li1 = (1..SIZE).to_a - # copy the list to li2 (not by individual items) - li2 = li1.dup - # remove each individual item from left side of li2 and - # append to right side of li3 (preserving order) - li3 = Array.new - while (not li2.empty?) - li3.push(li2.shift) - end - # li2 must now be empty - # remove each individual item from right side of li3 and - # append to right side of li2 (reversing list) - while (not li3.empty?) - li2.push(li3.pop) - end - # li3 must now be empty - # reverse li1 in place - li1.reverse! - # check that first item is now SIZE - if li1[0] != SIZE then - p "not SIZE" - 0 - else - # compare li1 and li2 for equality - if li1 != li2 then - return(0) - else - # return the length of the list - li1.length - end - end - end - - i = 0 - while i LIMIT_SQUARED - escape = true - break - end - end - - byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) - bit_num += 1 - - # Code is very similar for these cases, but using separate blocks - # ensures we skip the shifting when it's unnecessary, which is most cases. - if (bit_num == 8) - print byte_acc.chr - byte_acc = 0 - bit_num = 0 - elsif (x == count_size) - byte_acc <<= (8 - bit_num) - print byte_acc.chr - byte_acc = 0 - bit_num = 0 - end - end - end -loop_count: 1 diff --git a/benchmark/so_matrix.yml b/benchmark/so_matrix.yml deleted file mode 100644 index 9a534471d9..0000000000 --- a/benchmark/so_matrix.yml +++ /dev/null @@ -1,50 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ -benchmark: - so_matrix: | - - n = 60 #Integer(ARGV.shift || 1) - - size = 40 - - def mkmatrix(rows, cols) - count = 1 - mx = Array.new(rows) - (0 .. (rows - 1)).each do |bi| - row = Array.new(cols, 0) - (0 .. (cols - 1)).each do |j| - row[j] = count - count += 1 - end - mx[bi] = row - end - mx - end - - def mmult(rows, cols, m1, m2) - m3 = Array.new(rows) - (0 .. (rows - 1)).each do |bi| - row = Array.new(cols, 0) - (0 .. (cols - 1)).each do |j| - val = 0 - (0 .. (cols - 1)).each do |k| - val += m1.at(bi).at(k) * m2.at(k).at(j) - end - row[j] = val - end - m3[bi] = row - end - m3 - end - - m1 = mkmatrix(size, size) - m2 = mkmatrix(size, size) - mm = Array.new - n.times do - mm = mmult(size, size, m1, m2) - end - # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}" -loop_count: 1 diff --git a/benchmark/so_meteor_contest.yml b/benchmark/so_meteor_contest.yml deleted file mode 100644 index c35df18f68..0000000000 --- a/benchmark/so_meteor_contest.yml +++ /dev/null @@ -1,567 +0,0 @@ -prelude: | - #!/usr/bin/env ruby -benchmark: - so_meteor_contest: | - # - # The Computer Language Shootout - # http://shootout.alioth.debian.org - # contributed by Kevin Barnes (Ruby novice) - - # PROGRAM: the main body is at the bottom. - # 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ - # 2) see how I represent a board as a bitmask by reading the blank_board comments - # 3) read as your mental paths take you - - def print *args - end - - # class to represent all information about a particular rotation of a particular piece - class Rotation - # an array (by location) containing a bit mask for how the piece maps at the given location. - # if the rotation is invalid at that location the mask will contain false - attr_reader :start_masks - - # maps a direction to a relative location. these differ depending on whether it is an even or - # odd row being mapped from - @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 } - @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 } - - def initialize( directions ) - @even_offsets, @odd_offsets = normalize_offsets( get_values( directions )) - - @even_mask = mask_for_offsets( @even_offsets) - @odd_mask = mask_for_offsets( @odd_offsets) - - @start_masks = Array.new(60) - - # create the rotational masks by placing the base mask at the location and seeing if - # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these - # is true the piece cannot be placed - 0.upto(59) do | offset | - mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset) - if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then - imask = compute_required( mask, offset) - @start_masks[offset] = [ mask, imask, imask | mask ] - else - @start_masks[offset] = false - end - end - end - - def compute_required( mask, offset ) - board = blank_board - 0.upto(offset) { | i | board |= 1 << i } - board |= mask - return 0 if (!prunable(board | mask, offset)) - board = flood_fill(board,58) - count = 0 - imask = 0 - 0.upto(59) do | i | - if (board[i] == 0) then - imask |= (1 << i) - count += 1 - end - end - (count > 0 && count < 5) ? imask : 0 - end - - def flood_fill( board, location) - return board if (board[location] == 1) - board |= 1 << location - row, col = location.divmod(6) - board = flood_fill( board, location - 1) if (col > 0) - board = flood_fill( board, location + 1) if (col < 4) - if (row % 2 == 0) then - board = flood_fill( board, location - 7) if (col > 0 && row > 0) - board = flood_fill( board, location - 6) if (row > 0) - board = flood_fill( board, location + 6) if (row < 9) - board = flood_fill( board, location + 5) if (col > 0 && row < 9) - else - board = flood_fill( board, location - 5) if (col < 4 && row > 0) - board = flood_fill( board, location - 6) if (row > 0) - board = flood_fill( board, location + 6) if (row < 9) - board = flood_fill( board, location + 7) if (col < 4 && row < 9) - end - board - end - - # given a location, produces a list of relative locations covered by the piece at this rotation - def offsets( location) - if is_even( location) then - @even_offsets.collect { | value | value + location } - else - @odd_offsets.collect { | value | value + location } - end - end - - # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows) - # this is hard to explain. imagine we have this partial board: - # 0 0 0 0 0 x [positions 0-5] - # 0 0 1 1 0 x [positions 6-11] - # 0 0 1 0 0 x [positions 12-17] - # 0 1 0 0 0 x [positions 18-23] - # 0 1 0 0 0 x [positions 24-29] - # 0 0 0 0 0 x [positions 30-35] - # ... - # The top-left of the piece is at position 8, the - # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that - # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained - # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row: - # 0 0 0 1 1 x [positions 0-5] - # 0 0 1 0 0 x [positions 6-11] - # 0 0 1 0 0 x [positions 12-17] - # 0 1 0 0 0 x [positions 18-23] - # 0 0 0 0 0 x [positions 24-29] - # 0 0 0 0 0 x [positions 30-35] - # ... - # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the - # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what - # this function would return - def normalize_offsets( values) - min = values.min - even_min = is_even(min) - other_min = even_min ? min + 6 : min + 7 - other_values = values.collect do | value | - if is_even(value) then - value + 6 - other_min - else - value + 7 - other_min - end - end - values.collect! { | value | value - min } - - if even_min then - [values, other_values] - else - [other_values, values] - end - end - - # produce a bitmask representation of an array of offset locations - def mask_for_offsets( offsets ) - mask = 0 - offsets.each { | value | mask = mask + ( 1 << value ) } - mask - end - - # finds a "safe" position that a position as described by a list of directions can be placed - # without falling off any edge of the board. the values returned a location to place the first piece - # at so it will fit after making the described moves - def start_adjust( directions ) - south = east = 0; - directions.each do | direction | - east += 1 if ( direction == :sw || direction == :nw || direction == :west ) - south += 1 if ( direction == :nw || direction == :ne ) - end - south * 6 + east - end - - # given a set of directions places the piece (as defined by a set of directions) on the board at - # a location that will not take it off the edge - def get_values( directions ) - start = start_adjust(directions) - values = [ start ] - directions.each do | direction | - if (start % 12 >= 6) then - start += @@rotation_odd_adder[direction] - else - start += @@rotation_even_adder[direction] - end - values += [ start ] - end - - # some moves take you back to an existing location, we'll strip duplicates - values.uniq - end - end - - # describes a piece and caches information about its rotations to as to be efficient for iteration - # ATTRIBUTES: - # rotations -- all the rotations of the piece - # type -- a numeic "name" of the piece - # masks -- an array by location of all legal rotational masks (a n inner array) for that location - # placed -- the mask that this piece was last placed at (not a location, but the actual mask used) - class Piece - attr_reader :rotations, :type, :masks - attr_accessor :placed - - # transform hashes that change one direction into another when you either flip or rotate a set of directions - @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne } - @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw } - - def initialize( directions, type ) - @type = type - @rotations = Array.new(); - @map = {} - - generate_rotations( directions ) - directions.collect! { | value | @@flip_converter[value] } - generate_rotations( directions ) - - # creates the masks AND a map that returns [location, rotation] for any given mask - # this is used when a board is found and we want to draw it, otherwise the map is unused - @masks = Array.new(); - 0.upto(59) do | i | - even = true - @masks[i] = @rotations.collect do | rotation | - mask = rotation.start_masks[i] - @map[mask[0]] = [ i, rotation ] if (mask) - mask || nil - end - @masks[i].compact! - end - end - - # rotates a set of directions through all six angles and adds a Rotation to the list for each one - def generate_rotations( directions ) - 6.times do - rotations.push( Rotation.new(directions)) - directions.collect! { | value | @@rotate_converter[value] } - end - end - - # given a board string, adds this piece to the board at whatever location/rotation - # important: the outbound board string is 5 wide, the normal location notation is six wide (padded) - def fill_string( board_string) - location, rotation = @map[@placed] - rotation.offsets(location).each do | offset | - row, col = offset.divmod(6) - board_string[ row*5 + col, 1 ] = @type.to_s - end - end - end - - # a blank bit board having this form: - # - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 0 0 0 0 0 1 - # 1 1 1 1 1 1 - # - # where left lest significant bit is the top left and the most significant is the lower right - # the actual board only consists of the 0 places, the 1 places are blockers to keep things from running - # off the edges or bottom - def blank_board - 0b111111100000100000100000100000100000100000100000100000100000100000 - end - - def full_board - 0b111111111111111111111111111111111111111111111111111111111111111111 - end - - # determines if a location (bit position) is in an even row - def is_even( location) - (location % 12) < 6 - end - - # support function that create three utility maps: - # $converter -- for each row an array that maps a five bit row (via array mapping) - # to the a five bit representation of the bits below it - # $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row - # @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays - # a region array has three values the first is a mask of bits in the region, - # the second is the count of those bits and the third is identical to the first - # examples: - # 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001] - # 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001] - # 0b10001 => [ 0b01110, 3, 0b01110 ] - def create_collector_support - odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000] - even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000] - - all_odds = Array.new(0b100000) - all_evens = Array.new(0b100000) - bit_counts = Array.new(0b100000) - new_regions = Array.new(0b100000) - 0.upto(0b11111) do | i | - bit_count = odd = even = 0 - 0.upto(4) do | bit | - if (i[bit] == 1) then - bit_count += 1 - odd |= odd_map[bit] - even |= even_map[bit] - end - end - all_odds[i] = odd - all_evens[i] = even - bit_counts[i] = bit_count - new_regions[i] = create_regions( i) - end - - $converter = [] - 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) } - $bit_counts = bit_counts - $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } } - end - - # determines if a board is punable, meaning that there is no possibility that it - # can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces - # that are not a multiple of five. The following board is an example of a prunable board: - # 0 0 1 0 0 - # 0 1 0 0 0 - # 1 1 0 0 0 - # 0 1 0 0 0 - # 0 0 0 0 0 - # ... - # - # This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it - # parameters: - # board -- an initial bit board (6 bit padded rows, see blank_board for format) - # location -- starting location, everything above and to the left is already full - # slotting -- set to true only when testing initial pieces, when filling normally - # additional assumptions are possible - # - # Algorithm: - # The algorithm starts at the top row (as determined by location) and iterates a row at a time - # maintainng counts of active open areas (kept in the collector array) each collector contains - # three values at the start of an iteration: - # 0: mask of bits that would be adjacent to the collector in this row - # 1: the number of bits collected so far - # 2: a scratch space starting as zero, but used during the computation to represent - # the empty bits in the new row that are adjacent (position 0) - # The exact procedure is described in-code - def prunable( board, location, slotting = false) - collectors = [] - # loop across the rows - (location / 6).to_i.upto(9) do | row_on | - # obtain a set of regions representing the bits of the current row. - regions = $regions[(board >> (row_on * 6)) & 0b11111] - converter = $converter[row_on] - - # track the number of collectors at the start of the cycle so that - # we don't compute against newly created collectors, only existing collectors - initial_collector_count = collectors.length - - # loop against the regions. For each region of the row - # we will see if it connects to one or more existing collectors. - # if it connects to 1 collector, the bits from the region are added to the - # bits of the collector and the mask is placed in collector[2] - # If the region overlaps more than one collector then all the collectors - # it overlaps with are merged into the first one (the others are set to nil in the array) - # if NO collectors are found then the region is copied as a new collector - regions.each do | region | - collector_found = nil - region_mask = region[2] - initial_collector_count.times do | collector_num | - collector = collectors[collector_num] - if (collector) then - collector_mask = collector[0] - if (collector_mask & region_mask != 0) then - if (collector_found) then - collector_found[0] |= collector_mask - collector_found[1] += collector[1] - collector_found[2] |= collector[2] - collectors[collector_num] = nil - else - collector_found = collector - collector[1] += region[1] - collector[2] |= region_mask - end - end - end - end - if (collector_found == nil) then - collectors.push(Array.new(region)) - end - end - - # check the existing collectors, if any collector overlapped no bits in the region its [2] value will - # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since - # the board is prunable. if it is a multiple of five it is removed. - # Collector that are still active have a new adjacent value [0] set based n the matched bits - # and have [2] cleared out for the next cycle. - collectors.length.times do | collector_num | - collector = collectors[collector_num] - if (collector) then - if (collector[2] == 0) then - return true if (collector[1] % 5 != 0) - collectors[collector_num] = nil - else - # if a collector matches all bits in the row then we can return unprunable early for the - # following reasons: - # 1) there can be no more unavailable bits bince we fill from the top left downward - # 2) all previous regions have been closed or joined so only this region can fail - # 3) this region must be good since there can never be only 1 region that is nuot - # a multiple of five - # this rule only applies when filling normally, so we ignore the rule if we are "slotting" - # in pieces to see what configurations work for them (the only other time this algorithm is used). - return false if (collector[2] == 0b11111 && !slotting) - collector[0] = converter[collector[2]] - collector[2] = 0 - end - end - end - - # get rid of all the empty converters for the next round - collectors.compact! - end - return false if (collectors.length <= 1) # 1 collector or less and the region is fine - collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size - end - - # creates a region given a row mask. see prunable for what a "region" is - def create_regions( value ) - regions = [] - cur_region = 0 - 5.times do | bit | - if (value[bit] == 0) then - cur_region |= 1 << bit - else - if (cur_region != 0 ) then - regions.push( cur_region) - cur_region = 0; - end - end - end - regions.push(cur_region) if (cur_region != 0) - regions - end - - # find up to the counted number of solutions (or all solutions) and prints the final result - def find_all - find_top( 1) - find_top( 0) - print_results - end - - # show the board - def print_results - print "#{@boards_found} solutions found\n\n" - print_full_board( @min_board) - print "\n" - print_full_board( @max_board) - print "\n" - end - - # finds solutions. This special version of the main function is only used for the top level - # the reason for it is basically to force a particular ordering on how the rotations are tested for - # the first piece. It is called twice, first looking for placements of the odd rotations and then - # looking for placements of the even locations. - # - # WHY? - # Since any found solution has an inverse we want to maximize finding solutions that are not already found - # as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away - # (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier - # in the cycle. We still need to keep checking all the permutations, but our probability of finding one will - # diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces - # this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the - # maximum number - def find_top( rotation_skip) - board = blank_board - (@pieces.length-1).times do - piece = @pieces.shift - piece.masks[0].each do | mask, imask, cmask | - if ((rotation_skip += 1) % 2 == 0) then - piece.placed = mask - find( 1, 1, board | mask) - end - end - @pieces.push(piece) - end - piece = @pieces.shift - @pieces.push(piece) - end - - # the normail find routine, iterates through the available pieces, checks all rotations at the current location - # and adds any boards found. depth is achieved via recursion. the overall approach is described - # here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/ - # parameters: - # start_location -- where to start looking for place for the next piece at - # placed -- number of pieces placed - # board -- current state of the board - # - # see in-code comments - def find( start_location, placed, board) - # find the next location to place a piece by looking for an empty bit - while board[start_location] == 1 - start_location += 1 - end - - @pieces.length.times do - piece = @pieces.shift - piece.masks[start_location].each do | mask, imask, cmask | - if ( board & cmask == imask) then - piece.placed = mask - if (placed == 9) then - add_board - else - find( start_location + 1, placed + 1, board | mask) - end - end - end - @pieces.push(piece) - end - end - - # print the board - def print_full_board( board_string) - 10.times do | row | - print " " if (row % 2 == 1) - 5.times do | col | - print "#{board_string[row*5 + col,1]} " - end - print "\n" - end - end - - # when a board is found we "draw it" into a string and then flip that string, adding both to - # the list (hash) of solutions if they are unique. - def add_board - board_string = "99999999999999999999999999999999999999999999999999" - @all_pieces.each { | piece | piece.fill_string( board_string ) } - save( board_string) - save( board_string.reverse) - end - - # adds a board string to the list (if new) and updates the current best/worst board - def save( board_string) - if (@all_boards[board_string] == nil) then - @min_board = board_string if (board_string < @min_board) - @max_board = board_string if (board_string > @max_board) - @all_boards.store(board_string,true) - @boards_found += 1 - - # the exit motif is a time saver. Ideally the function should return, but those tests - # take noticeable time (performance). - if (@boards_found == @stop_count) then - print_results - exit(0) - end - end - end - - - ## - ## MAIN BODY :) - ## - create_collector_support - @pieces = [ - Piece.new( [ :nw, :ne, :east, :east ], 2), - Piece.new( [ :ne, :se, :east, :ne ], 7), - Piece.new( [ :ne, :east, :ne, :nw ], 1), - Piece.new( [ :east, :sw, :sw, :se ], 6), - Piece.new( [ :east, :ne, :se, :ne ], 5), - Piece.new( [ :east, :east, :east, :se ], 0), - Piece.new( [ :ne, :nw, :se, :east, :se ], 4), - Piece.new( [ :se, :se, :se, :west ], 9), - Piece.new( [ :se, :se, :east, :se ], 8), - Piece.new( [ :east, :east, :sw, :se ], 3) - ]; - - @all_pieces = Array.new( @pieces) - - @min_board = "99999999999999999999999999999999999999999999999999" - @max_board = "00000000000000000000000000000000000000000000000000" - @stop_count = ARGV[0].to_i || 2089 - @all_boards = {} - @boards_found = 0 - - find_all ######## DO IT!!! -loop_count: 1 diff --git a/benchmark/so_nbody.yml b/benchmark/so_nbody.yml deleted file mode 100644 index e4d111cd38..0000000000 --- a/benchmark/so_nbody.yml +++ /dev/null @@ -1,152 +0,0 @@ -prelude: | - # The Computer Language Shootout - # http://shootout.alioth.debian.org -benchmark: - so_nbody: | - # - # Optimized for Ruby by Jesse Millikan - # From version ported by Michael Neumann from the C gcc version, - # which was written by Christoph Bauer. - - SOLAR_MASS = 4 * Math::PI**2 - DAYS_PER_YEAR = 365.24 - - def _puts *args - end - - class Planet - attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass - - def initialize(x, y, z, vx, vy, vz, mass) - @x, @y, @z = x, y, z - @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR - @mass = mass * SOLAR_MASS - end - - def move_from_i(bodies, nbodies, dt, i) - while i < nbodies - b2 = bodies[i] - dx = @x - b2.x - dy = @y - b2.y - dz = @z - b2.z - - distance = Math.sqrt(dx * dx + dy * dy + dz * dz) - mag = dt / (distance * distance * distance) - b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag - - @vx -= dx * b2_mass_mag - @vy -= dy * b2_mass_mag - @vz -= dz * b2_mass_mag - b2.vx += dx * b_mass_mag - b2.vy += dy * b_mass_mag - b2.vz += dz * b_mass_mag - i += 1 - end - - @x += dt * @vx - @y += dt * @vy - @z += dt * @vz - end - end - - def energy(bodies) - e = 0.0 - nbodies = bodies.size - - for i in 0 ... nbodies - b = bodies[i] - e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz) - for j in (i + 1) ... nbodies - b2 = bodies[j] - dx = b.x - b2.x - dy = b.y - b2.y - dz = b.z - b2.z - distance = Math.sqrt(dx * dx + dy * dy + dz * dz) - e -= (b.mass * b2.mass) / distance - end - end - e - end - - def offset_momentum(bodies) - px, py, pz = 0.0, 0.0, 0.0 - - for b in bodies - m = b.mass - px += b.vx * m - py += b.vy * m - pz += b.vz * m - end - - b = bodies[0] - b.vx = - px / SOLAR_MASS - b.vy = - py / SOLAR_MASS - b.vz = - pz / SOLAR_MASS - end - - BODIES = [ - # sun - Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0), - - # jupiter - Planet.new( - 4.84143144246472090e+00, - -1.16032004402742839e+00, - -1.03622044471123109e-01, - 1.66007664274403694e-03, - 7.69901118419740425e-03, - -6.90460016972063023e-05, - 9.54791938424326609e-04), - - # saturn - Planet.new( - 8.34336671824457987e+00, - 4.12479856412430479e+00, - -4.03523417114321381e-01, - -2.76742510726862411e-03, - 4.99852801234917238e-03, - 2.30417297573763929e-05, - 2.85885980666130812e-04), - - # uranus - Planet.new( - 1.28943695621391310e+01, - -1.51111514016986312e+01, - -2.23307578892655734e-01, - 2.96460137564761618e-03, - 2.37847173959480950e-03, - -2.96589568540237556e-05, - 4.36624404335156298e-05), - - # neptune - Planet.new( - 1.53796971148509165e+01, - -2.59193146099879641e+01, - 1.79258772950371181e-01, - 2.68067772490389322e-03, - 1.62824170038242295e-03, - -9.51592254519715870e-05, - 5.15138902046611451e-05) - ] - - init = 200_000 # ARGV[0] - n = Integer(init) - - offset_momentum(BODIES) - - puts "%.9f" % energy(BODIES) - - nbodies = BODIES.size - dt = 0.01 - - n.times do - i = 0 - while i < nbodies - b = BODIES[i] - b.move_from_i(BODIES, nbodies, dt, i + 1) - i += 1 - end - end - - puts "%.9f" % energy(BODIES) -loop_count: 1 diff --git a/benchmark/so_nested_loop.yml b/benchmark/so_nested_loop.yml deleted file mode 100644 index 64a6901eac..0000000000 --- a/benchmark/so_nested_loop.yml +++ /dev/null @@ -1,26 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ - # from Avi Bryant -benchmark: - so_nested_loop: | - - n = 16 # Integer(ARGV.shift || 1) - x = 0 - n.times do - n.times do - n.times do - n.times do - n.times do - n.times do - x += 1 - end - end - end - end - end - end - # puts x -loop_count: 1 diff --git a/benchmark/so_nsieve.yml b/benchmark/so_nsieve.yml deleted file mode 100644 index 0799cff7a7..0000000000 --- a/benchmark/so_nsieve.yml +++ /dev/null @@ -1,39 +0,0 @@ -prelude: | - # The Computer Language Shootout - # http://shootout.alioth.debian.org/ -benchmark: - so_nsieve: | - # - # contributed by Glenn Parker, March 2005 - # modified by Evan Phoenix, Sept 2006 - - def sieve(m) - flags = Flags.dup[0,m] - count = 0 - pmax = m - 1 - p = 2 - while p <= pmax - unless flags[p].zero? - count += 1 - mult = p - while mult <= pmax - flags[mult] = 0 - mult += p - end - end - p += 1 - end - count - end - - n = 9 # (ARGV[0] || 2).to_i - Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*") - - n.downto(n-2) do |exponent| - break if exponent < 0 - m = (1 << exponent) * 10_000 - # m = (2 ** exponent) * 10_000 - count = sieve(m) - printf "Primes up to %8d %8d\n", m, count - end -loop_count: 1 diff --git a/benchmark/so_nsieve_bits.yml b/benchmark/so_nsieve_bits.yml deleted file mode 100644 index 08b47f53bb..0000000000 --- a/benchmark/so_nsieve_bits.yml +++ /dev/null @@ -1,46 +0,0 @@ -prelude: | - #!/usr/bin/ruby - #coding: us-ascii -benchmark: - so_nsieve_bits: | - # - # The Great Computer Language Shootout - # http://shootout.alioth.debian.org/ - # - # nsieve-bits in Ruby - # Contributed by Glenn Parker, March 2005 - - CharExponent = 3 - BitsPerChar = 1 << CharExponent - LowMask = BitsPerChar - 1 - - def sieve(m) - items = "\xFF" * ((m / BitsPerChar) + 1) - masks = "" - BitsPerChar.times do |b| - masks << (1 << b).chr - end - - count = 0 - pmax = m - 1 - 2.step(pmax, 1) do |p| - if items[p >> CharExponent][p & LowMask] == 1 - count += 1 - p.step(pmax, p) do |mult| - a = mult >> CharExponent - b = mult & LowMask - items[a] -= masks[b] if items[a][b] != 0 - end - end - end - count - end - - n = 9 # (ARGV[0] || 2).to_i - n.step(n - 2, -1) do |exponent| - break if exponent < 0 - m = 2 ** exponent * 10_000 - count = sieve(m) - printf "Primes up to %8d %8d\n", m, count - end -loop_count: 1 diff --git a/benchmark/so_object.yml b/benchmark/so_object.yml deleted file mode 100644 index 89fbce83cd..0000000000 --- a/benchmark/so_object.yml +++ /dev/null @@ -1,59 +0,0 @@ -prelude: | - #!/usr/bin/ruby - # -*- mode: ruby -*- - # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $ - # http://www.bagley.org/~doug/shootout/ - # with help from Aristarkh Zagorodnikov -benchmark: - so_object: | - - class Toggle - def initialize(start_state) - @bool = start_state - end - - def value - @bool - end - - def activate - @bool = !@bool - self - end - end - - class NthToggle < Toggle - def initialize(start_state, max_counter) - super start_state - @count_max = max_counter - @counter = 0 - end - - def activate - @counter += 1 - if @counter >= @count_max - @bool = !@bool - @counter = 0 - end - self - end - end - - n = 1500000 # (ARGV.shift || 1).to_i - - toggle = Toggle.new 1 - 5.times do - toggle.activate.value ? 'true' : 'false' - end - n.times do - toggle = Toggle.new 1 - end - - ntoggle = NthToggle.new 1, 3 - 8.times do - ntoggle.activate.value ? 'true' : 'false' - end - n.times do - ntoggle = NthToggle.new 1, 3 - end -loop_count: 1 diff --git a/benchmark/so_partial_sums.yml b/benchmark/so_partial_sums.yml deleted file mode 100644 index d45017bca8..0000000000 --- a/benchmark/so_partial_sums.yml +++ /dev/null @@ -1,34 +0,0 @@ -benchmark: - so_partial_sums: | - n = 2_500_000 # (ARGV.shift || 1).to_i - - alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0 - - 1.upto(n) do |d| - d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d) - - s0 += (2.0 / 3.0) ** (d - 1.0) - s1 += 1.0 / Math.sqrt(d) - s2 += 1.0 / (d * (d + 1.0)) - s3 += 1.0 / (d3 * ds * ds) - s4 += 1.0 / (d3 * dc * dc) - s5 += 1.0 / d - s6 += 1.0 / d2 - s7 += alt / d - s8 += alt / (2.0 * d - 1.0) - - alt = -alt - end - - if false - printf("%.9f\t(2/3)^k\n", s0) - printf("%.9f\tk^-0.5\n", s1) - printf("%.9f\t1/k(k+1)\n", s2) - printf("%.9f\tFlint Hills\n", s3) - printf("%.9f\tCookson Hills\n", s4) - printf("%.9f\tHarmonic\n", s5) - printf("%.9f\tRiemann Zeta\n", s6) - printf("%.9f\tAlternating Harmonic\n", s7) - printf("%.9f\tGregory\n", s8) - end -loop_count: 1 diff --git a/benchmark/so_pidigits.yml b/benchmark/so_pidigits.yml deleted file mode 100644 index 793745f5b5..0000000000 --- a/benchmark/so_pidigits.yml +++ /dev/null @@ -1,95 +0,0 @@ -prelude: | - # The Great Computer Language Shootout - # http://shootout.alioth.debian.org/ -benchmark: - so_pidigits: | - # - # contributed by Gabriele Renzi - - class PiDigitSpigot - - def initialize() - @z = Transformation.new 1,0,0,1 - @x = Transformation.new 0,0,0,0 - @inverse = Transformation.new 0,0,0,0 - end - - def next! - @y = @z.extract(3) - if safe? @y - @z = produce(@y) - @y - else - @z = consume @x.next!() - next!() - end - end - - def safe?(digit) - digit == @z.extract(4) - end - - def produce(i) - @inverse.qrst(10,-10*i,0,1).compose(@z) - end - - def consume(a) - @z.compose(a) - end - end - - - class Transformation - attr_reader :q, :r, :s, :t - def initialize(q, r, s, t) - @q,@r,@s,@t,@k = q,r,s,t,0 - end - - def next!() - @q = @k = @k + 1 - @r = 4 * @k + 2 - @s = 0 - @t = 2 * @k + 1 - self - end - - def extract(j) - (@q * j + @r) / (@s * j + @t) - end - - def compose(a) - self.class.new( @q * a.q, - @q * a.r + r * a.t, - @s * a.q + t * a.s, - @s * a.r + t * a.t - ) - end - - def qrst *args - initialize *args - self - end - - - end - - - WIDTH = 10 - n = 2_500 # Integer(ARGV[0]) - j = 0 - - digits = PiDigitSpigot.new - - while n > 0 - if n >= WIDTH - WIDTH.times {print digits.next!} - j += WIDTH - else - n.times {print digits.next!} - (WIDTH-n).times {print " "} - j += n - end - puts "\t:"+j.to_s - n -= WIDTH - end -loop_count: 1 diff --git a/benchmark/so_random.yml b/benchmark/so_random.yml deleted file mode 100644 index 3a39453377..0000000000 --- a/benchmark/so_random.yml +++ /dev/null @@ -1,24 +0,0 @@ -prelude: | - # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby -benchmark: - so_random: | - - IM = 139968.0 - IA = 3877.0 - IC = 29573.0 - - $last = 42.0 - - def gen_random(max) - (max * ($last = ($last * IA + IC) % IM)) / IM - end - - N = 3_000_000 - - i = 0 - while i"yyyy"} - end - GC.start - end -loop_count: 1 diff --git a/benchmark/vm3_gc_old_full.yml b/benchmark/vm3_gc_old_full.yml deleted file mode 100644 index 11958c2d0a..0000000000 --- a/benchmark/vm3_gc_old_full.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - vm3_gc_old_full: | - old_object = Array.new(1_000_000){''} - 100.times do - GC.start - end -loop_count: 1 diff --git a/benchmark/vm3_gc_old_immediate.yml b/benchmark/vm3_gc_old_immediate.yml deleted file mode 100644 index 3aea9c05f9..0000000000 --- a/benchmark/vm3_gc_old_immediate.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - vm3_gc_old_immediate: | - old_object = Array.new(1_000_000){''} - 30_000.times do - GC.start(full_mark: false, immediate_sweep: true) - end -loop_count: 1 diff --git a/benchmark/vm3_gc_old_lazy.yml b/benchmark/vm3_gc_old_lazy.yml deleted file mode 100644 index 37ad5c38f1..0000000000 --- a/benchmark/vm3_gc_old_lazy.yml +++ /dev/null @@ -1,7 +0,0 @@ -benchmark: - vm3_gc_old_lazy: | - old_object = Array.new(1_000_000){''} - 30_000.times do - GC.start(full_mark: false, immediate_sweep: false) - end -loop_count: 1 diff --git a/benchmark/vm_symbol_block_pass.yml b/benchmark/vm_symbol_block_pass.yml deleted file mode 100644 index c690b5944e..0000000000 --- a/benchmark/vm_symbol_block_pass.yml +++ /dev/null @@ -1,16 +0,0 @@ -benchmark: - vm_symbol_block_pass: | - class C - 1000.times {|i| - eval("def i#{i};end") - } - end - - c = C.new - m = C.instance_methods(false) - 5_000.times do - m.each do |n| - c.tap(&n) - end - end -loop_count: 1 diff --git a/benchmark/vm_thread_alive_check1.yml b/benchmark/vm_thread_alive_check1.yml deleted file mode 100644 index 4ab97401da..0000000000 --- a/benchmark/vm_thread_alive_check1.yml +++ /dev/null @@ -1,9 +0,0 @@ -benchmark: - vm_thread_alive_check1: | - 5_000.times{ - t = Thread.new{} - while t.alive? - Thread.pass - end - } -loop_count: 1 diff --git a/benchmark/vm_thread_close.yml b/benchmark/vm_thread_close.yml deleted file mode 100644 index 4867f1ca2a..0000000000 --- a/benchmark/vm_thread_close.yml +++ /dev/null @@ -1,9 +0,0 @@ -benchmark: - vm_thread_close: | - 1000.times { Thread.new { sleep } } - i = 0 - while i<100_000 # benchmark loop 3 - i += 1 - IO.pipe.each(&:close) - end -loop_count: 1 diff --git a/benchmark/vm_thread_condvar1.yml b/benchmark/vm_thread_condvar1.yml deleted file mode 100644 index 1f481ab757..0000000000 --- a/benchmark/vm_thread_condvar1.yml +++ /dev/null @@ -1,32 +0,0 @@ -prelude: | - # two threads, two mutex, two condvar ping-pong -benchmark: - vm_thread_condvar1: | - require 'thread' - m1 = Mutex.new - m2 = Mutex.new - cv1 = ConditionVariable.new - cv2 = ConditionVariable.new - max = 100000 - i = 0 - wait = nil - m2.synchronize do - wait = Thread.new do - m1.synchronize do - m2.synchronize { cv2.signal } - while (i += 1) < max - cv1.wait(m1) - cv2.signal - end - end - end - cv2.wait(m2) - end - m1.synchronize do - while i < max - cv1.signal - cv2.wait(m1) - end - end - wait.join -loop_count: 1 diff --git a/benchmark/vm_thread_condvar2.yml b/benchmark/vm_thread_condvar2.yml deleted file mode 100644 index 5b5798c7c5..0000000000 --- a/benchmark/vm_thread_condvar2.yml +++ /dev/null @@ -1,39 +0,0 @@ -prelude: | - # many threads, one mutex, many condvars -benchmark: - vm_thread_condvar2: | - require 'thread' - m = Mutex.new - cv1 = ConditionVariable.new - cv2 = ConditionVariable.new - max = 1000 - n = 100 - waiting = 0 - scvs = [] - waiters = n.times.map do |i| - start_cv = ConditionVariable.new - scvs << start_cv - start_mtx = Mutex.new - start_mtx.synchronize do - th = Thread.new(start_mtx, start_cv) do |sm, scv| - m.synchronize do - sm.synchronize { scv.signal } - max.times do - cv2.signal if (waiting += 1) == n - cv1.wait(m) - end - end - end - start_cv.wait(start_mtx) - th - end - end - m.synchronize do - max.times do - cv2.wait(m) until waiting == n - waiting = 0 - cv1.broadcast - end - end - waiters.each(&:join) -loop_count: 1 diff --git a/benchmark/vm_thread_create_join.yml b/benchmark/vm_thread_create_join.yml deleted file mode 100644 index 7fe82b3fb0..0000000000 --- a/benchmark/vm_thread_create_join.yml +++ /dev/null @@ -1,9 +0,0 @@ -benchmark: - vm_thread_create_join: | - i = 0 - while i<100_000 # benchmark loop 3 - i += 1 - Thread.new{ - }.join - end -loop_count: 1 diff --git a/benchmark/vm_thread_mutex1.yml b/benchmark/vm_thread_mutex1.yml deleted file mode 100644 index 33ab7a2651..0000000000 --- a/benchmark/vm_thread_mutex1.yml +++ /dev/null @@ -1,25 +0,0 @@ -prelude: | - # one thread, one mutex (no contention) -benchmark: - vm_thread_mutex1: | - - require 'thread' - m = Thread::Mutex.new - r = 0 - max = 2000 - lmax = max * max - (1..1).map{ - Thread.new{ - i = 0 - while i 0 - q.push true - n -= 1 - end - q.push nil - } - - consumer.join -loop_count: 1 diff --git a/benchmark/vm_thread_sized_queue2.yml b/benchmark/vm_thread_sized_queue2.yml deleted file mode 100644 index 7a5c2251c1..0000000000 --- a/benchmark/vm_thread_sized_queue2.yml +++ /dev/null @@ -1,26 +0,0 @@ -benchmark: - vm_thread_sized_queue2: | - require 'thread' - # one producer, many consumers - n = 1_000_000 - m = 10 - q = Thread::SizedQueue.new(100) - consumers = m.times.map do - Thread.new do - while q.pop - # consuming - end - end - end - - producer = Thread.new do - while n > 0 - q.push true - n -= 1 - end - m.times { q.push nil } - end - - producer.join - consumers.each(&:join) -loop_count: 1 diff --git a/benchmark/vm_thread_sized_queue3.yml b/benchmark/vm_thread_sized_queue3.yml deleted file mode 100644 index 6eefe50984..0000000000 --- a/benchmark/vm_thread_sized_queue3.yml +++ /dev/null @@ -1,25 +0,0 @@ -benchmark: - vm_thread_sized_queue3: | - require 'thread' - # many producers, one consumer - n = 1_000_000 - m = 10 - q = Thread::SizedQueue.new(100) - consumer = Thread.new do - while q.pop - # consuming - end - end - - producers = m.times.map do - Thread.new do - while n > 0 - q.push true - n -= 1 - end - end - end - producers.each(&:join) - q.push nil - consumer.join -loop_count: 1 diff --git a/benchmark/vm_thread_sized_queue4.yml b/benchmark/vm_thread_sized_queue4.yml deleted file mode 100644 index 2af8ea4ebe..0000000000 --- a/benchmark/vm_thread_sized_queue4.yml +++ /dev/null @@ -1,29 +0,0 @@ -benchmark: - vm_thread_sized_queue4: | - require 'thread' - # many producers, many consumers - nr = 1_000_000 - n = 10 - m = 10 - q = Thread::SizedQueue.new(100) - consumers = n.times.map do - Thread.new do - while q.pop - # consuming - end - end - end - - producers = m.times.map do - Thread.new do - while nr > 0 - q.push true - nr -= 1 - end - end - end - - producers.each(&:join) - n.times { q.push nil } - consumers.each(&:join) -loop_count: 1 -- cgit v1.2.3