From 433af16167aec949c6345ad41b78b17c440b4a6d Mon Sep 17 00:00:00 2001 From: k0kubun Date: Tue, 10 Jul 2018 13:08:40 +0000 Subject: benchmark: drop all bm_ prefix for legacy driver.rb benchmark/*.rb is only benchmarks now. We don't need prefixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/app_answer.rb | 15 + benchmark/app_aobench.rb | 291 ++++++++++++++ benchmark/app_erb.rb | 25 ++ benchmark/app_factorial.rb | 11 + benchmark/app_fib.rb | 10 + benchmark/app_lc_fizzbuzz.rb | 52 +++ benchmark/app_mandelbrot.rb | 23 ++ benchmark/app_pentomino.rb | 130 +++++++ benchmark/app_raise.rb | 8 + benchmark/app_strconcat.rb | 5 + benchmark/app_tak.rb | 13 + benchmark/app_tarai.rb | 10 + benchmark/app_uri.rb | 8 + benchmark/array_sample_100k_10.rb | 2 + benchmark/array_sample_100k_11.rb | 2 + benchmark/array_sample_100k__100.rb | 2 + benchmark/array_sample_100k__1k.rb | 2 + benchmark/array_sample_100k__6k.rb | 2 + benchmark/array_sample_100k___10k.rb | 2 + benchmark/array_sample_100k___50k.rb | 2 + benchmark/array_shift.rb | 14 + benchmark/array_small_and.rb | 17 + benchmark/array_small_diff.rb | 17 + benchmark/array_small_or.rb | 17 + benchmark/array_sort_block.rb | 2 + benchmark/array_sort_float.rb | 2 + benchmark/array_values_at_int.rb | 2 + benchmark/array_values_at_range.rb | 2 + benchmark/bighash.rb | 1 + 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.rb | 5 + benchmark/erb_render.rb | 25 ++ benchmark/file_chmod.rb | 9 + benchmark/file_rename.rb | 11 + benchmark/hash_aref_dsym.rb | 4 + benchmark/hash_aref_dsym_long.rb | 21 ++ benchmark/hash_aref_fix.rb | 4 + benchmark/hash_aref_flo.rb | 4 + benchmark/hash_aref_miss.rb | 5 + benchmark/hash_aref_str.rb | 4 + benchmark/hash_aref_sym.rb | 9 + benchmark/hash_aref_sym_long.rb | 13 + benchmark/hash_flatten.rb | 9 + benchmark/hash_ident_flo.rb | 4 + benchmark/hash_ident_num.rb | 4 + benchmark/hash_ident_obj.rb | 4 + benchmark/hash_ident_str.rb | 4 + benchmark/hash_ident_sym.rb | 4 + benchmark/hash_keys.rb | 9 + benchmark/hash_long.rb | 4 + benchmark/hash_shift.rb | 10 + benchmark/hash_shift_u16.rb | 10 + benchmark/hash_shift_u24.rb | 10 + benchmark/hash_shift_u32.rb | 10 + benchmark/hash_small2.rb | 1 + benchmark/hash_small4.rb | 1 + benchmark/hash_small8.rb | 1 + benchmark/hash_to_proc.rb | 9 + benchmark/hash_values.rb | 9 + benchmark/int_quo.rb | 1 + benchmark/io_copy_stream_write.rb | 24 ++ benchmark/io_copy_stream_write_socket.rb | 35 ++ benchmark/io_file_create.rb | 13 + benchmark/io_file_read.rb | 15 + benchmark/io_file_write.rb | 14 + benchmark/io_nonblock_noex.rb | 22 ++ benchmark/io_nonblock_noex2.rb | 21 ++ benchmark/io_pipe_rw.rb | 13 + benchmark/io_select.rb | 9 + benchmark/io_select2.rb | 22 ++ benchmark/io_select3.rb | 21 ++ benchmark/loop_for.rb | 3 + benchmark/loop_generator.rb | 14 + benchmark/loop_times.rb | 1 + benchmark/loop_whileloop.rb | 4 + benchmark/loop_whileloop2.rb | 4 + benchmark/marshal_dump_flo.rb | 2 + benchmark/marshal_dump_load_geniv.rb | 10 + benchmark/marshal_dump_load_time.rb | 1 + benchmark/securerandom.rb | 5 + benchmark/so_ackermann.rb | 19 + benchmark/so_array.rb | 23 ++ benchmark/so_binary_trees.rb | 62 +++ benchmark/so_concatenate.rb | 18 + benchmark/so_exception.rb | 61 +++ benchmark/so_fannkuch.rb | 45 +++ benchmark/so_fasta.rb | 81 ++++ benchmark/so_lists.rb | 47 +++ benchmark/so_mandelbrot.rb | 57 +++ benchmark/so_matrix.rb | 48 +++ benchmark/so_meteor_contest.rb | 563 ++++++++++++++++++++++++++++ benchmark/so_nbody.rb | 148 ++++++++ benchmark/so_nested_loop.rb | 24 ++ benchmark/so_nsieve.rb | 35 ++ benchmark/so_nsieve_bits.rb | 43 +++ benchmark/so_object.rb | 56 +++ benchmark/so_partial_sums.rb | 31 ++ benchmark/so_pidigits.rb | 92 +++++ benchmark/so_random.rb | 20 + benchmark/so_sieve.rb | 24 ++ benchmark/so_spectralnorm.rb | 50 +++ benchmark/string_index.rb | 3 + benchmark/string_scan_re.rb | 2 + benchmark/string_scan_str.rb | 2 + benchmark/time_subsec.rb | 2 + benchmark/vm3_backtrace.rb | 22 ++ benchmark/vm3_clearmethodcache.rb | 8 + benchmark/vm3_gc.rb | 6 + benchmark/vm3_gc_old_full.rb | 4 + benchmark/vm3_gc_old_immediate.rb | 4 + benchmark/vm3_gc_old_lazy.rb | 4 + benchmark/vm_symbol_block_pass.rb | 13 + benchmark/vm_thread_alive_check1.rb | 6 + benchmark/vm_thread_close.rb | 6 + benchmark/vm_thread_condvar1.rb | 28 ++ benchmark/vm_thread_condvar2.rb | 35 ++ benchmark/vm_thread_create_join.rb | 6 + benchmark/vm_thread_mutex1.rb | 21 ++ benchmark/vm_thread_mutex2.rb | 21 ++ benchmark/vm_thread_mutex3.rb | 20 + benchmark/vm_thread_pass.rb | 15 + benchmark/vm_thread_pass_flood.rb | 10 + benchmark/vm_thread_pipe.rb | 17 + benchmark/vm_thread_queue.rb | 18 + benchmark/vm_thread_sized_queue.rb | 20 + benchmark/vm_thread_sized_queue2.rb | 23 ++ benchmark/vm_thread_sized_queue3.rb | 22 ++ benchmark/vm_thread_sized_queue4.rb | 26 ++ 254 files changed, 3071 insertions(+), 3071 deletions(-) create mode 100644 benchmark/app_answer.rb create mode 100644 benchmark/app_aobench.rb create mode 100644 benchmark/app_erb.rb create mode 100644 benchmark/app_factorial.rb create mode 100644 benchmark/app_fib.rb create mode 100644 benchmark/app_lc_fizzbuzz.rb create mode 100644 benchmark/app_mandelbrot.rb create mode 100644 benchmark/app_pentomino.rb create mode 100644 benchmark/app_raise.rb create mode 100644 benchmark/app_strconcat.rb create mode 100644 benchmark/app_tak.rb create mode 100644 benchmark/app_tarai.rb create mode 100644 benchmark/app_uri.rb create mode 100644 benchmark/array_sample_100k_10.rb create mode 100644 benchmark/array_sample_100k_11.rb create mode 100644 benchmark/array_sample_100k__100.rb create mode 100644 benchmark/array_sample_100k__1k.rb create mode 100644 benchmark/array_sample_100k__6k.rb create mode 100644 benchmark/array_sample_100k___10k.rb create mode 100644 benchmark/array_sample_100k___50k.rb create mode 100644 benchmark/array_shift.rb create mode 100644 benchmark/array_small_and.rb create mode 100644 benchmark/array_small_diff.rb create mode 100644 benchmark/array_small_or.rb create mode 100644 benchmark/array_sort_block.rb create mode 100644 benchmark/array_sort_float.rb create mode 100644 benchmark/array_values_at_int.rb create mode 100644 benchmark/array_values_at_range.rb create mode 100644 benchmark/bighash.rb delete mode 100644 benchmark/bm_app_answer.rb delete mode 100644 benchmark/bm_app_aobench.rb delete mode 100644 benchmark/bm_app_erb.rb delete mode 100644 benchmark/bm_app_factorial.rb delete mode 100644 benchmark/bm_app_fib.rb delete mode 100644 benchmark/bm_app_lc_fizzbuzz.rb delete mode 100644 benchmark/bm_app_mandelbrot.rb delete mode 100644 benchmark/bm_app_pentomino.rb delete mode 100644 benchmark/bm_app_raise.rb delete mode 100644 benchmark/bm_app_strconcat.rb delete mode 100644 benchmark/bm_app_tak.rb delete mode 100644 benchmark/bm_app_tarai.rb delete mode 100644 benchmark/bm_app_uri.rb delete mode 100644 benchmark/bm_array_sample_100k_10.rb delete mode 100644 benchmark/bm_array_sample_100k_11.rb delete mode 100644 benchmark/bm_array_sample_100k__100.rb delete mode 100644 benchmark/bm_array_sample_100k__1k.rb delete mode 100644 benchmark/bm_array_sample_100k__6k.rb delete mode 100644 benchmark/bm_array_sample_100k___10k.rb delete mode 100644 benchmark/bm_array_sample_100k___50k.rb delete mode 100644 benchmark/bm_array_shift.rb delete mode 100644 benchmark/bm_array_small_and.rb delete mode 100644 benchmark/bm_array_small_diff.rb delete mode 100644 benchmark/bm_array_small_or.rb delete mode 100644 benchmark/bm_array_sort_block.rb delete mode 100644 benchmark/bm_array_sort_float.rb delete mode 100644 benchmark/bm_array_values_at_int.rb delete mode 100644 benchmark/bm_array_values_at_range.rb delete mode 100644 benchmark/bm_bighash.rb delete mode 100644 benchmark/bm_dir_empty_p.rb delete mode 100644 benchmark/bm_erb_render.rb delete mode 100644 benchmark/bm_file_chmod.rb delete mode 100644 benchmark/bm_file_rename.rb delete mode 100644 benchmark/bm_hash_aref_dsym.rb delete mode 100644 benchmark/bm_hash_aref_dsym_long.rb delete mode 100644 benchmark/bm_hash_aref_fix.rb delete mode 100644 benchmark/bm_hash_aref_flo.rb delete mode 100644 benchmark/bm_hash_aref_miss.rb delete mode 100644 benchmark/bm_hash_aref_str.rb delete mode 100644 benchmark/bm_hash_aref_sym.rb delete mode 100644 benchmark/bm_hash_aref_sym_long.rb delete mode 100644 benchmark/bm_hash_flatten.rb delete mode 100644 benchmark/bm_hash_ident_flo.rb delete mode 100644 benchmark/bm_hash_ident_num.rb delete mode 100644 benchmark/bm_hash_ident_obj.rb delete mode 100644 benchmark/bm_hash_ident_str.rb delete mode 100644 benchmark/bm_hash_ident_sym.rb delete mode 100644 benchmark/bm_hash_keys.rb delete mode 100644 benchmark/bm_hash_long.rb delete mode 100644 benchmark/bm_hash_shift.rb delete mode 100644 benchmark/bm_hash_shift_u16.rb delete mode 100644 benchmark/bm_hash_shift_u24.rb delete mode 100644 benchmark/bm_hash_shift_u32.rb delete mode 100644 benchmark/bm_hash_small2.rb delete mode 100644 benchmark/bm_hash_small4.rb delete mode 100644 benchmark/bm_hash_small8.rb delete mode 100644 benchmark/bm_hash_to_proc.rb delete mode 100644 benchmark/bm_hash_values.rb delete mode 100644 benchmark/bm_int_quo.rb delete mode 100644 benchmark/bm_io_copy_stream_write.rb delete mode 100644 benchmark/bm_io_copy_stream_write_socket.rb delete mode 100644 benchmark/bm_io_file_create.rb delete mode 100644 benchmark/bm_io_file_read.rb delete mode 100644 benchmark/bm_io_file_write.rb delete mode 100644 benchmark/bm_io_nonblock_noex.rb delete mode 100644 benchmark/bm_io_nonblock_noex2.rb delete mode 100644 benchmark/bm_io_pipe_rw.rb delete mode 100644 benchmark/bm_io_select.rb delete mode 100644 benchmark/bm_io_select2.rb delete mode 100644 benchmark/bm_io_select3.rb delete mode 100644 benchmark/bm_loop_for.rb delete mode 100644 benchmark/bm_loop_generator.rb delete mode 100644 benchmark/bm_loop_times.rb delete mode 100644 benchmark/bm_loop_whileloop.rb delete mode 100644 benchmark/bm_loop_whileloop2.rb delete mode 100644 benchmark/bm_marshal_dump_flo.rb delete mode 100644 benchmark/bm_marshal_dump_load_geniv.rb delete mode 100644 benchmark/bm_marshal_dump_load_time.rb delete mode 100644 benchmark/bm_securerandom.rb delete mode 100644 benchmark/bm_so_ackermann.rb delete mode 100644 benchmark/bm_so_array.rb delete mode 100644 benchmark/bm_so_binary_trees.rb delete mode 100644 benchmark/bm_so_concatenate.rb delete mode 100644 benchmark/bm_so_exception.rb delete mode 100644 benchmark/bm_so_fannkuch.rb delete mode 100644 benchmark/bm_so_fasta.rb delete mode 100644 benchmark/bm_so_lists.rb delete mode 100644 benchmark/bm_so_mandelbrot.rb delete mode 100644 benchmark/bm_so_matrix.rb delete mode 100755 benchmark/bm_so_meteor_contest.rb delete mode 100644 benchmark/bm_so_nbody.rb delete mode 100644 benchmark/bm_so_nested_loop.rb delete mode 100644 benchmark/bm_so_nsieve.rb delete mode 100644 benchmark/bm_so_nsieve_bits.rb delete mode 100644 benchmark/bm_so_object.rb delete mode 100644 benchmark/bm_so_partial_sums.rb delete mode 100644 benchmark/bm_so_pidigits.rb delete mode 100644 benchmark/bm_so_random.rb delete mode 100644 benchmark/bm_so_sieve.rb delete mode 100644 benchmark/bm_so_spectralnorm.rb delete mode 100644 benchmark/bm_string_index.rb delete mode 100644 benchmark/bm_string_scan_re.rb delete mode 100644 benchmark/bm_string_scan_str.rb delete mode 100644 benchmark/bm_time_subsec.rb delete mode 100644 benchmark/bm_vm3_backtrace.rb delete mode 100644 benchmark/bm_vm3_clearmethodcache.rb delete mode 100644 benchmark/bm_vm3_gc.rb delete mode 100644 benchmark/bm_vm3_gc_old_full.rb delete mode 100644 benchmark/bm_vm3_gc_old_immediate.rb delete mode 100644 benchmark/bm_vm3_gc_old_lazy.rb delete mode 100644 benchmark/bm_vm_symbol_block_pass.rb delete mode 100644 benchmark/bm_vm_thread_alive_check1.rb delete mode 100644 benchmark/bm_vm_thread_close.rb delete mode 100644 benchmark/bm_vm_thread_condvar1.rb delete mode 100644 benchmark/bm_vm_thread_condvar2.rb delete mode 100644 benchmark/bm_vm_thread_create_join.rb delete mode 100644 benchmark/bm_vm_thread_mutex1.rb delete mode 100644 benchmark/bm_vm_thread_mutex2.rb delete mode 100644 benchmark/bm_vm_thread_mutex3.rb delete mode 100644 benchmark/bm_vm_thread_pass.rb delete mode 100644 benchmark/bm_vm_thread_pass_flood.rb delete mode 100644 benchmark/bm_vm_thread_pipe.rb delete mode 100644 benchmark/bm_vm_thread_queue.rb delete mode 100644 benchmark/bm_vm_thread_sized_queue.rb delete mode 100644 benchmark/bm_vm_thread_sized_queue2.rb delete mode 100644 benchmark/bm_vm_thread_sized_queue3.rb delete mode 100644 benchmark/bm_vm_thread_sized_queue4.rb create mode 100644 benchmark/dir_empty_p.rb create mode 100644 benchmark/erb_render.rb create mode 100644 benchmark/file_chmod.rb create mode 100644 benchmark/file_rename.rb create mode 100644 benchmark/hash_aref_dsym.rb create mode 100644 benchmark/hash_aref_dsym_long.rb create mode 100644 benchmark/hash_aref_fix.rb create mode 100644 benchmark/hash_aref_flo.rb create mode 100644 benchmark/hash_aref_miss.rb create mode 100644 benchmark/hash_aref_str.rb create mode 100644 benchmark/hash_aref_sym.rb create mode 100644 benchmark/hash_aref_sym_long.rb create mode 100644 benchmark/hash_flatten.rb create mode 100644 benchmark/hash_ident_flo.rb create mode 100644 benchmark/hash_ident_num.rb create mode 100644 benchmark/hash_ident_obj.rb create mode 100644 benchmark/hash_ident_str.rb create mode 100644 benchmark/hash_ident_sym.rb create mode 100644 benchmark/hash_keys.rb create mode 100644 benchmark/hash_long.rb create mode 100644 benchmark/hash_shift.rb create mode 100644 benchmark/hash_shift_u16.rb create mode 100644 benchmark/hash_shift_u24.rb create mode 100644 benchmark/hash_shift_u32.rb create mode 100644 benchmark/hash_small2.rb create mode 100644 benchmark/hash_small4.rb create mode 100644 benchmark/hash_small8.rb create mode 100644 benchmark/hash_to_proc.rb create mode 100644 benchmark/hash_values.rb create mode 100644 benchmark/int_quo.rb create mode 100644 benchmark/io_copy_stream_write.rb create mode 100644 benchmark/io_copy_stream_write_socket.rb create mode 100644 benchmark/io_file_create.rb create mode 100644 benchmark/io_file_read.rb create mode 100644 benchmark/io_file_write.rb create mode 100644 benchmark/io_nonblock_noex.rb create mode 100644 benchmark/io_nonblock_noex2.rb create mode 100644 benchmark/io_pipe_rw.rb create mode 100644 benchmark/io_select.rb create mode 100644 benchmark/io_select2.rb create mode 100644 benchmark/io_select3.rb create mode 100644 benchmark/loop_for.rb create mode 100644 benchmark/loop_generator.rb create mode 100644 benchmark/loop_times.rb create mode 100644 benchmark/loop_whileloop.rb create mode 100644 benchmark/loop_whileloop2.rb create mode 100644 benchmark/marshal_dump_flo.rb create mode 100644 benchmark/marshal_dump_load_geniv.rb create mode 100644 benchmark/marshal_dump_load_time.rb create mode 100644 benchmark/securerandom.rb create mode 100644 benchmark/so_ackermann.rb create mode 100644 benchmark/so_array.rb create mode 100644 benchmark/so_binary_trees.rb create mode 100644 benchmark/so_concatenate.rb create mode 100644 benchmark/so_exception.rb create mode 100644 benchmark/so_fannkuch.rb create mode 100644 benchmark/so_fasta.rb create mode 100644 benchmark/so_lists.rb create mode 100644 benchmark/so_mandelbrot.rb create mode 100644 benchmark/so_matrix.rb create mode 100644 benchmark/so_meteor_contest.rb create mode 100644 benchmark/so_nbody.rb create mode 100644 benchmark/so_nested_loop.rb create mode 100644 benchmark/so_nsieve.rb create mode 100644 benchmark/so_nsieve_bits.rb create mode 100644 benchmark/so_object.rb create mode 100644 benchmark/so_partial_sums.rb create mode 100644 benchmark/so_pidigits.rb create mode 100644 benchmark/so_random.rb create mode 100644 benchmark/so_sieve.rb create mode 100644 benchmark/so_spectralnorm.rb create mode 100644 benchmark/string_index.rb create mode 100644 benchmark/string_scan_re.rb create mode 100644 benchmark/string_scan_str.rb create mode 100644 benchmark/time_subsec.rb create mode 100644 benchmark/vm3_backtrace.rb create mode 100644 benchmark/vm3_clearmethodcache.rb create mode 100644 benchmark/vm3_gc.rb create mode 100644 benchmark/vm3_gc_old_full.rb create mode 100644 benchmark/vm3_gc_old_immediate.rb create mode 100644 benchmark/vm3_gc_old_lazy.rb create mode 100644 benchmark/vm_symbol_block_pass.rb create mode 100644 benchmark/vm_thread_alive_check1.rb create mode 100644 benchmark/vm_thread_close.rb create mode 100644 benchmark/vm_thread_condvar1.rb create mode 100644 benchmark/vm_thread_condvar2.rb create mode 100644 benchmark/vm_thread_create_join.rb create mode 100644 benchmark/vm_thread_mutex1.rb create mode 100644 benchmark/vm_thread_mutex2.rb create mode 100644 benchmark/vm_thread_mutex3.rb create mode 100644 benchmark/vm_thread_pass.rb create mode 100644 benchmark/vm_thread_pass_flood.rb create mode 100644 benchmark/vm_thread_pipe.rb create mode 100644 benchmark/vm_thread_queue.rb create mode 100644 benchmark/vm_thread_sized_queue.rb create mode 100644 benchmark/vm_thread_sized_queue2.rb create mode 100644 benchmark/vm_thread_sized_queue3.rb create mode 100644 benchmark/vm_thread_sized_queue4.rb (limited to 'benchmark') diff --git a/benchmark/app_answer.rb b/benchmark/app_answer.rb new file mode 100644 index 0000000000..3cd8a8fd37 --- /dev/null +++ b/benchmark/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/app_aobench.rb b/benchmark/app_aobench.rb new file mode 100644 index 0000000000..2bd6acfaf8 --- /dev/null +++ b/benchmark/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/app_erb.rb b/benchmark/app_erb.rb new file mode 100644 index 0000000000..9a1cb2707f --- /dev/null +++ b/benchmark/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/app_factorial.rb b/benchmark/app_factorial.rb new file mode 100644 index 0000000000..45f471dfdb --- /dev/null +++ b/benchmark/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/app_fib.rb b/benchmark/app_fib.rb new file mode 100644 index 0000000000..34a7b2e725 --- /dev/null +++ b/benchmark/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/app_lc_fizzbuzz.rb b/benchmark/app_lc_fizzbuzz.rb new file mode 100644 index 0000000000..f09574bbeb --- /dev/null +++ b/benchmark/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/app_mandelbrot.rb b/benchmark/app_mandelbrot.rb new file mode 100644 index 0000000000..801b75e8e2 --- /dev/null +++ b/benchmark/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/app_pentomino.rb b/benchmark/app_pentomino.rb new file mode 100644 index 0000000000..47be7b203f --- /dev/null +++ b/benchmark/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/app_raise.rb b/benchmark/app_raise.rb new file mode 100644 index 0000000000..5db8f95d50 --- /dev/null +++ b/benchmark/app_raise.rb @@ -0,0 +1,8 @@ +i = 0 +while i<300000 + i += 1 + begin + raise + rescue + end +end diff --git a/benchmark/app_strconcat.rb b/benchmark/app_strconcat.rb new file mode 100644 index 0000000000..7eed7c1aed --- /dev/null +++ b/benchmark/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/app_tak.rb b/benchmark/app_tak.rb new file mode 100644 index 0000000000..efe5380f4e --- /dev/null +++ b/benchmark/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/app_tarai.rb b/benchmark/app_tarai.rb new file mode 100644 index 0000000000..4c146f5ccf --- /dev/null +++ b/benchmark/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/app_uri.rb b/benchmark/app_uri.rb new file mode 100644 index 0000000000..586edfd5dc --- /dev/null +++ b/benchmark/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/array_sample_100k_10.rb b/benchmark/array_sample_100k_10.rb new file mode 100644 index 0000000000..5f41ecc32b --- /dev/null +++ b/benchmark/array_sample_100k_10.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 10} diff --git a/benchmark/array_sample_100k_11.rb b/benchmark/array_sample_100k_11.rb new file mode 100644 index 0000000000..18b1715319 --- /dev/null +++ b/benchmark/array_sample_100k_11.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 11} diff --git a/benchmark/array_sample_100k__100.rb b/benchmark/array_sample_100k__100.rb new file mode 100644 index 0000000000..22863afe89 --- /dev/null +++ b/benchmark/array_sample_100k__100.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 100} diff --git a/benchmark/array_sample_100k__1k.rb b/benchmark/array_sample_100k__1k.rb new file mode 100644 index 0000000000..4cd79e6c67 --- /dev/null +++ b/benchmark/array_sample_100k__1k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 1000} diff --git a/benchmark/array_sample_100k__6k.rb b/benchmark/array_sample_100k__6k.rb new file mode 100644 index 0000000000..b3d264249e --- /dev/null +++ b/benchmark/array_sample_100k__6k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 6000} diff --git a/benchmark/array_sample_100k___10k.rb b/benchmark/array_sample_100k___10k.rb new file mode 100644 index 0000000000..5dd55ec058 --- /dev/null +++ b/benchmark/array_sample_100k___10k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 10_000} diff --git a/benchmark/array_sample_100k___50k.rb b/benchmark/array_sample_100k___50k.rb new file mode 100644 index 0000000000..1506732c3c --- /dev/null +++ b/benchmark/array_sample_100k___50k.rb @@ -0,0 +1,2 @@ +arr = [*0...100000] +10_000.times {arr.sample 50_000} diff --git a/benchmark/array_shift.rb b/benchmark/array_shift.rb new file mode 100644 index 0000000000..798bb9e3f4 --- /dev/null +++ b/benchmark/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/array_small_and.rb b/benchmark/array_small_and.rb new file mode 100644 index 0000000000..e53a6edae6 --- /dev/null +++ b/benchmark/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/array_small_diff.rb b/benchmark/array_small_diff.rb new file mode 100644 index 0000000000..9661ee48db --- /dev/null +++ b/benchmark/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/array_small_or.rb b/benchmark/array_small_or.rb new file mode 100644 index 0000000000..c58b5fd1ff --- /dev/null +++ b/benchmark/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/array_sort_block.rb b/benchmark/array_sort_block.rb new file mode 100644 index 0000000000..3579786056 --- /dev/null +++ b/benchmark/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/array_sort_float.rb b/benchmark/array_sort_float.rb new file mode 100644 index 0000000000..9a6e2f8bd2 --- /dev/null +++ b/benchmark/array_sort_float.rb @@ -0,0 +1,2 @@ +arr = Array.new(1000) { rand } +10000.times { arr.sort } diff --git a/benchmark/array_values_at_int.rb b/benchmark/array_values_at_int.rb new file mode 100644 index 0000000000..6cb394cb9f --- /dev/null +++ b/benchmark/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/array_values_at_range.rb b/benchmark/array_values_at_range.rb new file mode 100644 index 0000000000..5b53806d1c --- /dev/null +++ b/benchmark/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/bighash.rb b/benchmark/bighash.rb new file mode 100644 index 0000000000..e2ad5a5c94 --- /dev/null +++ b/benchmark/bighash.rb @@ -0,0 +1 @@ +h = {}; 5000000.times {|n| h[n] = n } diff --git a/benchmark/bm_app_answer.rb b/benchmark/bm_app_answer.rb deleted file mode 100644 index 3cd8a8fd37..0000000000 --- a/benchmark/bm_app_answer.rb +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 2bd6acfaf8..0000000000 --- a/benchmark/bm_app_aobench.rb +++ /dev/null @@ -1,291 +0,0 @@ -# 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 deleted file mode 100644 index 9a1cb2707f..0000000000 --- a/benchmark/bm_app_erb.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -# 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 deleted file mode 100644 index 45f471dfdb..0000000000 --- a/benchmark/bm_app_factorial.rb +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 34a7b2e725..0000000000 --- a/benchmark/bm_app_fib.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index f09574bbeb..0000000000 --- a/benchmark/bm_app_lc_fizzbuzz.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# 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 deleted file mode 100644 index 801b75e8e2..0000000000 --- a/benchmark/bm_app_mandelbrot.rb +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 47be7b203f..0000000000 --- a/benchmark/bm_app_pentomino.rb +++ /dev/null @@ -1,130 +0,0 @@ -#!/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 deleted file mode 100644 index 5db8f95d50..0000000000 --- a/benchmark/bm_app_raise.rb +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7eed7c1aed..0000000000 --- a/benchmark/bm_app_strconcat.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index efe5380f4e..0000000000 --- a/benchmark/bm_app_tak.rb +++ /dev/null @@ -1,13 +0,0 @@ - -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 deleted file mode 100644 index 4c146f5ccf..0000000000 --- a/benchmark/bm_app_tarai.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 586edfd5dc..0000000000 --- a/benchmark/bm_app_uri.rb +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 5f41ecc32b..0000000000 --- a/benchmark/bm_array_sample_100k_10.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 18b1715319..0000000000 --- a/benchmark/bm_array_sample_100k_11.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 22863afe89..0000000000 --- a/benchmark/bm_array_sample_100k__100.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 4cd79e6c67..0000000000 --- a/benchmark/bm_array_sample_100k__1k.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index b3d264249e..0000000000 --- a/benchmark/bm_array_sample_100k__6k.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 5dd55ec058..0000000000 --- a/benchmark/bm_array_sample_100k___10k.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 1506732c3c..0000000000 --- a/benchmark/bm_array_sample_100k___50k.rb +++ /dev/null @@ -1,2 +0,0 @@ -arr = [*0...100000] -10_000.times {arr.sample 50_000} diff --git a/benchmark/bm_array_shift.rb b/benchmark/bm_array_shift.rb deleted file mode 100644 index 798bb9e3f4..0000000000 --- a/benchmark/bm_array_shift.rb +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index e53a6edae6..0000000000 --- a/benchmark/bm_array_small_and.rb +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 9661ee48db..0000000000 --- a/benchmark/bm_array_small_diff.rb +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index c58b5fd1ff..0000000000 --- a/benchmark/bm_array_small_or.rb +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 3579786056..0000000000 --- a/benchmark/bm_array_sort_block.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 9a6e2f8bd2..0000000000 --- a/benchmark/bm_array_sort_float.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 6cb394cb9f..0000000000 --- a/benchmark/bm_array_values_at_int.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 5b53806d1c..0000000000 --- a/benchmark/bm_array_values_at_range.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index e2ad5a5c94..0000000000 --- a/benchmark/bm_bighash.rb +++ /dev/null @@ -1 +0,0 @@ -h = {}; 5000000.times {|n| h[n] = n } diff --git a/benchmark/bm_dir_empty_p.rb b/benchmark/bm_dir_empty_p.rb deleted file mode 100644 index 8329c757cf..0000000000 --- a/benchmark/bm_dir_empty_p.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 7dc0816c43..0000000000 --- a/benchmark/bm_erb_render.rb +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 1cd4760c9d..0000000000 --- a/benchmark/bm_file_chmod.rb +++ /dev/null @@ -1,9 +0,0 @@ -# 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 deleted file mode 100644 index bbb44aebac..0000000000 --- a/benchmark/bm_file_rename.rb +++ /dev/null @@ -1,11 +0,0 @@ -# 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 deleted file mode 100644 index af4f8c36d4..0000000000 --- a/benchmark/bm_hash_aref_dsym.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 9d7759379e..0000000000 --- a/benchmark/bm_hash_aref_dsym_long.rb +++ /dev/null @@ -1,21 +0,0 @@ -# [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 deleted file mode 100644 index 1346890582..0000000000 --- a/benchmark/bm_hash_aref_fix.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 2217274c82..0000000000 --- a/benchmark/bm_hash_aref_flo.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index b0913dd4bb..0000000000 --- a/benchmark/bm_hash_aref_miss.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 19439b061b..0000000000 --- a/benchmark/bm_hash_aref_str.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index f75d163fe6..0000000000 --- a/benchmark/bm_hash_aref_sym.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 9dab8df7be..0000000000 --- a/benchmark/bm_hash_aref_sym_long.rb +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index e944aae9f2..0000000000 --- a/benchmark/bm_hash_flatten.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 0c7edfed3e..0000000000 --- a/benchmark/bm_hash_ident_flo.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index b226736c6f..0000000000 --- a/benchmark/bm_hash_ident_num.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 4b3b58edec..0000000000 --- a/benchmark/bm_hash_ident_obj.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 8582b38e31..0000000000 --- a/benchmark/bm_hash_ident_str.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 4c81e3d28e..0000000000 --- a/benchmark/bm_hash_ident_sym.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 6863cd01f9..0000000000 --- a/benchmark/bm_hash_keys.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 03d9109602..0000000000 --- a/benchmark/bm_hash_long.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index a645671a5b..0000000000 --- a/benchmark/bm_hash_shift.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index ec800d0342..0000000000 --- a/benchmark/bm_hash_shift_u16.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index de4e0fa696..0000000000 --- a/benchmark/bm_hash_shift_u24.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 656aa55583..0000000000 --- a/benchmark/bm_hash_shift_u32.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 45485d9c71..0000000000 --- a/benchmark/bm_hash_small2.rb +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index acd4084334..0000000000 --- a/benchmark/bm_hash_small4.rb +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 9cffcc91b6..0000000000 --- a/benchmark/bm_hash_small8.rb +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 2b675bf509..0000000000 --- a/benchmark/bm_hash_to_proc.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 069441302f..0000000000 --- a/benchmark/bm_hash_values.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index e22a3f8c30..0000000000 --- a/benchmark/bm_int_quo.rb +++ /dev/null @@ -1 +0,0 @@ -5000000.times { 42.quo(3) } diff --git a/benchmark/bm_io_copy_stream_write.rb b/benchmark/bm_io_copy_stream_write.rb deleted file mode 100644 index 3fd87250a4..0000000000 --- a/benchmark/bm_io_copy_stream_write.rb +++ /dev/null @@ -1,24 +0,0 @@ -# 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 deleted file mode 100644 index 11f369bd0d..0000000000 --- a/benchmark/bm_io_copy_stream_write_socket.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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 deleted file mode 100644 index 2f205c1333..0000000000 --- a/benchmark/bm_io_file_create.rb +++ /dev/null @@ -1,13 +0,0 @@ -# -# 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 deleted file mode 100644 index b9e796ed30..0000000000 --- a/benchmark/bm_io_file_read.rb +++ /dev/null @@ -1,15 +0,0 @@ -# -# 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 deleted file mode 100644 index aa1be0e5fe..0000000000 --- a/benchmark/bm_io_file_write.rb +++ /dev/null @@ -1,14 +0,0 @@ -# -# 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 deleted file mode 100644 index da9357fdc6..0000000000 --- a/benchmark/bm_io_nonblock_noex.rb +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 56819d049b..0000000000 --- a/benchmark/bm_io_nonblock_noex2.rb +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 6862a8ae61..0000000000 --- a/benchmark/bm_io_pipe_rw.rb +++ /dev/null @@ -1,13 +0,0 @@ -# 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 deleted file mode 100644 index 19248daeb1..0000000000 --- a/benchmark/bm_io_select.rb +++ /dev/null @@ -1,9 +0,0 @@ -# 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 deleted file mode 100644 index 10e37d71b2..0000000000 --- a/benchmark/bm_io_select2.rb +++ /dev/null @@ -1,22 +0,0 @@ -# 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 deleted file mode 100644 index 7d0ba1f092..0000000000 --- a/benchmark/bm_io_select3.rb +++ /dev/null @@ -1,21 +0,0 @@ -# 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 deleted file mode 100644 index 0fc4cc1511..0000000000 --- a/benchmark/bm_loop_for.rb +++ /dev/null @@ -1,3 +0,0 @@ -for i in 1..30_000_000 - # -end diff --git a/benchmark/bm_loop_generator.rb b/benchmark/bm_loop_generator.rb deleted file mode 100644 index d3375c744c..0000000000 --- a/benchmark/bm_loop_generator.rb +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 521f72ad1a..0000000000 --- a/benchmark/bm_loop_times.rb +++ /dev/null @@ -1 +0,0 @@ -30_000_000.times{|e|} diff --git a/benchmark/bm_loop_whileloop.rb b/benchmark/bm_loop_whileloop.rb deleted file mode 100644 index 0072822c06..0000000000 --- a/benchmark/bm_loop_whileloop.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 47d02dffc4..0000000000 --- a/benchmark/bm_loop_whileloop2.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 9b8d0c6afb..0000000000 --- a/benchmark/bm_marshal_dump_flo.rb +++ /dev/null @@ -1,2 +0,0 @@ -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 deleted file mode 100644 index 8252ad90fa..0000000000 --- a/benchmark/bm_marshal_dump_load_geniv.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index e29743b791..0000000000 --- a/benchmark/bm_marshal_dump_load_time.rb +++ /dev/null @@ -1 +0,0 @@ -100000.times { Marshal.load(Marshal.dump(Time.now)) } diff --git a/benchmark/bm_securerandom.rb b/benchmark/bm_securerandom.rb deleted file mode 100644 index a082ea6d5b..0000000000 --- a/benchmark/bm_securerandom.rb +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 7db5be9050..0000000000 --- a/benchmark/bm_so_ackermann.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/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 deleted file mode 100644 index 2b8fce8f99..0000000000 --- a/benchmark/bm_so_array.rb +++ /dev/null @@ -1,23 +0,0 @@ -#!/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 deleted file mode 100644 index b1693e4109..0000000000 --- a/benchmark/bm_so_binary_trees.rb +++ /dev/null @@ -1,62 +0,0 @@ -# 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 deleted file mode 100644 index 873214de7c..0000000000 --- a/benchmark/bm_so_concatenate.rb +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 deleted file mode 100644 index deb003a594..0000000000 --- a/benchmark/bm_so_exception.rb +++ /dev/null @@ -1,61 +0,0 @@ -#!/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 deleted file mode 100644 index bac5ecd44c..0000000000 --- a/benchmark/bm_so_fannkuch.rb +++ /dev/null @@ -1,45 +0,0 @@ -# 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 deleted file mode 100644 index dcc6b39507..0000000000 --- a/benchmark/bm_so_fasta.rb +++ /dev/null @@ -1,81 +0,0 @@ -# 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 deleted file mode 100644 index e8f4a2a5f7..0000000000 --- a/benchmark/bm_so_lists.rb +++ /dev/null @@ -1,47 +0,0 @@ -#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 deleted file mode 100644 index e2c5c8e559..0000000000 --- a/benchmark/bm_so_matrix.rb +++ /dev/null @@ -1,48 +0,0 @@ -#!/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 deleted file mode 100755 index 8c136baa6c..0000000000 --- a/benchmark/bm_so_meteor_contest.rb +++ /dev/null @@ -1,563 +0,0 @@ -#!/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 deleted file mode 100644 index d6c5bb9e61..0000000000 --- a/benchmark/bm_so_nbody.rb +++ /dev/null @@ -1,148 +0,0 @@ -# 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 deleted file mode 100644 index a0513f8c47..0000000000 --- a/benchmark/bm_so_nested_loop.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/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 deleted file mode 100644 index a65cc78233..0000000000 --- a/benchmark/bm_so_nsieve.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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 deleted file mode 100644 index 6f958ee44e..0000000000 --- a/benchmark/bm_so_nsieve_bits.rb +++ /dev/null @@ -1,43 +0,0 @@ -#!/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 deleted file mode 100644 index e8607c7199..0000000000 --- a/benchmark/bm_so_object.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/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 deleted file mode 100644 index 630b45cb8d..0000000000 --- a/benchmark/bm_so_partial_sums.rb +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 9a537b2d1c..0000000000 --- a/benchmark/bm_so_pidigits.rb +++ /dev/null @@ -1,92 +0,0 @@ -# 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 deleted file mode 100644 index a66b9e8e63..0000000000 --- a/benchmark/bm_so_random.rb +++ /dev/null @@ -1,20 +0,0 @@ -# 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 deleted file mode 100644 index cfdfc8c5a5..0000000000 --- a/benchmark/bm_vm3_gc_old_full.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index ad22feb655..0000000000 --- a/benchmark/bm_vm3_gc_old_immediate.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index b74d44baf1..0000000000 --- a/benchmark/bm_vm3_gc_old_lazy.rb +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 1d433353e1..0000000000 --- a/benchmark/bm_vm_symbol_block_pass.rb +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index c993accdda..0000000000 --- a/benchmark/bm_vm_thread_alive_check1.rb +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 3e9a265ce8..0000000000 --- a/benchmark/bm_vm_thread_close.rb +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index cf5706b23e..0000000000 --- a/benchmark/bm_vm_thread_condvar1.rb +++ /dev/null @@ -1,28 +0,0 @@ -# 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 deleted file mode 100644 index 7c8dc19481..0000000000 --- a/benchmark/bm_vm_thread_condvar2.rb +++ /dev/null @@ -1,35 +0,0 @@ -# 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 deleted file mode 100644 index 393cd45df9..0000000000 --- a/benchmark/bm_vm_thread_create_join.rb +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 66e42c85e1..0000000000 --- a/benchmark/bm_vm_thread_mutex1.rb +++ /dev/null @@ -1,21 +0,0 @@ -# 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 deleted file mode 100644 index de9f55e978..0000000000 --- a/benchmark/bm_vm_thread_sized_queue2.rb +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index ce5f1796d8..0000000000 --- a/benchmark/bm_vm_thread_sized_queue3.rb +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index a9b7d80ec0..0000000000 --- a/benchmark/bm_vm_thread_sized_queue4.rb +++ /dev/null @@ -1,26 +0,0 @@ -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.rb b/benchmark/dir_empty_p.rb new file mode 100644 index 0000000000..8329c757cf --- /dev/null +++ b/benchmark/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/erb_render.rb b/benchmark/erb_render.rb new file mode 100644 index 0000000000..7dc0816c43 --- /dev/null +++ b/benchmark/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/file_chmod.rb b/benchmark/file_chmod.rb new file mode 100644 index 0000000000..1cd4760c9d --- /dev/null +++ b/benchmark/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/file_rename.rb b/benchmark/file_rename.rb new file mode 100644 index 0000000000..bbb44aebac --- /dev/null +++ b/benchmark/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/hash_aref_dsym.rb b/benchmark/hash_aref_dsym.rb new file mode 100644 index 0000000000..af4f8c36d4 --- /dev/null +++ b/benchmark/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/hash_aref_dsym_long.rb b/benchmark/hash_aref_dsym_long.rb new file mode 100644 index 0000000000..9d7759379e --- /dev/null +++ b/benchmark/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/hash_aref_fix.rb b/benchmark/hash_aref_fix.rb new file mode 100644 index 0000000000..1346890582 --- /dev/null +++ b/benchmark/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/hash_aref_flo.rb b/benchmark/hash_aref_flo.rb new file mode 100644 index 0000000000..2217274c82 --- /dev/null +++ b/benchmark/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/hash_aref_miss.rb b/benchmark/hash_aref_miss.rb new file mode 100644 index 0000000000..b0913dd4bb --- /dev/null +++ b/benchmark/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/hash_aref_str.rb b/benchmark/hash_aref_str.rb new file mode 100644 index 0000000000..19439b061b --- /dev/null +++ b/benchmark/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/hash_aref_sym.rb b/benchmark/hash_aref_sym.rb new file mode 100644 index 0000000000..f75d163fe6 --- /dev/null +++ b/benchmark/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/hash_aref_sym_long.rb b/benchmark/hash_aref_sym_long.rb new file mode 100644 index 0000000000..9dab8df7be --- /dev/null +++ b/benchmark/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/hash_flatten.rb b/benchmark/hash_flatten.rb new file mode 100644 index 0000000000..e944aae9f2 --- /dev/null +++ b/benchmark/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/hash_ident_flo.rb b/benchmark/hash_ident_flo.rb new file mode 100644 index 0000000000..0c7edfed3e --- /dev/null +++ b/benchmark/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/hash_ident_num.rb b/benchmark/hash_ident_num.rb new file mode 100644 index 0000000000..b226736c6f --- /dev/null +++ b/benchmark/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/hash_ident_obj.rb b/benchmark/hash_ident_obj.rb new file mode 100644 index 0000000000..4b3b58edec --- /dev/null +++ b/benchmark/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/hash_ident_str.rb b/benchmark/hash_ident_str.rb new file mode 100644 index 0000000000..8582b38e31 --- /dev/null +++ b/benchmark/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/hash_ident_sym.rb b/benchmark/hash_ident_sym.rb new file mode 100644 index 0000000000..4c81e3d28e --- /dev/null +++ b/benchmark/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/hash_keys.rb b/benchmark/hash_keys.rb new file mode 100644 index 0000000000..6863cd01f9 --- /dev/null +++ b/benchmark/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/hash_long.rb b/benchmark/hash_long.rb new file mode 100644 index 0000000000..03d9109602 --- /dev/null +++ b/benchmark/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/hash_shift.rb b/benchmark/hash_shift.rb new file mode 100644 index 0000000000..a645671a5b --- /dev/null +++ b/benchmark/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/hash_shift_u16.rb b/benchmark/hash_shift_u16.rb new file mode 100644 index 0000000000..ec800d0342 --- /dev/null +++ b/benchmark/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/hash_shift_u24.rb b/benchmark/hash_shift_u24.rb new file mode 100644 index 0000000000..de4e0fa696 --- /dev/null +++ b/benchmark/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/hash_shift_u32.rb b/benchmark/hash_shift_u32.rb new file mode 100644 index 0000000000..656aa55583 --- /dev/null +++ b/benchmark/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/hash_small2.rb b/benchmark/hash_small2.rb new file mode 100644 index 0000000000..45485d9c71 --- /dev/null +++ b/benchmark/hash_small2.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a} diff --git a/benchmark/hash_small4.rb b/benchmark/hash_small4.rb new file mode 100644 index 0000000000..acd4084334 --- /dev/null +++ b/benchmark/hash_small4.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a} diff --git a/benchmark/hash_small8.rb b/benchmark/hash_small8.rb new file mode 100644 index 0000000000..9cffcc91b6 --- /dev/null +++ b/benchmark/hash_small8.rb @@ -0,0 +1 @@ +1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a} diff --git a/benchmark/hash_to_proc.rb b/benchmark/hash_to_proc.rb new file mode 100644 index 0000000000..2b675bf509 --- /dev/null +++ b/benchmark/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/hash_values.rb b/benchmark/hash_values.rb new file mode 100644 index 0000000000..069441302f --- /dev/null +++ b/benchmark/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/int_quo.rb b/benchmark/int_quo.rb new file mode 100644 index 0000000000..e22a3f8c30 --- /dev/null +++ b/benchmark/int_quo.rb @@ -0,0 +1 @@ +5000000.times { 42.quo(3) } diff --git a/benchmark/io_copy_stream_write.rb b/benchmark/io_copy_stream_write.rb new file mode 100644 index 0000000000..3fd87250a4 --- /dev/null +++ b/benchmark/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/io_copy_stream_write_socket.rb b/benchmark/io_copy_stream_write_socket.rb new file mode 100644 index 0000000000..11f369bd0d --- /dev/null +++ b/benchmark/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/io_file_create.rb b/benchmark/io_file_create.rb new file mode 100644 index 0000000000..2f205c1333 --- /dev/null +++ b/benchmark/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/io_file_read.rb b/benchmark/io_file_read.rb new file mode 100644 index 0000000000..b9e796ed30 --- /dev/null +++ b/benchmark/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/io_file_write.rb b/benchmark/io_file_write.rb new file mode 100644 index 0000000000..aa1be0e5fe --- /dev/null +++ b/benchmark/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/io_nonblock_noex.rb b/benchmark/io_nonblock_noex.rb new file mode 100644 index 0000000000..da9357fdc6 --- /dev/null +++ b/benchmark/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/io_nonblock_noex2.rb b/benchmark/io_nonblock_noex2.rb new file mode 100644 index 0000000000..56819d049b --- /dev/null +++ b/benchmark/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/io_pipe_rw.rb b/benchmark/io_pipe_rw.rb new file mode 100644 index 0000000000..6862a8ae61 --- /dev/null +++ b/benchmark/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/io_select.rb b/benchmark/io_select.rb new file mode 100644 index 0000000000..19248daeb1 --- /dev/null +++ b/benchmark/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/io_select2.rb b/benchmark/io_select2.rb new file mode 100644 index 0000000000..10e37d71b2 --- /dev/null +++ b/benchmark/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/io_select3.rb b/benchmark/io_select3.rb new file mode 100644 index 0000000000..7d0ba1f092 --- /dev/null +++ b/benchmark/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/loop_for.rb b/benchmark/loop_for.rb new file mode 100644 index 0000000000..0fc4cc1511 --- /dev/null +++ b/benchmark/loop_for.rb @@ -0,0 +1,3 @@ +for i in 1..30_000_000 + # +end diff --git a/benchmark/loop_generator.rb b/benchmark/loop_generator.rb new file mode 100644 index 0000000000..d3375c744c --- /dev/null +++ b/benchmark/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/loop_times.rb b/benchmark/loop_times.rb new file mode 100644 index 0000000000..521f72ad1a --- /dev/null +++ b/benchmark/loop_times.rb @@ -0,0 +1 @@ +30_000_000.times{|e|} diff --git a/benchmark/loop_whileloop.rb b/benchmark/loop_whileloop.rb new file mode 100644 index 0000000000..0072822c06 --- /dev/null +++ b/benchmark/loop_whileloop.rb @@ -0,0 +1,4 @@ +i = 0 +while i<30_000_000 # benchmark loop 1 + i += 1 +end diff --git a/benchmark/loop_whileloop2.rb b/benchmark/loop_whileloop2.rb new file mode 100644 index 0000000000..47d02dffc4 --- /dev/null +++ b/benchmark/loop_whileloop2.rb @@ -0,0 +1,4 @@ +i = 0 +while i< 6_000_000 # benchmark loop 2 + i += 1 +end diff --git a/benchmark/marshal_dump_flo.rb b/benchmark/marshal_dump_flo.rb new file mode 100644 index 0000000000..9b8d0c6afb --- /dev/null +++ b/benchmark/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/marshal_dump_load_geniv.rb b/benchmark/marshal_dump_load_geniv.rb new file mode 100644 index 0000000000..8252ad90fa --- /dev/null +++ b/benchmark/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/marshal_dump_load_time.rb b/benchmark/marshal_dump_load_time.rb new file mode 100644 index 0000000000..e29743b791 --- /dev/null +++ b/benchmark/marshal_dump_load_time.rb @@ -0,0 +1 @@ +100000.times { Marshal.load(Marshal.dump(Time.now)) } diff --git a/benchmark/securerandom.rb b/benchmark/securerandom.rb new file mode 100644 index 0000000000..a082ea6d5b --- /dev/null +++ b/benchmark/securerandom.rb @@ -0,0 +1,5 @@ +require "securerandom" + +20_0000.times do + SecureRandom.random_number(100) +end diff --git a/benchmark/so_ackermann.rb b/benchmark/so_ackermann.rb new file mode 100644 index 0000000000..7db5be9050 --- /dev/null +++ b/benchmark/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/so_array.rb b/benchmark/so_array.rb new file mode 100644 index 0000000000..2b8fce8f99 --- /dev/null +++ b/benchmark/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/so_binary_trees.rb b/benchmark/so_binary_trees.rb new file mode 100644 index 0000000000..b1693e4109 --- /dev/null +++ b/benchmark/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/so_concatenate.rb b/benchmark/so_concatenate.rb new file mode 100644 index 0000000000..873214de7c --- /dev/null +++ b/benchmark/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/so_exception.rb b/benchmark/so_exception.rb new file mode 100644 index 0000000000..deb003a594 --- /dev/null +++ b/benchmark/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/so_fannkuch.rb b/benchmark/so_fannkuch.rb new file mode 100644 index 0000000000..bac5ecd44c --- /dev/null +++ b/benchmark/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/so_fasta.rb b/benchmark/so_fasta.rb new file mode 100644 index 0000000000..dcc6b39507 --- /dev/null +++ b/benchmark/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/so_lists.rb b/benchmark/so_lists.rb new file mode 100644 index 0000000000..e8f4a2a5f7 --- /dev/null +++ b/benchmark/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/so_matrix.rb b/benchmark/so_matrix.rb new file mode 100644 index 0000000000..e2c5c8e559 --- /dev/null +++ b/benchmark/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/so_meteor_contest.rb b/benchmark/so_meteor_contest.rb new file mode 100644 index 0000000000..8c136baa6c --- /dev/null +++ b/benchmark/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/so_nbody.rb b/benchmark/so_nbody.rb new file mode 100644 index 0000000000..d6c5bb9e61 --- /dev/null +++ b/benchmark/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/so_nested_loop.rb b/benchmark/so_nested_loop.rb new file mode 100644 index 0000000000..a0513f8c47 --- /dev/null +++ b/benchmark/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/so_nsieve.rb b/benchmark/so_nsieve.rb new file mode 100644 index 0000000000..a65cc78233 --- /dev/null +++ b/benchmark/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/so_nsieve_bits.rb b/benchmark/so_nsieve_bits.rb new file mode 100644 index 0000000000..6f958ee44e --- /dev/null +++ b/benchmark/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/so_object.rb b/benchmark/so_object.rb new file mode 100644 index 0000000000..e8607c7199 --- /dev/null +++ b/benchmark/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/so_partial_sums.rb b/benchmark/so_partial_sums.rb new file mode 100644 index 0000000000..630b45cb8d --- /dev/null +++ b/benchmark/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/so_pidigits.rb b/benchmark/so_pidigits.rb new file mode 100644 index 0000000000..9a537b2d1c --- /dev/null +++ b/benchmark/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/so_random.rb b/benchmark/so_random.rb new file mode 100644 index 0000000000..a66b9e8e63 --- /dev/null +++ b/benchmark/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/vm3_gc_old_full.rb b/benchmark/vm3_gc_old_full.rb new file mode 100644 index 0000000000..cfdfc8c5a5 --- /dev/null +++ b/benchmark/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/vm3_gc_old_immediate.rb b/benchmark/vm3_gc_old_immediate.rb new file mode 100644 index 0000000000..ad22feb655 --- /dev/null +++ b/benchmark/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/vm3_gc_old_lazy.rb b/benchmark/vm3_gc_old_lazy.rb new file mode 100644 index 0000000000..b74d44baf1 --- /dev/null +++ b/benchmark/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/vm_symbol_block_pass.rb b/benchmark/vm_symbol_block_pass.rb new file mode 100644 index 0000000000..1d433353e1 --- /dev/null +++ b/benchmark/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/vm_thread_alive_check1.rb b/benchmark/vm_thread_alive_check1.rb new file mode 100644 index 0000000000..c993accdda --- /dev/null +++ b/benchmark/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/vm_thread_close.rb b/benchmark/vm_thread_close.rb new file mode 100644 index 0000000000..3e9a265ce8 --- /dev/null +++ b/benchmark/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/vm_thread_condvar1.rb b/benchmark/vm_thread_condvar1.rb new file mode 100644 index 0000000000..cf5706b23e --- /dev/null +++ b/benchmark/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/vm_thread_condvar2.rb b/benchmark/vm_thread_condvar2.rb new file mode 100644 index 0000000000..7c8dc19481 --- /dev/null +++ b/benchmark/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/vm_thread_create_join.rb b/benchmark/vm_thread_create_join.rb new file mode 100644 index 0000000000..393cd45df9 --- /dev/null +++ b/benchmark/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/vm_thread_mutex1.rb b/benchmark/vm_thread_mutex1.rb new file mode 100644 index 0000000000..66e42c85e1 --- /dev/null +++ b/benchmark/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/vm_thread_sized_queue2.rb b/benchmark/vm_thread_sized_queue2.rb new file mode 100644 index 0000000000..de9f55e978 --- /dev/null +++ b/benchmark/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/vm_thread_sized_queue3.rb b/benchmark/vm_thread_sized_queue3.rb new file mode 100644 index 0000000000..ce5f1796d8 --- /dev/null +++ b/benchmark/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/vm_thread_sized_queue4.rb b/benchmark/vm_thread_sized_queue4.rb new file mode 100644 index 0000000000..a9b7d80ec0 --- /dev/null +++ b/benchmark/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) -- cgit v1.2.3