summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-10 13:05:29 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-10 13:05:29 +0000
commit8068d34cfe4f74784cba29e981e2d8437ff02a9f (patch)
tree85b1f81c676f3fecdf3c425a94f341f63797eec4 /benchmark
parentbd12037e50a216bda5896676b678bafee5eacb49 (diff)
Revert "benchmark/*.yml: convert from benchmark/bm_*.rb"
This reverts r63900. Having single-execution benchmark as a normal Ruby script is preferred by ko1. I'm not a big fan of having inconsistent benchmark formats, but I can understand some benefits of it. common.mk: remove obsolsted benchmark-each PHONY declaration, support running Ruby scripts added by this commit. README.md: follow ARGS change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/README.md4
-rw-r--r--benchmark/app_answer.yml18
-rw-r--r--benchmark/app_aobench.yml295
-rw-r--r--benchmark/app_erb.yml28
-rw-r--r--benchmark/app_factorial.yml14
-rw-r--r--benchmark/app_fib.yml12
-rw-r--r--benchmark/app_lc_fizzbuzz.yml55
-rw-r--r--benchmark/app_mandelbrot.yml25
-rw-r--r--benchmark/app_pentomino.yml130
-rw-r--r--benchmark/app_raise.yml11
-rw-r--r--benchmark/app_strconcat.yml8
-rw-r--r--benchmark/app_tak.yml15
-rw-r--r--benchmark/app_tarai.yml13
-rw-r--r--benchmark/app_uri.yml11
-rw-r--r--benchmark/array_sample_100k_10.yml5
-rw-r--r--benchmark/array_sample_100k_11.yml5
-rw-r--r--benchmark/array_sample_100k__100.yml5
-rw-r--r--benchmark/array_sample_100k__1k.yml5
-rw-r--r--benchmark/array_sample_100k__6k.yml5
-rw-r--r--benchmark/array_sample_100k___10k.yml5
-rw-r--r--benchmark/array_sample_100k___50k.yml5
-rw-r--r--benchmark/array_shift.yml17
-rw-r--r--benchmark/array_small_and.yml20
-rw-r--r--benchmark/array_small_diff.yml20
-rw-r--r--benchmark/array_small_or.yml20
-rw-r--r--benchmark/array_sort_block.yml5
-rw-r--r--benchmark/array_sort_float.yml5
-rw-r--r--benchmark/array_values_at_int.yml5
-rw-r--r--benchmark/array_values_at_range.yml5
-rw-r--r--benchmark/bighash.yml4
-rw-r--r--benchmark/bm_app_answer.rb15
-rw-r--r--benchmark/bm_app_aobench.rb291
-rw-r--r--benchmark/bm_app_erb.rb25
-rw-r--r--benchmark/bm_app_factorial.rb11
-rw-r--r--benchmark/bm_app_fib.rb10
-rw-r--r--benchmark/bm_app_lc_fizzbuzz.rb52
-rw-r--r--benchmark/bm_app_mandelbrot.rb23
-rw-r--r--benchmark/bm_app_pentomino.rb130
-rw-r--r--benchmark/bm_app_raise.rb8
-rw-r--r--benchmark/bm_app_strconcat.rb5
-rw-r--r--benchmark/bm_app_tak.rb13
-rw-r--r--benchmark/bm_app_tarai.rb10
-rw-r--r--benchmark/bm_app_uri.rb8
-rw-r--r--benchmark/bm_array_sample_100k_10.rb2
-rw-r--r--benchmark/bm_array_sample_100k_11.rb2
-rw-r--r--benchmark/bm_array_sample_100k__100.rb2
-rw-r--r--benchmark/bm_array_sample_100k__1k.rb2
-rw-r--r--benchmark/bm_array_sample_100k__6k.rb2
-rw-r--r--benchmark/bm_array_sample_100k___10k.rb2
-rw-r--r--benchmark/bm_array_sample_100k___50k.rb2
-rw-r--r--benchmark/bm_array_shift.rb14
-rw-r--r--benchmark/bm_array_small_and.rb17
-rw-r--r--benchmark/bm_array_small_diff.rb17
-rw-r--r--benchmark/bm_array_small_or.rb17
-rw-r--r--benchmark/bm_array_sort_block.rb2
-rw-r--r--benchmark/bm_array_sort_float.rb2
-rw-r--r--benchmark/bm_array_values_at_int.rb2
-rw-r--r--benchmark/bm_array_values_at_range.rb2
-rw-r--r--benchmark/bm_bighash.rb1
-rw-r--r--benchmark/bm_dir_empty_p.rb5
-rw-r--r--benchmark/bm_erb_render.rb25
-rw-r--r--benchmark/bm_file_chmod.rb9
-rw-r--r--benchmark/bm_file_rename.rb11
-rw-r--r--benchmark/bm_hash_aref_dsym.rb4
-rw-r--r--benchmark/bm_hash_aref_dsym_long.rb21
-rw-r--r--benchmark/bm_hash_aref_fix.rb4
-rw-r--r--benchmark/bm_hash_aref_flo.rb4
-rw-r--r--benchmark/bm_hash_aref_miss.rb5
-rw-r--r--benchmark/bm_hash_aref_str.rb4
-rw-r--r--benchmark/bm_hash_aref_sym.rb9
-rw-r--r--benchmark/bm_hash_aref_sym_long.rb13
-rw-r--r--benchmark/bm_hash_flatten.rb9
-rw-r--r--benchmark/bm_hash_ident_flo.rb4
-rw-r--r--benchmark/bm_hash_ident_num.rb4
-rw-r--r--benchmark/bm_hash_ident_obj.rb4
-rw-r--r--benchmark/bm_hash_ident_str.rb4
-rw-r--r--benchmark/bm_hash_ident_sym.rb4
-rw-r--r--benchmark/bm_hash_keys.rb9
-rw-r--r--benchmark/bm_hash_long.rb4
-rw-r--r--benchmark/bm_hash_shift.rb10
-rw-r--r--benchmark/bm_hash_shift_u16.rb10
-rw-r--r--benchmark/bm_hash_shift_u24.rb10
-rw-r--r--benchmark/bm_hash_shift_u32.rb10
-rw-r--r--benchmark/bm_hash_small2.rb1
-rw-r--r--benchmark/bm_hash_small4.rb1
-rw-r--r--benchmark/bm_hash_small8.rb1
-rw-r--r--benchmark/bm_hash_to_proc.rb9
-rw-r--r--benchmark/bm_hash_values.rb9
-rw-r--r--benchmark/bm_int_quo.rb1
-rw-r--r--benchmark/bm_io_copy_stream_write.rb24
-rw-r--r--benchmark/bm_io_copy_stream_write_socket.rb35
-rw-r--r--benchmark/bm_io_file_create.rb13
-rw-r--r--benchmark/bm_io_file_read.rb15
-rw-r--r--benchmark/bm_io_file_write.rb14
-rw-r--r--benchmark/bm_io_nonblock_noex.rb22
-rw-r--r--benchmark/bm_io_nonblock_noex2.rb21
-rw-r--r--benchmark/bm_io_pipe_rw.rb13
-rw-r--r--benchmark/bm_io_select.rb9
-rw-r--r--benchmark/bm_io_select2.rb22
-rw-r--r--benchmark/bm_io_select3.rb21
-rw-r--r--benchmark/bm_loop_for.rb3
-rw-r--r--benchmark/bm_loop_generator.rb14
-rw-r--r--benchmark/bm_loop_times.rb1
-rw-r--r--benchmark/bm_loop_whileloop.rb4
-rw-r--r--benchmark/bm_loop_whileloop2.rb4
-rw-r--r--benchmark/bm_marshal_dump_flo.rb2
-rw-r--r--benchmark/bm_marshal_dump_load_geniv.rb10
-rw-r--r--benchmark/bm_marshal_dump_load_time.rb1
-rw-r--r--benchmark/bm_securerandom.rb5
-rw-r--r--benchmark/bm_so_ackermann.rb19
-rw-r--r--benchmark/bm_so_array.rb23
-rw-r--r--benchmark/bm_so_binary_trees.rb62
-rw-r--r--benchmark/bm_so_concatenate.rb18
-rw-r--r--benchmark/bm_so_exception.rb61
-rw-r--r--benchmark/bm_so_fannkuch.rb45
-rw-r--r--benchmark/bm_so_fasta.rb81
-rw-r--r--benchmark/bm_so_lists.rb47
-rw-r--r--benchmark/bm_so_mandelbrot.rb57
-rw-r--r--benchmark/bm_so_matrix.rb48
-rwxr-xr-xbenchmark/bm_so_meteor_contest.rb563
-rw-r--r--benchmark/bm_so_nbody.rb148
-rw-r--r--benchmark/bm_so_nested_loop.rb24
-rw-r--r--benchmark/bm_so_nsieve.rb35
-rw-r--r--benchmark/bm_so_nsieve_bits.rb43
-rw-r--r--benchmark/bm_so_object.rb56
-rw-r--r--benchmark/bm_so_partial_sums.rb31
-rw-r--r--benchmark/bm_so_pidigits.rb92
-rw-r--r--benchmark/bm_so_random.rb20
-rw-r--r--benchmark/bm_so_sieve.rb24
-rw-r--r--benchmark/bm_so_spectralnorm.rb50
-rw-r--r--benchmark/bm_string_index.rb3
-rw-r--r--benchmark/bm_string_scan_re.rb2
-rw-r--r--benchmark/bm_string_scan_str.rb2
-rw-r--r--benchmark/bm_time_subsec.rb2
-rw-r--r--benchmark/bm_vm3_backtrace.rb22
-rw-r--r--benchmark/bm_vm3_clearmethodcache.rb8
-rw-r--r--benchmark/bm_vm3_gc.rb6
-rw-r--r--benchmark/bm_vm3_gc_old_full.rb4
-rw-r--r--benchmark/bm_vm3_gc_old_immediate.rb4
-rw-r--r--benchmark/bm_vm3_gc_old_lazy.rb4
-rw-r--r--benchmark/bm_vm_symbol_block_pass.rb13
-rw-r--r--benchmark/bm_vm_thread_alive_check1.rb6
-rw-r--r--benchmark/bm_vm_thread_close.rb6
-rw-r--r--benchmark/bm_vm_thread_condvar1.rb28
-rw-r--r--benchmark/bm_vm_thread_condvar2.rb35
-rw-r--r--benchmark/bm_vm_thread_create_join.rb6
-rw-r--r--benchmark/bm_vm_thread_mutex1.rb21
-rw-r--r--benchmark/bm_vm_thread_mutex2.rb21
-rw-r--r--benchmark/bm_vm_thread_mutex3.rb20
-rw-r--r--benchmark/bm_vm_thread_pass.rb15
-rw-r--r--benchmark/bm_vm_thread_pass_flood.rb10
-rw-r--r--benchmark/bm_vm_thread_pipe.rb17
-rw-r--r--benchmark/bm_vm_thread_queue.rb18
-rw-r--r--benchmark/bm_vm_thread_sized_queue.rb20
-rw-r--r--benchmark/bm_vm_thread_sized_queue2.rb23
-rw-r--r--benchmark/bm_vm_thread_sized_queue3.rb22
-rw-r--r--benchmark/bm_vm_thread_sized_queue4.rb26
-rw-r--r--benchmark/dir_empty_p.yml8
-rw-r--r--benchmark/erb_render.yml28
-rw-r--r--benchmark/file_chmod.yml13
-rw-r--r--benchmark/file_rename.yml15
-rw-r--r--benchmark/hash_aref_dsym.yml7
-rw-r--r--benchmark/hash_aref_dsym_long.yml25
-rw-r--r--benchmark/hash_aref_fix.yml7
-rw-r--r--benchmark/hash_aref_flo.yml7
-rw-r--r--benchmark/hash_aref_miss.yml8
-rw-r--r--benchmark/hash_aref_str.yml7
-rw-r--r--benchmark/hash_aref_sym.yml12
-rw-r--r--benchmark/hash_aref_sym_long.yml16
-rw-r--r--benchmark/hash_flatten.yml12
-rw-r--r--benchmark/hash_ident_flo.yml7
-rw-r--r--benchmark/hash_ident_num.yml7
-rw-r--r--benchmark/hash_ident_obj.yml7
-rw-r--r--benchmark/hash_ident_str.yml7
-rw-r--r--benchmark/hash_ident_sym.yml7
-rw-r--r--benchmark/hash_keys.yml12
-rw-r--r--benchmark/hash_long.yml7
-rw-r--r--benchmark/hash_shift.yml13
-rw-r--r--benchmark/hash_shift_u16.yml13
-rw-r--r--benchmark/hash_shift_u24.yml13
-rw-r--r--benchmark/hash_shift_u32.yml13
-rw-r--r--benchmark/hash_small2.yml4
-rw-r--r--benchmark/hash_small4.yml4
-rw-r--r--benchmark/hash_small8.yml4
-rw-r--r--benchmark/hash_to_proc.yml12
-rw-r--r--benchmark/hash_values.yml12
-rw-r--r--benchmark/int_quo.yml4
-rw-r--r--benchmark/io_copy_stream_write.yml28
-rw-r--r--benchmark/io_copy_stream_write_socket.yml39
-rw-r--r--benchmark/io_file_create.yml15
-rw-r--r--benchmark/io_file_read.yml18
-rw-r--r--benchmark/io_file_write.yml17
-rw-r--r--benchmark/io_nonblock_noex.yml25
-rw-r--r--benchmark/io_nonblock_noex2.yml24
-rw-r--r--benchmark/io_pipe_rw.yml17
-rw-r--r--benchmark/io_select.yml12
-rw-r--r--benchmark/io_select2.yml25
-rw-r--r--benchmark/io_select3.yml24
-rw-r--r--benchmark/loop_for.yml6
-rw-r--r--benchmark/loop_generator.yml17
-rw-r--r--benchmark/loop_times.yml4
-rw-r--r--benchmark/loop_whileloop.yml7
-rw-r--r--benchmark/loop_whileloop2.yml7
-rw-r--r--benchmark/marshal_dump_flo.yml5
-rw-r--r--benchmark/marshal_dump_load_geniv.yml13
-rw-r--r--benchmark/marshal_dump_load_time.yml4
-rw-r--r--benchmark/securerandom.yml8
-rw-r--r--benchmark/so_ackermann.yml21
-rw-r--r--benchmark/so_array.yml25
-rw-r--r--benchmark/so_binary_trees.yml66
-rw-r--r--benchmark/so_concatenate.yml20
-rw-r--r--benchmark/so_exception.yml65
-rw-r--r--benchmark/so_fannkuch.yml48
-rw-r--r--benchmark/so_fasta.yml84
-rw-r--r--benchmark/so_lists.yml51
-rw-r--r--benchmark/so_mandelbrot.yml61
-rw-r--r--benchmark/so_matrix.yml50
-rw-r--r--benchmark/so_meteor_contest.yml567
-rw-r--r--benchmark/so_nbody.yml152
-rw-r--r--benchmark/so_nested_loop.yml26
-rw-r--r--benchmark/so_nsieve.yml39
-rw-r--r--benchmark/so_nsieve_bits.yml46
-rw-r--r--benchmark/so_object.yml59
-rw-r--r--benchmark/so_partial_sums.yml34
-rw-r--r--benchmark/so_pidigits.yml95
-rw-r--r--benchmark/so_random.yml24
-rw-r--r--benchmark/so_sieve.yml28
-rw-r--r--benchmark/so_spectralnorm.yml54
-rw-r--r--benchmark/string_index.yml6
-rw-r--r--benchmark/string_scan_re.yml5
-rw-r--r--benchmark/string_scan_str.yml5
-rw-r--r--benchmark/time_subsec.yml5
-rw-r--r--benchmark/vm3_backtrace.yml26
-rw-r--r--benchmark/vm3_clearmethodcache.yml11
-rw-r--r--benchmark/vm3_gc.yml9
-rw-r--r--benchmark/vm3_gc_old_full.yml7
-rw-r--r--benchmark/vm3_gc_old_immediate.yml7
-rw-r--r--benchmark/vm3_gc_old_lazy.yml7
-rw-r--r--benchmark/vm_symbol_block_pass.yml16
-rw-r--r--benchmark/vm_thread_alive_check1.yml9
-rw-r--r--benchmark/vm_thread_close.yml9
-rw-r--r--benchmark/vm_thread_condvar1.yml32
-rw-r--r--benchmark/vm_thread_condvar2.yml39
-rw-r--r--benchmark/vm_thread_create_join.yml9
-rw-r--r--benchmark/vm_thread_mutex1.yml25
-rw-r--r--benchmark/vm_thread_mutex2.yml25
-rw-r--r--benchmark/vm_thread_mutex3.yml24
-rw-r--r--benchmark/vm_thread_pass.yml17
-rw-r--r--benchmark/vm_thread_pass_flood.yml14
-rw-r--r--benchmark/vm_thread_pipe.yml20
-rw-r--r--benchmark/vm_thread_queue.yml21
-rw-r--r--benchmark/vm_thread_sized_queue.yml23
-rw-r--r--benchmark/vm_thread_sized_queue2.yml26
-rw-r--r--benchmark/vm_thread_sized_queue3.yml25
-rw-r--r--benchmark/vm_thread_sized_queue4.yml29
255 files changed, 3073 insertions, 3465 deletions
diff --git a/benchmark/README.md b/benchmark/README.md
index 013de7904c..018198b4b5 100644
--- a/benchmark/README.md
+++ b/benchmark/README.md
@@ -37,8 +37,8 @@ make benchmark ITEM=vm1
# Run some limited benchmarks in ITEM-matched files
make benchmark ITEM=vm1 OPTS=--filter=block
-# You can specify the benchmark by an exact filename instead of using
-# the default argument: ARGS=$(srcdir)/benchmark/*$(ITEM)*.yml
+# You can specify the benchmark by an exact filename instead of using the default argument:
+# ARGS = $$(find $(srcdir)/benchmark -maxdepth 1 -name '*$(ITEM)*.yml' -o -name '*$(ITEM)*.rb')
make benchmark ARGS=../benchmark/erb_render.yml
# You can specify any option via $OPTS
diff --git a/benchmark/app_answer.yml b/benchmark/app_answer.yml
deleted file mode 100644
index ad6bf3be16..0000000000
--- a/benchmark/app_answer.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-benchmark:
- app_answer: |
- def ack(m, n)
- if m == 0 then
- n + 1
- elsif n == 0 then
- ack(m - 1, 1)
- else
- ack(m - 1, ack(m, n - 1))
- end
- end
-
- def the_answer_to_life_the_universe_and_everything
- (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i
- end
-
- answer = the_answer_to_life_the_universe_and_everything
-loop_count: 1
diff --git a/benchmark/app_aobench.yml b/benchmark/app_aobench.yml
deleted file mode 100644
index 5479d0a421..0000000000
--- a/benchmark/app_aobench.yml
+++ /dev/null
@@ -1,295 +0,0 @@
-prelude: |
- # AO render benchmark
- # Original program (C) Syoyo Fujita in Javascript (and other languages)
- # https://code.google.com/p/aobench/
- # Ruby(yarv2llvm) version by Hideki Miura
-benchmark:
- app_aobench: |
- #
-
- IMAGE_WIDTH = 256
- IMAGE_HEIGHT = 256
- NSUBSAMPLES = 2
- NAO_SAMPLES = 8
-
- class Vec
- def initialize(x, y, z)
- @x = x
- @y = y
- @z = z
- end
-
- attr_accessor :x, :y, :z
-
- def vadd(b)
- Vec.new(@x + b.x, @y + b.y, @z + b.z)
- end
-
- def vsub(b)
- Vec.new(@x - b.x, @y - b.y, @z - b.z)
- end
-
- def vcross(b)
- Vec.new(@y * b.z - @z * b.y,
- @z * b.x - @x * b.z,
- @x * b.y - @y * b.x)
- end
-
- def vdot(b)
- @x * b.x + @y * b.y + @z * b.z
- end
-
- def vlength
- Math.sqrt(@x * @x + @y * @y + @z * @z)
- end
-
- def vnormalize
- len = vlength
- v = Vec.new(@x, @y, @z)
- if len > 1.0e-17 then
- v.x = v.x / len
- v.y = v.y / len
- v.z = v.z / len
- end
- v
- end
- end
-
-
- class Sphere
- def initialize(center, radius)
- @center = center
- @radius = radius
- end
-
- attr_reader :center, :radius
-
- def intersect(ray, isect)
- rs = ray.org.vsub(@center)
- b = rs.vdot(ray.dir)
- c = rs.vdot(rs) - (@radius * @radius)
- d = b * b - c
- if d > 0.0 then
- t = - b - Math.sqrt(d)
-
- if t > 0.0 and t < isect.t then
- isect.t = t
- isect.hit = true
- isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
- ray.org.y + ray.dir.y * t,
- ray.org.z + ray.dir.z * t)
- n = isect.pl.vsub(@center)
- isect.n = n.vnormalize
- else
- 0.0
- end
- end
- nil
- end
- end
-
- class Plane
- def initialize(p, n)
- @p = p
- @n = n
- end
-
- def intersect(ray, isect)
- d = -@p.vdot(@n)
- v = ray.dir.vdot(@n)
- v0 = v
- if v < 0.0 then
- v0 = -v
- end
- if v0 < 1.0e-17 then
- return
- end
-
- t = -(ray.org.vdot(@n) + d) / v
-
- if t > 0.0 and t < isect.t then
- isect.hit = true
- isect.t = t
- isect.n = @n
- isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
- ray.org.y + t * ray.dir.y,
- ray.org.z + t * ray.dir.z)
- end
- nil
- end
- end
-
- class Ray
- def initialize(org, dir)
- @org = org
- @dir = dir
- end
-
- attr_accessor :org, :dir
- end
-
- class Isect
- def initialize
- @t = 10000000.0
- @hit = false
- @pl = Vec.new(0.0, 0.0, 0.0)
- @n = Vec.new(0.0, 0.0, 0.0)
- end
-
- attr_accessor :t, :hit, :pl, :n
- end
-
- def clamp(f)
- i = f * 255.5
- if i > 255.0 then
- i = 255.0
- end
- if i < 0.0 then
- i = 0.0
- end
- i.to_i
- end
-
- def otherBasis(basis, n)
- basis[2] = Vec.new(n.x, n.y, n.z)
- basis[1] = Vec.new(0.0, 0.0, 0.0)
-
- if n.x < 0.6 and n.x > -0.6 then
- basis[1].x = 1.0
- elsif n.y < 0.6 and n.y > -0.6 then
- basis[1].y = 1.0
- elsif n.z < 0.6 and n.z > -0.6 then
- basis[1].z = 1.0
- else
- basis[1].x = 1.0
- end
-
- basis[0] = basis[1].vcross(basis[2])
- basis[0] = basis[0].vnormalize
-
- basis[1] = basis[2].vcross(basis[0])
- basis[1] = basis[1].vnormalize
- end
-
- class Scene
- def initialize
- @spheres = Array.new
- @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
- @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
- @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5)
- @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
- end
-
- def ambient_occlusion(isect)
- basis = Array.new
- otherBasis(basis, isect.n)
-
- ntheta = NAO_SAMPLES
- nphi = NAO_SAMPLES
- eps = 0.0001
- occlusion = 0.0
-
- p0 = Vec.new(isect.pl.x + eps * isect.n.x,
- isect.pl.y + eps * isect.n.y,
- isect.pl.z + eps * isect.n.z)
- nphi.times do |j|
- ntheta.times do |i|
- r = rand
- phi = 2.0 * 3.14159265 * rand
- x = Math.cos(phi) * Math.sqrt(1.0 - r)
- y = Math.sin(phi) * Math.sqrt(1.0 - r)
- z = Math.sqrt(r)
-
- rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
- ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
- rz = x * basis[0].z + y * basis[1].z + z * basis[2].z
-
- raydir = Vec.new(rx, ry, rz)
- ray = Ray.new(p0, raydir)
-
- occisect = Isect.new
- @spheres[0].intersect(ray, occisect)
- @spheres[1].intersect(ray, occisect)
- @spheres[2].intersect(ray, occisect)
- @plane.intersect(ray, occisect)
- if occisect.hit then
- occlusion = occlusion + 1.0
- else
- 0.0
- end
- end
- end
-
- occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)
-
- Vec.new(occlusion, occlusion, occlusion)
- end
-
- def render(w, h, nsubsamples)
- cnt = 0
- nsf = nsubsamples.to_f
- h.times do |y|
- w.times do |x|
- rad = Vec.new(0.0, 0.0, 0.0)
-
- # Subsampling
- nsubsamples.times do |v|
- nsubsamples.times do |u|
-
- cnt = cnt + 1
- wf = w.to_f
- hf = h.to_f
- xf = x.to_f
- yf = y.to_f
- uf = u.to_f
- vf = v.to_f
-
- px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
- py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
-
- eye = Vec.new(px, py, -1.0).vnormalize
-
- ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
-
- isect = Isect.new
- @spheres[0].intersect(ray, isect)
- @spheres[1].intersect(ray, isect)
- @spheres[2].intersect(ray, isect)
- @plane.intersect(ray, isect)
- if isect.hit then
- col = ambient_occlusion(isect)
- rad.x = rad.x + col.x
- rad.y = rad.y + col.y
- rad.z = rad.z + col.z
- end
- end
- end
-
- r = rad.x / (nsf * nsf)
- g = rad.y / (nsf * nsf)
- b = rad.z / (nsf * nsf)
- printf("%c", clamp(r))
- printf("%c", clamp(g))
- printf("%c", clamp(b))
- end
- nil
- end
-
- nil
- end
- end
-
- alias printf_orig printf
- def printf *args
- end
-
- # File.open("ao.ppm", "w") do |fp|
- printf("P6\n")
- printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
- printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
- Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
- # end
-
- undef printf
- alias printf printf_orig
-loop_count: 1
diff --git a/benchmark/app_erb.yml b/benchmark/app_erb.yml
deleted file mode 100644
index df0630585f..0000000000
--- a/benchmark/app_erb.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-benchmark:
- app_erb: |
- #
- # Create many HTML strings with ERB.
- #
-
- require 'erb'
-
- data = <<erb
- <html>
- <head> <%= title %> </head>
- <body>
- <h1> <%= title %> </h1>
- <p>
- <%= content %>
- </p>
- </body>
- </html>
- erb
-
- max = 15_000
- title = "hello world!"
- content = "hello world!\n" * 10
-
- max.times{
- ERB.new(data).result(binding)
- }
-loop_count: 1
diff --git a/benchmark/app_factorial.yml b/benchmark/app_factorial.yml
deleted file mode 100644
index 9db58e1a3c..0000000000
--- a/benchmark/app_factorial.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-benchmark:
- app_factorial: |
- def fact(n)
- if(n > 1)
- n * fact(n-1)
- else
- 1
- end
- end
-
- 100.times {
- fact(5000)
- }
-loop_count: 1
diff --git a/benchmark/app_fib.yml b/benchmark/app_fib.yml
deleted file mode 100644
index d1c6671e9d..0000000000
--- a/benchmark/app_fib.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- app_fib: |
- def fib n
- if n < 3
- 1
- else
- fib(n-1) + fib(n-2)
- end
- end
-
- fib(34)
-loop_count: 1
diff --git a/benchmark/app_lc_fizzbuzz.yml b/benchmark/app_lc_fizzbuzz.yml
deleted file mode 100644
index e17024c87b..0000000000
--- a/benchmark/app_lc_fizzbuzz.yml
+++ /dev/null
@@ -1,55 +0,0 @@
-benchmark:
- app_lc_fizzbuzz: |
- #
- # FizzBuzz program using only lambda calculus
- #
- # This program is quoted from
- # "Understanding Computation" by Tom Stuart
- # http://computationbook.com/
- #
- # You can understand why this program works fine by reading this book.
- #
-
- solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }]
-
- FIRST = -> l { LEFT[RIGHT[l]] }
- IF = -> b { b }
- LEFT = -> p { p[-> x { -> y { x } } ] }
- RIGHT = -> p { p[-> x { -> y { y } } ] }
- IS_EMPTY = LEFT
- REST = -> l { RIGHT[RIGHT[l]] }
-
- def to_integer(proc)
- proc[-> n { n + 1 }][0]
- end
-
- def to_boolean(proc)
- IF[proc][true][false]
- end
-
- def to_array(proc)
- array = []
-
- until to_boolean(IS_EMPTY[proc])
- array.push(FIRST[proc])
- proc = REST[proc]
- end
-
- array
- end
-
- def to_char(c)
- '0123456789BFiuz'.slice(to_integer(c))
- end
-
- def to_string(s)
- to_array(s).map { |c| to_char(c) }.join
- end
-
- answer = to_array(solution).map do |p|
- to_string(p)
- end
-
- answer_ary = answer.to_a
- # puts answer_ary
-loop_count: 1
diff --git a/benchmark/app_mandelbrot.yml b/benchmark/app_mandelbrot.yml
deleted file mode 100644
index d0ec9db010..0000000000
--- a/benchmark/app_mandelbrot.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-benchmark:
- app_mandelbrot: |
- require 'complex'
-
- def mandelbrot? z
- i = 0
- while i<100
- i += 1
- z = z * z
- return false if z.abs > 2
- end
- true
- end
-
- ary = []
-
- (0..1000).each{|dx|
- (0..1000).each{|dy|
- x = dx / 50.0
- y = dy / 50.0
- c = Complex(x, y)
- ary << c if mandelbrot?(c)
- }
- }
-loop_count: 1
diff --git a/benchmark/app_pentomino.yml b/benchmark/app_pentomino.yml
deleted file mode 100644
index ab6e19bf1a..0000000000
--- a/benchmark/app_pentomino.yml
+++ /dev/null
@@ -1,130 +0,0 @@
-benchmark:
- app_pentomino: |
- # This program is contributed by Shin Nishiyama
- # modified by K.Sasada
-
- NP = 5
- ROW = 8 + NP
- COL = 8
-
- $p = []
- $b = []
- $no = 0
-
- def piece(n, a, nb)
- nb.each{|x|
- a[n] = x
- if n == NP-1
- $p << [a.sort]
- else
- nbc=nb.dup
- [-ROW, -1, 1, ROW].each{|d|
- if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
- nbc << x+d
- end
- }
- nbc.delete x
- piece(n+1,a[0..n],nbc)
- end
- }
- end
-
- def kikaku(a)
- a.collect {|x| x - a[0]}
- end
- def ud(a)
- kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
- end
- def rl(a)
- kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
- end
- def xy(a)
- kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
- end
-
- def mkpieces
- piece(0,[],[0])
- $p.each do |a|
- a0 = a[0]
- a[1] = ud(a0)
- a[2] = rl(a0)
- a[3] = ud(rl(a0))
- a[4] = xy(a0)
- a[5] = ud(xy(a0))
- a[6] = rl(xy(a0))
- a[7] = ud(rl(xy(a0)))
- a.sort!
- a.uniq!
- end
- $p.uniq!.sort! {|x,y| x[0] <=> y[0] }
- end
-
- def mkboard
- (0...ROW*COL).each{|i|
- if i % ROW >= ROW-NP
- $b[i] = -2
- else
- $b[i] = -1
- end
- $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
- }
- end
-
- def pboard
- return # skip print
- print "No. #$no\n"
- (0...COL).each{|i|
- print "|"
- (0...ROW-NP).each{|j|
- x = $b[i*ROW+j]
- if x < 0
- print "..|"
- else
- printf "%2d|",x+1
- end
- }
- print "\n"
- }
- print "\n"
- end
-
- $pnum=[]
- def setpiece(a,pos)
- if a.length == $p.length then
- $no += 1
- pboard
- return
- end
- while $b[pos] != -1
- pos += 1
- end
- ($pnum - a).each do |i|
- $p[i].each do |x|
- f = 0
- x.each{|s|
- if $b[pos+s] != -1
- f=1
- break
- end
- }
- if f == 0 then
- x.each{|s|
- $b[pos+s] = i
- }
- a << i
- setpiece(a.dup, pos)
- a.pop
- x.each{|s|
- $b[pos+s] = -1
- }
- end
- end
- end
- end
-
- mkpieces
- mkboard
- $p[4] = [$p[4][0]]
- $pnum = (0...$p.length).to_a
- setpiece([],0)
-loop_count: 1
diff --git a/benchmark/app_raise.yml b/benchmark/app_raise.yml
deleted file mode 100644
index 3b7826c34f..0000000000
--- a/benchmark/app_raise.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-benchmark:
- app_raise: |
- i = 0
- while i<300000
- i += 1
- begin
- raise
- rescue
- end
- end
-loop_count: 1
diff --git a/benchmark/app_strconcat.yml b/benchmark/app_strconcat.yml
deleted file mode 100644
index 2762bf4aa2..0000000000
--- a/benchmark/app_strconcat.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-benchmark:
- app_strconcat: |
- i = 0
- while i<2_000_000
- "#{1+1} #{1+1} #{1+1}"
- i += 1
- end
-loop_count: 1
diff --git a/benchmark/app_tak.yml b/benchmark/app_tak.yml
deleted file mode 100644
index 0b67558b32..0000000000
--- a/benchmark/app_tak.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-benchmark:
- app_tak: |
-
- def tak x, y, z
- unless y < x
- z
- else
- tak( tak(x-1, y, z),
- tak(y-1, z, x),
- tak(z-1, x, y))
- end
- end
-
- tak(18, 9, 0)
-loop_count: 1
diff --git a/benchmark/app_tarai.yml b/benchmark/app_tarai.yml
deleted file mode 100644
index 1f53db68a0..0000000000
--- a/benchmark/app_tarai.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- app_tarai: |
- def tarai( x, y, z )
- if x <= y
- then y
- else tarai(tarai(x-1, y, z),
- tarai(y-1, z, x),
- tarai(z-1, x, y))
- end
- end
-
- tarai(12, 6, 0)
-loop_count: 1
diff --git a/benchmark/app_uri.yml b/benchmark/app_uri.yml
deleted file mode 100644
index 1f7e49de51..0000000000
--- a/benchmark/app_uri.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-benchmark:
- app_uri: |
- require 'uri'
-
- 100_000.times{
- uri = URI.parse('http://www.ruby-lang.org')
- uri.scheme
- uri.host
- uri.port
- }
-loop_count: 1
diff --git a/benchmark/array_sample_100k_10.yml b/benchmark/array_sample_100k_10.yml
deleted file mode 100644
index 043e2fdf1c..0000000000
--- a/benchmark/array_sample_100k_10.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k_10: |
- arr = [*0...100000]
- 10_000.times {arr.sample 10}
-loop_count: 1
diff --git a/benchmark/array_sample_100k_11.yml b/benchmark/array_sample_100k_11.yml
deleted file mode 100644
index 0072c46930..0000000000
--- a/benchmark/array_sample_100k_11.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k_11: |
- arr = [*0...100000]
- 10_000.times {arr.sample 11}
-loop_count: 1
diff --git a/benchmark/array_sample_100k__100.yml b/benchmark/array_sample_100k__100.yml
deleted file mode 100644
index 93d25b3053..0000000000
--- a/benchmark/array_sample_100k__100.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k__100: |
- arr = [*0...100000]
- 10_000.times {arr.sample 100}
-loop_count: 1
diff --git a/benchmark/array_sample_100k__1k.yml b/benchmark/array_sample_100k__1k.yml
deleted file mode 100644
index a6a66ef5dc..0000000000
--- a/benchmark/array_sample_100k__1k.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k__1k: |
- arr = [*0...100000]
- 10_000.times {arr.sample 1000}
-loop_count: 1
diff --git a/benchmark/array_sample_100k__6k.yml b/benchmark/array_sample_100k__6k.yml
deleted file mode 100644
index 438a345b8f..0000000000
--- a/benchmark/array_sample_100k__6k.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k__6k: |
- arr = [*0...100000]
- 10_000.times {arr.sample 6000}
-loop_count: 1
diff --git a/benchmark/array_sample_100k___10k.yml b/benchmark/array_sample_100k___10k.yml
deleted file mode 100644
index 13da9ccd83..0000000000
--- a/benchmark/array_sample_100k___10k.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k___10k: |
- arr = [*0...100000]
- 10_000.times {arr.sample 10_000}
-loop_count: 1
diff --git a/benchmark/array_sample_100k___50k.yml b/benchmark/array_sample_100k___50k.yml
deleted file mode 100644
index 579312dc3f..0000000000
--- a/benchmark/array_sample_100k___50k.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sample_100k___50k: |
- arr = [*0...100000]
- 10_000.times {arr.sample 50_000}
-loop_count: 1
diff --git a/benchmark/array_shift.yml b/benchmark/array_shift.yml
deleted file mode 100644
index 713c542024..0000000000
--- a/benchmark/array_shift.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-benchmark:
- array_shift: |
- require 'benchmark'
-
- Benchmark.bm do |x|
- [10_000,1_000_000,100_000_000].each do |n|
- ary = Array.new(n,0)
- GC.start
- x.report("#{n}:shift"){ ary.shift }
- (0..4).each do |i|
- ary = Array.new(n,0)
- GC.start
- x.report("#{n}:shift(#{i})"){ ary.shift(i) }
- end
- end
- end
-loop_count: 1
diff --git a/benchmark/array_small_and.yml b/benchmark/array_small_and.yml
deleted file mode 100644
index 34d2e8ff58..0000000000
--- a/benchmark/array_small_and.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-benchmark:
- array_small_and: |
- MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
- MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
- ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
-
- ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
- (MIN_SIZE..MAX_SIZE).map do |size2|
- [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
- end
- end
-
- ITERATIONS.times do
- ARRAYS.each do |group|
- group.each do |arr1, arr2|
- arr1 & arr2
- end
- end
- end
-loop_count: 1
diff --git a/benchmark/array_small_diff.yml b/benchmark/array_small_diff.yml
deleted file mode 100644
index 64710e96bf..0000000000
--- a/benchmark/array_small_diff.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-benchmark:
- array_small_diff: |
- MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
- MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
- ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
-
- ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
- (MIN_SIZE..MAX_SIZE).map do |size2|
- [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
- end
- end
-
- ITERATIONS.times do
- ARRAYS.each do |group|
- group.each do |arr1, arr2|
- arr1 - arr2
- end
- end
- end
-loop_count: 1
diff --git a/benchmark/array_small_or.yml b/benchmark/array_small_or.yml
deleted file mode 100644
index 9338bd5dbd..0000000000
--- a/benchmark/array_small_or.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-benchmark:
- array_small_or: |
- MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
- MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
- ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
-
- ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
- (MIN_SIZE..MAX_SIZE).map do |size2|
- [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
- end
- end
-
- ITERATIONS.times do
- ARRAYS.each do |group|
- group.each do |arr1, arr2|
- arr1 | arr2
- end
- end
- end
-loop_count: 1
diff --git a/benchmark/array_sort_block.yml b/benchmark/array_sort_block.yml
deleted file mode 100644
index 775db90f4b..0000000000
--- a/benchmark/array_sort_block.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sort_block: |
- ary = Array.new(1000) { rand(1000) }
- 10000.times { ary.sort { |a, b| a <=> b } }
-loop_count: 1
diff --git a/benchmark/array_sort_float.yml b/benchmark/array_sort_float.yml
deleted file mode 100644
index 2aa2bd5fec..0000000000
--- a/benchmark/array_sort_float.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_sort_float: |
- arr = Array.new(1000) { rand }
- 10000.times { arr.sort }
-loop_count: 1
diff --git a/benchmark/array_values_at_int.yml b/benchmark/array_values_at_int.yml
deleted file mode 100644
index 48bb0f7492..0000000000
--- a/benchmark/array_values_at_int.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_values_at_int: |
- ary = Array.new(10000) {|i| i}
- 100000.times { ary.values_at(500) }
-loop_count: 1
diff --git a/benchmark/array_values_at_range.yml b/benchmark/array_values_at_range.yml
deleted file mode 100644
index 9de66261bb..0000000000
--- a/benchmark/array_values_at_range.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- array_values_at_range: |
- ary = Array.new(10000) {|i| i}
- 100000.times { ary.values_at(1..2000) }
-loop_count: 1
diff --git a/benchmark/bighash.yml b/benchmark/bighash.yml
deleted file mode 100644
index 65d74049e7..0000000000
--- a/benchmark/bighash.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- bighash: |
- h = {}; 5000000.times {|n| h[n] = n }
-loop_count: 1
diff --git a/benchmark/bm_app_answer.rb b/benchmark/bm_app_answer.rb
new file mode 100644
index 0000000000..3cd8a8fd37
--- /dev/null
+++ b/benchmark/bm_app_answer.rb
@@ -0,0 +1,15 @@
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+def the_answer_to_life_the_universe_and_everything
+ (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i
+end
+
+answer = the_answer_to_life_the_universe_and_everything
diff --git a/benchmark/bm_app_aobench.rb b/benchmark/bm_app_aobench.rb
new file mode 100644
index 0000000000..2bd6acfaf8
--- /dev/null
+++ b/benchmark/bm_app_aobench.rb
@@ -0,0 +1,291 @@
+# AO render benchmark
+# Original program (C) Syoyo Fujita in Javascript (and other languages)
+# https://code.google.com/p/aobench/
+# Ruby(yarv2llvm) version by Hideki Miura
+#
+
+IMAGE_WIDTH = 256
+IMAGE_HEIGHT = 256
+NSUBSAMPLES = 2
+NAO_SAMPLES = 8
+
+class Vec
+ def initialize(x, y, z)
+ @x = x
+ @y = y
+ @z = z
+ end
+
+ attr_accessor :x, :y, :z
+
+ def vadd(b)
+ Vec.new(@x + b.x, @y + b.y, @z + b.z)
+ end
+
+ def vsub(b)
+ Vec.new(@x - b.x, @y - b.y, @z - b.z)
+ end
+
+ def vcross(b)
+ Vec.new(@y * b.z - @z * b.y,
+ @z * b.x - @x * b.z,
+ @x * b.y - @y * b.x)
+ end
+
+ def vdot(b)
+ @x * b.x + @y * b.y + @z * b.z
+ end
+
+ def vlength
+ Math.sqrt(@x * @x + @y * @y + @z * @z)
+ end
+
+ def vnormalize
+ len = vlength
+ v = Vec.new(@x, @y, @z)
+ if len > 1.0e-17 then
+ v.x = v.x / len
+ v.y = v.y / len
+ v.z = v.z / len
+ end
+ v
+ end
+end
+
+
+class Sphere
+ def initialize(center, radius)
+ @center = center
+ @radius = radius
+ end
+
+ attr_reader :center, :radius
+
+ def intersect(ray, isect)
+ rs = ray.org.vsub(@center)
+ b = rs.vdot(ray.dir)
+ c = rs.vdot(rs) - (@radius * @radius)
+ d = b * b - c
+ if d > 0.0 then
+ t = - b - Math.sqrt(d)
+
+ if t > 0.0 and t < isect.t then
+ isect.t = t
+ isect.hit = true
+ isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
+ ray.org.y + ray.dir.y * t,
+ ray.org.z + ray.dir.z * t)
+ n = isect.pl.vsub(@center)
+ isect.n = n.vnormalize
+ else
+ 0.0
+ end
+ end
+ nil
+ end
+end
+
+class Plane
+ def initialize(p, n)
+ @p = p
+ @n = n
+ end
+
+ def intersect(ray, isect)
+ d = -@p.vdot(@n)
+ v = ray.dir.vdot(@n)
+ v0 = v
+ if v < 0.0 then
+ v0 = -v
+ end
+ if v0 < 1.0e-17 then
+ return
+ end
+
+ t = -(ray.org.vdot(@n) + d) / v
+
+ if t > 0.0 and t < isect.t then
+ isect.hit = true
+ isect.t = t
+ isect.n = @n
+ isect.pl = Vec.new(ray.org.x + t * ray.dir.x,
+ ray.org.y + t * ray.dir.y,
+ ray.org.z + t * ray.dir.z)
+ end
+ nil
+ end
+end
+
+class Ray
+ def initialize(org, dir)
+ @org = org
+ @dir = dir
+ end
+
+ attr_accessor :org, :dir
+end
+
+class Isect
+ def initialize
+ @t = 10000000.0
+ @hit = false
+ @pl = Vec.new(0.0, 0.0, 0.0)
+ @n = Vec.new(0.0, 0.0, 0.0)
+ end
+
+ attr_accessor :t, :hit, :pl, :n
+end
+
+def clamp(f)
+ i = f * 255.5
+ if i > 255.0 then
+ i = 255.0
+ end
+ if i < 0.0 then
+ i = 0.0
+ end
+ i.to_i
+end
+
+def otherBasis(basis, n)
+ basis[2] = Vec.new(n.x, n.y, n.z)
+ basis[1] = Vec.new(0.0, 0.0, 0.0)
+
+ if n.x < 0.6 and n.x > -0.6 then
+ basis[1].x = 1.0
+ elsif n.y < 0.6 and n.y > -0.6 then
+ basis[1].y = 1.0
+ elsif n.z < 0.6 and n.z > -0.6 then
+ basis[1].z = 1.0
+ else
+ basis[1].x = 1.0
+ end
+
+ basis[0] = basis[1].vcross(basis[2])
+ basis[0] = basis[0].vnormalize
+
+ basis[1] = basis[2].vcross(basis[0])
+ basis[1] = basis[1].vnormalize
+end
+
+class Scene
+ def initialize
+ @spheres = Array.new
+ @spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
+ @spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
+ @spheres[2] = Sphere.new(Vec.new(1.0, 0.0, -2.2), 0.5)
+ @plane = Plane.new(Vec.new(0.0, -0.5, 0.0), Vec.new(0.0, 1.0, 0.0))
+ end
+
+ def ambient_occlusion(isect)
+ basis = Array.new
+ otherBasis(basis, isect.n)
+
+ ntheta = NAO_SAMPLES
+ nphi = NAO_SAMPLES
+ eps = 0.0001
+ occlusion = 0.0
+
+ p0 = Vec.new(isect.pl.x + eps * isect.n.x,
+ isect.pl.y + eps * isect.n.y,
+ isect.pl.z + eps * isect.n.z)
+ nphi.times do |j|
+ ntheta.times do |i|
+ r = rand
+ phi = 2.0 * 3.14159265 * rand
+ x = Math.cos(phi) * Math.sqrt(1.0 - r)
+ y = Math.sin(phi) * Math.sqrt(1.0 - r)
+ z = Math.sqrt(r)
+
+ rx = x * basis[0].x + y * basis[1].x + z * basis[2].x
+ ry = x * basis[0].y + y * basis[1].y + z * basis[2].y
+ rz = x * basis[0].z + y * basis[1].z + z * basis[2].z
+
+ raydir = Vec.new(rx, ry, rz)
+ ray = Ray.new(p0, raydir)
+
+ occisect = Isect.new
+ @spheres[0].intersect(ray, occisect)
+ @spheres[1].intersect(ray, occisect)
+ @spheres[2].intersect(ray, occisect)
+ @plane.intersect(ray, occisect)
+ if occisect.hit then
+ occlusion = occlusion + 1.0
+ else
+ 0.0
+ end
+ end
+ end
+
+ occlusion = (ntheta.to_f * nphi.to_f - occlusion) / (ntheta.to_f * nphi.to_f)
+
+ Vec.new(occlusion, occlusion, occlusion)
+ end
+
+ def render(w, h, nsubsamples)
+ cnt = 0
+ nsf = nsubsamples.to_f
+ h.times do |y|
+ w.times do |x|
+ rad = Vec.new(0.0, 0.0, 0.0)
+
+ # Subsampling
+ nsubsamples.times do |v|
+ nsubsamples.times do |u|
+
+ cnt = cnt + 1
+ wf = w.to_f
+ hf = h.to_f
+ xf = x.to_f
+ yf = y.to_f
+ uf = u.to_f
+ vf = v.to_f
+
+ px = (xf + (uf / nsf) - (wf / 2.0)) / (wf / 2.0)
+ py = -(yf + (vf / nsf) - (hf / 2.0)) / (hf / 2.0)
+
+ eye = Vec.new(px, py, -1.0).vnormalize
+
+ ray = Ray.new(Vec.new(0.0, 0.0, 0.0), eye)
+
+ isect = Isect.new
+ @spheres[0].intersect(ray, isect)
+ @spheres[1].intersect(ray, isect)
+ @spheres[2].intersect(ray, isect)
+ @plane.intersect(ray, isect)
+ if isect.hit then
+ col = ambient_occlusion(isect)
+ rad.x = rad.x + col.x
+ rad.y = rad.y + col.y
+ rad.z = rad.z + col.z
+ end
+ end
+ end
+
+ r = rad.x / (nsf * nsf)
+ g = rad.y / (nsf * nsf)
+ b = rad.z / (nsf * nsf)
+ printf("%c", clamp(r))
+ printf("%c", clamp(g))
+ printf("%c", clamp(b))
+ end
+ nil
+ end
+
+ nil
+ end
+end
+
+alias printf_orig printf
+def printf *args
+end
+
+# File.open("ao.ppm", "w") do |fp|
+ printf("P6\n")
+ printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
+ printf("255\n", IMAGE_WIDTH, IMAGE_HEIGHT)
+ Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
+# end
+
+undef printf
+alias printf printf_orig
diff --git a/benchmark/bm_app_erb.rb b/benchmark/bm_app_erb.rb
new file mode 100644
index 0000000000..9a1cb2707f
--- /dev/null
+++ b/benchmark/bm_app_erb.rb
@@ -0,0 +1,25 @@
+#
+# Create many HTML strings with ERB.
+#
+
+require 'erb'
+
+data = <<erb
+<html>
+ <head> <%= title %> </head>
+ <body>
+ <h1> <%= title %> </h1>
+ <p>
+ <%= content %>
+ </p>
+ </body>
+</html>
+erb
+
+max = 15_000
+title = "hello world!"
+content = "hello world!\n" * 10
+
+max.times{
+ ERB.new(data).result(binding)
+}
diff --git a/benchmark/bm_app_factorial.rb b/benchmark/bm_app_factorial.rb
new file mode 100644
index 0000000000..45f471dfdb
--- /dev/null
+++ b/benchmark/bm_app_factorial.rb
@@ -0,0 +1,11 @@
+def fact(n)
+ if(n > 1)
+ n * fact(n-1)
+ else
+ 1
+ end
+end
+
+100.times {
+ fact(5000)
+}
diff --git a/benchmark/bm_app_fib.rb b/benchmark/bm_app_fib.rb
new file mode 100644
index 0000000000..34a7b2e725
--- /dev/null
+++ b/benchmark/bm_app_fib.rb
@@ -0,0 +1,10 @@
+def fib n
+ if n < 3
+ 1
+ else
+ fib(n-1) + fib(n-2)
+ end
+end
+
+fib(34)
+
diff --git a/benchmark/bm_app_lc_fizzbuzz.rb b/benchmark/bm_app_lc_fizzbuzz.rb
new file mode 100644
index 0000000000..f09574bbeb
--- /dev/null
+++ b/benchmark/bm_app_lc_fizzbuzz.rb
@@ -0,0 +1,52 @@
+#
+# FizzBuzz program using only lambda calculus
+#
+# This program is quoted from
+# "Understanding Computation" by Tom Stuart
+# http://computationbook.com/
+#
+# You can understand why this program works fine by reading this book.
+#
+
+solution = -> k { -> f { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][k][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> l { -> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[l][f[x]] } }] } }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[m][n]][-> x { -> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[f[-> n { -> p { -> x { p[n[p][x]] } } }[m]][n]][m][x] }][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]] } } }][-> p { -> x { p[x] } }][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] } }]][-> n { -> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[x]]]]]]]]]]]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[x]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> b { b }[-> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]]][-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> n { -> p { -> x { p[n[p][x]] } } }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]]]][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> n { -> l { -> x { -> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> l { -> x { -> g { -> b { b }[-> p { p[-> x { -> y { x } }] }[l]][x][-> y { g[f[-> l { -> p { p[-> x { -> y { y } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][x][g]][-> l { -> p { p[-> x { -> y { x } }] }[-> p { p[-> x { -> y { y } }] }[l]] }[l]][y] }] } } } }][l][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }[-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][x]][-> l { -> x { -> x { -> y { -> f { f[x][y] } } }[-> x { -> y { y } }][-> x { -> y { -> f { f[x][y] } } }[x][l]] } }] } }[-> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }[-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]]][-> x { -> y { -> f { f[x][y] } } }[-> x { -> y { x } }][-> x { -> y { x } }]][-> x { f[-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { -> n { -> p { -> x { p[n[p][x]] } } }[f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n]][x] }][-> p { -> x { x } }] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]][x] }]][-> f { -> x { f[-> y { x[x][y] }] }[-> x { f[-> y { x[x][y] }] }] }[-> f { -> m { -> n { -> b { b }[-> m { -> n { -> n { n[-> x { -> x { -> y { y } } }][-> x { -> y { x } }] }[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]] } }[n][m]][-> x { f[-> m { -> n { n[-> n { -> p { p[-> x { -> y { x } }] }[n[-> p { -> x { -> y { -> f { f[x][y] } } }[-> p { p[-> x { -> y { y } }] }[p]][-> n { -> p { -> x { p[n[p][x]] } } }[-> p { p[-> x { -> y { y } }] }[p]]] }][-> x { -> y { -> f { f[x][y] } } }[-> p { -> x { x } }][-> p { -> x { x } }]]] }][m] } }[m][n]][n][x] }][m] } } }][n][-> m { -> n { n[-> m { -> n { n[-> n { -> p { -> x { p[n[p][x]] } } }][m] } }[m]][-> p { -> x { x } }] } }[-> p { -> x { p[p[x]] } }][-> p { -> x { p[p[p[p[p[x]]]]] } }]]] } }][n]]]] }]
+
+FIRST = -> l { LEFT[RIGHT[l]] }
+IF = -> b { b }
+LEFT = -> p { p[-> x { -> y { x } } ] }
+RIGHT = -> p { p[-> x { -> y { y } } ] }
+IS_EMPTY = LEFT
+REST = -> l { RIGHT[RIGHT[l]] }
+
+def to_integer(proc)
+ proc[-> n { n + 1 }][0]
+end
+
+def to_boolean(proc)
+ IF[proc][true][false]
+end
+
+def to_array(proc)
+ array = []
+
+ until to_boolean(IS_EMPTY[proc])
+ array.push(FIRST[proc])
+ proc = REST[proc]
+ end
+
+ array
+end
+
+def to_char(c)
+ '0123456789BFiuz'.slice(to_integer(c))
+end
+
+def to_string(s)
+ to_array(s).map { |c| to_char(c) }.join
+end
+
+answer = to_array(solution).map do |p|
+ to_string(p)
+end
+
+answer_ary = answer.to_a
+# puts answer_ary
diff --git a/benchmark/bm_app_mandelbrot.rb b/benchmark/bm_app_mandelbrot.rb
new file mode 100644
index 0000000000..801b75e8e2
--- /dev/null
+++ b/benchmark/bm_app_mandelbrot.rb
@@ -0,0 +1,23 @@
+require 'complex'
+
+def mandelbrot? z
+ i = 0
+ while i<100
+ i += 1
+ z = z * z
+ return false if z.abs > 2
+ end
+ true
+end
+
+ary = []
+
+(0..1000).each{|dx|
+ (0..1000).each{|dy|
+ x = dx / 50.0
+ y = dy / 50.0
+ c = Complex(x, y)
+ ary << c if mandelbrot?(c)
+ }
+}
+
diff --git a/benchmark/bm_app_pentomino.rb b/benchmark/bm_app_pentomino.rb
new file mode 100644
index 0000000000..47be7b203f
--- /dev/null
+++ b/benchmark/bm_app_pentomino.rb
@@ -0,0 +1,130 @@
+#!/usr/local/bin/ruby
+# This program is contributed by Shin Nishiyama
+
+
+# modified by K.Sasada
+
+NP = 5
+ROW = 8 + NP
+COL = 8
+
+$p = []
+$b = []
+$no = 0
+
+def piece(n, a, nb)
+ nb.each{|x|
+ a[n] = x
+ if n == NP-1
+ $p << [a.sort]
+ else
+ nbc=nb.dup
+ [-ROW, -1, 1, ROW].each{|d|
+ if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
+ nbc << x+d
+ end
+ }
+ nbc.delete x
+ piece(n+1,a[0..n],nbc)
+ end
+ }
+end
+
+def kikaku(a)
+ a.collect {|x| x - a[0]}
+end
+def ud(a)
+ kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
+end
+def rl(a)
+ kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
+end
+def xy(a)
+ kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
+end
+
+def mkpieces
+ piece(0,[],[0])
+ $p.each do |a|
+ a0 = a[0]
+ a[1] = ud(a0)
+ a[2] = rl(a0)
+ a[3] = ud(rl(a0))
+ a[4] = xy(a0)
+ a[5] = ud(xy(a0))
+ a[6] = rl(xy(a0))
+ a[7] = ud(rl(xy(a0)))
+ a.sort!
+ a.uniq!
+ end
+ $p.uniq!.sort! {|x,y| x[0] <=> y[0] }
+end
+
+def mkboard
+ (0...ROW*COL).each{|i|
+ if i % ROW >= ROW-NP
+ $b[i] = -2
+ else
+ $b[i] = -1
+ end
+ $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
+ }
+end
+
+def pboard
+ return # skip print
+ print "No. #$no\n"
+ (0...COL).each{|i|
+ print "|"
+ (0...ROW-NP).each{|j|
+ x = $b[i*ROW+j]
+ if x < 0
+ print "..|"
+ else
+ printf "%2d|",x+1
+ end
+ }
+ print "\n"
+ }
+ print "\n"
+end
+
+$pnum=[]
+def setpiece(a,pos)
+ if a.length == $p.length then
+ $no += 1
+ pboard
+ return
+ end
+ while $b[pos] != -1
+ pos += 1
+ end
+ ($pnum - a).each do |i|
+ $p[i].each do |x|
+ f = 0
+ x.each{|s|
+ if $b[pos+s] != -1
+ f=1
+ break
+ end
+ }
+ if f == 0 then
+ x.each{|s|
+ $b[pos+s] = i
+ }
+ a << i
+ setpiece(a.dup, pos)
+ a.pop
+ x.each{|s|
+ $b[pos+s] = -1
+ }
+ end
+ end
+ end
+end
+
+mkpieces
+mkboard
+$p[4] = [$p[4][0]]
+$pnum = (0...$p.length).to_a
+setpiece([],0)
diff --git a/benchmark/bm_app_raise.rb b/benchmark/bm_app_raise.rb
new file mode 100644
index 0000000000..5db8f95d50
--- /dev/null
+++ b/benchmark/bm_app_raise.rb
@@ -0,0 +1,8 @@
+i = 0
+while i<300000
+ i += 1
+ begin
+ raise
+ rescue
+ end
+end
diff --git a/benchmark/bm_app_strconcat.rb b/benchmark/bm_app_strconcat.rb
new file mode 100644
index 0000000000..7eed7c1aed
--- /dev/null
+++ b/benchmark/bm_app_strconcat.rb
@@ -0,0 +1,5 @@
+i = 0
+while i<2_000_000
+ "#{1+1} #{1+1} #{1+1}"
+ i += 1
+end
diff --git a/benchmark/bm_app_tak.rb b/benchmark/bm_app_tak.rb
new file mode 100644
index 0000000000..efe5380f4e
--- /dev/null
+++ b/benchmark/bm_app_tak.rb
@@ -0,0 +1,13 @@
+
+def tak x, y, z
+ unless y < x
+ z
+ else
+ tak( tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+ end
+end
+
+tak(18, 9, 0)
+
diff --git a/benchmark/bm_app_tarai.rb b/benchmark/bm_app_tarai.rb
new file mode 100644
index 0000000000..4c146f5ccf
--- /dev/null
+++ b/benchmark/bm_app_tarai.rb
@@ -0,0 +1,10 @@
+def tarai( x, y, z )
+ if x <= y
+ then y
+ else tarai(tarai(x-1, y, z),
+ tarai(y-1, z, x),
+ tarai(z-1, x, y))
+ end
+end
+
+tarai(12, 6, 0)
diff --git a/benchmark/bm_app_uri.rb b/benchmark/bm_app_uri.rb
new file mode 100644
index 0000000000..586edfd5dc
--- /dev/null
+++ b/benchmark/bm_app_uri.rb
@@ -0,0 +1,8 @@
+require 'uri'
+
+100_000.times{
+ uri = URI.parse('http://www.ruby-lang.org')
+ uri.scheme
+ uri.host
+ uri.port
+}
diff --git a/benchmark/bm_array_sample_100k_10.rb b/benchmark/bm_array_sample_100k_10.rb
new file mode 100644
index 0000000000..5f41ecc32b
--- /dev/null
+++ b/benchmark/bm_array_sample_100k_10.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 10}
diff --git a/benchmark/bm_array_sample_100k_11.rb b/benchmark/bm_array_sample_100k_11.rb
new file mode 100644
index 0000000000..18b1715319
--- /dev/null
+++ b/benchmark/bm_array_sample_100k_11.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 11}
diff --git a/benchmark/bm_array_sample_100k__100.rb b/benchmark/bm_array_sample_100k__100.rb
new file mode 100644
index 0000000000..22863afe89
--- /dev/null
+++ b/benchmark/bm_array_sample_100k__100.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 100}
diff --git a/benchmark/bm_array_sample_100k__1k.rb b/benchmark/bm_array_sample_100k__1k.rb
new file mode 100644
index 0000000000..4cd79e6c67
--- /dev/null
+++ b/benchmark/bm_array_sample_100k__1k.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 1000}
diff --git a/benchmark/bm_array_sample_100k__6k.rb b/benchmark/bm_array_sample_100k__6k.rb
new file mode 100644
index 0000000000..b3d264249e
--- /dev/null
+++ b/benchmark/bm_array_sample_100k__6k.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 6000}
diff --git a/benchmark/bm_array_sample_100k___10k.rb b/benchmark/bm_array_sample_100k___10k.rb
new file mode 100644
index 0000000000..5dd55ec058
--- /dev/null
+++ b/benchmark/bm_array_sample_100k___10k.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 10_000}
diff --git a/benchmark/bm_array_sample_100k___50k.rb b/benchmark/bm_array_sample_100k___50k.rb
new file mode 100644
index 0000000000..1506732c3c
--- /dev/null
+++ b/benchmark/bm_array_sample_100k___50k.rb
@@ -0,0 +1,2 @@
+arr = [*0...100000]
+10_000.times {arr.sample 50_000}
diff --git a/benchmark/bm_array_shift.rb b/benchmark/bm_array_shift.rb
new file mode 100644
index 0000000000..798bb9e3f4
--- /dev/null
+++ b/benchmark/bm_array_shift.rb
@@ -0,0 +1,14 @@
+require 'benchmark'
+
+Benchmark.bm do |x|
+ [10_000,1_000_000,100_000_000].each do |n|
+ ary = Array.new(n,0)
+ GC.start
+ x.report("#{n}:shift"){ ary.shift }
+ (0..4).each do |i|
+ ary = Array.new(n,0)
+ GC.start
+ x.report("#{n}:shift(#{i})"){ ary.shift(i) }
+ end
+ end
+end
diff --git a/benchmark/bm_array_small_and.rb b/benchmark/bm_array_small_and.rb
new file mode 100644
index 0000000000..e53a6edae6
--- /dev/null
+++ b/benchmark/bm_array_small_and.rb
@@ -0,0 +1,17 @@
+MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
+MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
+ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
+
+ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
+ (MIN_SIZE..MAX_SIZE).map do |size2|
+ [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
+ end
+end
+
+ITERATIONS.times do
+ ARRAYS.each do |group|
+ group.each do |arr1, arr2|
+ arr1 & arr2
+ end
+ end
+end
diff --git a/benchmark/bm_array_small_diff.rb b/benchmark/bm_array_small_diff.rb
new file mode 100644
index 0000000000..9661ee48db
--- /dev/null
+++ b/benchmark/bm_array_small_diff.rb
@@ -0,0 +1,17 @@
+MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
+MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
+ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
+
+ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
+ (MIN_SIZE..MAX_SIZE).map do |size2|
+ [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
+ end
+end
+
+ITERATIONS.times do
+ ARRAYS.each do |group|
+ group.each do |arr1, arr2|
+ arr1 - arr2
+ end
+ end
+end
diff --git a/benchmark/bm_array_small_or.rb b/benchmark/bm_array_small_or.rb
new file mode 100644
index 0000000000..c58b5fd1ff
--- /dev/null
+++ b/benchmark/bm_array_small_or.rb
@@ -0,0 +1,17 @@
+MIN_SIZE = ENV.fetch('SMALL_ARRAY_MIN', 0).to_i
+MAX_SIZE = ENV.fetch('SMALL_ARRAY_MAX', 16).to_i
+ITERATIONS = ENV.fetch('SMALL_ARRAY_ITERATIONS', 100).to_i
+
+ARRAYS = (MIN_SIZE..MAX_SIZE).map do |size1|
+ (MIN_SIZE..MAX_SIZE).map do |size2|
+ [Array.new(size1) { rand(MAX_SIZE) }, Array.new(size2) { rand(MAX_SIZE) }]
+ end
+end
+
+ITERATIONS.times do
+ ARRAYS.each do |group|
+ group.each do |arr1, arr2|
+ arr1 | arr2
+ end
+ end
+end
diff --git a/benchmark/bm_array_sort_block.rb b/benchmark/bm_array_sort_block.rb
new file mode 100644
index 0000000000..3579786056
--- /dev/null
+++ b/benchmark/bm_array_sort_block.rb
@@ -0,0 +1,2 @@
+ary = Array.new(1000) { rand(1000) }
+10000.times { ary.sort { |a, b| a <=> b } }
diff --git a/benchmark/bm_array_sort_float.rb b/benchmark/bm_array_sort_float.rb
new file mode 100644
index 0000000000..9a6e2f8bd2
--- /dev/null
+++ b/benchmark/bm_array_sort_float.rb
@@ -0,0 +1,2 @@
+arr = Array.new(1000) { rand }
+10000.times { arr.sort }
diff --git a/benchmark/bm_array_values_at_int.rb b/benchmark/bm_array_values_at_int.rb
new file mode 100644
index 0000000000..6cb394cb9f
--- /dev/null
+++ b/benchmark/bm_array_values_at_int.rb
@@ -0,0 +1,2 @@
+ary = Array.new(10000) {|i| i}
+100000.times { ary.values_at(500) }
diff --git a/benchmark/bm_array_values_at_range.rb b/benchmark/bm_array_values_at_range.rb
new file mode 100644
index 0000000000..5b53806d1c
--- /dev/null
+++ b/benchmark/bm_array_values_at_range.rb
@@ -0,0 +1,2 @@
+ary = Array.new(10000) {|i| i}
+100000.times { ary.values_at(1..2000) }
diff --git a/benchmark/bm_bighash.rb b/benchmark/bm_bighash.rb
new file mode 100644
index 0000000000..e2ad5a5c94
--- /dev/null
+++ b/benchmark/bm_bighash.rb
@@ -0,0 +1 @@
+h = {}; 5000000.times {|n| h[n] = n }
diff --git a/benchmark/bm_dir_empty_p.rb b/benchmark/bm_dir_empty_p.rb
new file mode 100644
index 0000000000..8329c757cf
--- /dev/null
+++ b/benchmark/bm_dir_empty_p.rb
@@ -0,0 +1,5 @@
+require 'tmpdir'
+max = 100_000
+Dir.mktmpdir('bm_dir_empty_p') do |dir|
+ max.times { Dir.empty?(dir) }
+end
diff --git a/benchmark/bm_erb_render.rb b/benchmark/bm_erb_render.rb
new file mode 100644
index 0000000000..7dc0816c43
--- /dev/null
+++ b/benchmark/bm_erb_render.rb
@@ -0,0 +1,25 @@
+require 'erb'
+
+data = <<erb
+<html>
+ <head> <%= title %> </head>
+ <body>
+ <h1> <%= title %> </h1>
+ <p>
+ <%= content %>
+ </p>
+ </body>
+</html>
+erb
+
+max = 1_500_000
+title = "hello world!"
+content = "hello world!\n" * 10
+
+src = "def self.render(title, content); #{ERB.new(data).src}; end"
+mod = Module.new
+mod.instance_eval(src, "(ERB)")
+
+max.times do
+ mod.render(title, content)
+end
diff --git a/benchmark/bm_file_chmod.rb b/benchmark/bm_file_chmod.rb
new file mode 100644
index 0000000000..1cd4760c9d
--- /dev/null
+++ b/benchmark/bm_file_chmod.rb
@@ -0,0 +1,9 @@
+# chmod file
+require 'tempfile'
+max = 200_000
+tmp = Tempfile.new('chmod')
+path = tmp.path
+max.times do
+ File.chmod(0777, path)
+end
+tmp.close!
diff --git a/benchmark/bm_file_rename.rb b/benchmark/bm_file_rename.rb
new file mode 100644
index 0000000000..bbb44aebac
--- /dev/null
+++ b/benchmark/bm_file_rename.rb
@@ -0,0 +1,11 @@
+# rename file
+require 'tempfile'
+
+max = 100_000
+tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ]
+a, b = tmp.map { |x| x.path }
+tmp.each { |t| t.close } # Windows can't rename files without closing them
+max.times do
+ File.rename(a, b)
+ File.rename(b, a)
+end
diff --git a/benchmark/bm_hash_aref_dsym.rb b/benchmark/bm_hash_aref_dsym.rb
new file mode 100644
index 0000000000..af4f8c36d4
--- /dev/null
+++ b/benchmark/bm_hash_aref_dsym.rb
@@ -0,0 +1,4 @@
+h = {}
+syms = ('a'..'z').map { |s| s.to_sym }
+syms.each { |s| h[s] = 1 }
+200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_dsym_long.rb b/benchmark/bm_hash_aref_dsym_long.rb
new file mode 100644
index 0000000000..9d7759379e
--- /dev/null
+++ b/benchmark/bm_hash_aref_dsym_long.rb
@@ -0,0 +1,21 @@
+# [ruby-core:70129] [Bug #11396]
+collection_size = 200000
+sample_size = 10000
+
+values = (1..collection_size).to_a.map do |x|
+ "THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}"
+end
+
+symbol_hash = {}
+
+values.each do |x|
+ symbol_hash[x.to_sym] = 1
+end
+
+# use the same samples each time to minimize deviations
+rng = Random.new(0)
+symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym)
+
+3000.times do
+ symbol_sample_array.each { |x| symbol_hash[x] }
+end
diff --git a/benchmark/bm_hash_aref_fix.rb b/benchmark/bm_hash_aref_fix.rb
new file mode 100644
index 0000000000..1346890582
--- /dev/null
+++ b/benchmark/bm_hash_aref_fix.rb
@@ -0,0 +1,4 @@
+h = {}
+nums = (1..26).to_a
+nums.each { |i| h[i] = i }
+200_000.times { nums.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_flo.rb b/benchmark/bm_hash_aref_flo.rb
new file mode 100644
index 0000000000..2217274c82
--- /dev/null
+++ b/benchmark/bm_hash_aref_flo.rb
@@ -0,0 +1,4 @@
+h = {}
+strs = [*1..10000].map! {|i| i.fdiv(10)}
+strs.each { |s| h[s] = s }
+50.times { strs.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_miss.rb b/benchmark/bm_hash_aref_miss.rb
new file mode 100644
index 0000000000..b0913dd4bb
--- /dev/null
+++ b/benchmark/bm_hash_aref_miss.rb
@@ -0,0 +1,5 @@
+h = {}
+strs = ('a'..'z').to_a.map!(&:freeze)
+strs.each { |s| h[s] = s }
+strs = ('A'..'Z').to_a
+200_000.times { strs.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_str.rb b/benchmark/bm_hash_aref_str.rb
new file mode 100644
index 0000000000..19439b061b
--- /dev/null
+++ b/benchmark/bm_hash_aref_str.rb
@@ -0,0 +1,4 @@
+h = {}
+strs = ('a'..'z').to_a.map!(&:freeze)
+strs.each { |s| h[s] = s }
+200_000.times { strs.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_sym.rb b/benchmark/bm_hash_aref_sym.rb
new file mode 100644
index 0000000000..f75d163fe6
--- /dev/null
+++ b/benchmark/bm_hash_aref_sym.rb
@@ -0,0 +1,9 @@
+h = {}
+syms = ('a'..'z').to_a
+begin
+ syms = eval("%i[#{syms.join(' ')}]")
+rescue SyntaxError # <= 1.9.3
+ syms.map!(&:to_sym)
+end
+syms.each { |s| h[s] = s }
+200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_aref_sym_long.rb b/benchmark/bm_hash_aref_sym_long.rb
new file mode 100644
index 0000000000..9dab8df7be
--- /dev/null
+++ b/benchmark/bm_hash_aref_sym_long.rb
@@ -0,0 +1,13 @@
+h = {}
+syms = %w[puts warn syswrite write stat bacon lettuce tomato
+some symbols in this array may already be interned others should not be
+hash browns make good breakfast but not cooked using prime numbers
+shift for division entries delete_if keys exist?
+]
+begin
+ syms = eval("%i[#{syms.join(' ')}]")
+rescue SyntaxError # <= 1.9.3
+ syms.map!(&:to_sym)
+end
+syms.each { |s| h[s] = s }
+200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_flatten.rb b/benchmark/bm_hash_flatten.rb
new file mode 100644
index 0000000000..e944aae9f2
--- /dev/null
+++ b/benchmark/bm_hash_flatten.rb
@@ -0,0 +1,9 @@
+h = {}
+
+10000.times do |i|
+ h[i] = nil
+end
+
+1000.times do
+ h.flatten
+end
diff --git a/benchmark/bm_hash_ident_flo.rb b/benchmark/bm_hash_ident_flo.rb
new file mode 100644
index 0000000000..0c7edfed3e
--- /dev/null
+++ b/benchmark/bm_hash_ident_flo.rb
@@ -0,0 +1,4 @@
+h = {}.compare_by_identity
+strs = (1..10000).to_a.map!(&:to_f)
+strs.each { |s| h[s] = s }
+50.times { strs.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_ident_num.rb b/benchmark/bm_hash_ident_num.rb
new file mode 100644
index 0000000000..b226736c6f
--- /dev/null
+++ b/benchmark/bm_hash_ident_num.rb
@@ -0,0 +1,4 @@
+h = {}.compare_by_identity
+nums = (1..26).to_a
+nums.each { |n| h[n] = n }
+200_000.times { nums.each { |n| h[n] } }
diff --git a/benchmark/bm_hash_ident_obj.rb b/benchmark/bm_hash_ident_obj.rb
new file mode 100644
index 0000000000..4b3b58edec
--- /dev/null
+++ b/benchmark/bm_hash_ident_obj.rb
@@ -0,0 +1,4 @@
+h = {}.compare_by_identity
+objs = 26.times.map { Object.new }
+objs.each { |o| h[o] = o }
+200_000.times { objs.each { |o| h[o] } }
diff --git a/benchmark/bm_hash_ident_str.rb b/benchmark/bm_hash_ident_str.rb
new file mode 100644
index 0000000000..8582b38e31
--- /dev/null
+++ b/benchmark/bm_hash_ident_str.rb
@@ -0,0 +1,4 @@
+h = {}.compare_by_identity
+strs = ('a'..'z').to_a
+strs.each { |s| h[s] = s }
+200_000.times { strs.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_ident_sym.rb b/benchmark/bm_hash_ident_sym.rb
new file mode 100644
index 0000000000..4c81e3d28e
--- /dev/null
+++ b/benchmark/bm_hash_ident_sym.rb
@@ -0,0 +1,4 @@
+h = {}.compare_by_identity
+syms = ('a'..'z').to_a.map(&:to_sym)
+syms.each { |s| h[s] = s }
+200_000.times { syms.each { |s| h[s] } }
diff --git a/benchmark/bm_hash_keys.rb b/benchmark/bm_hash_keys.rb
new file mode 100644
index 0000000000..6863cd01f9
--- /dev/null
+++ b/benchmark/bm_hash_keys.rb
@@ -0,0 +1,9 @@
+h = {}
+
+10000.times do |i|
+ h[i] = nil
+end
+
+5000.times do
+ h.keys
+end
diff --git a/benchmark/bm_hash_long.rb b/benchmark/bm_hash_long.rb
new file mode 100644
index 0000000000..03d9109602
--- /dev/null
+++ b/benchmark/bm_hash_long.rb
@@ -0,0 +1,4 @@
+k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong";
+k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping";
+h = {k1 => 0, k2 => 0};
+3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1}
diff --git a/benchmark/bm_hash_shift.rb b/benchmark/bm_hash_shift.rb
new file mode 100644
index 0000000000..a645671a5b
--- /dev/null
+++ b/benchmark/bm_hash_shift.rb
@@ -0,0 +1,10 @@
+h = {}
+
+10000.times do |i|
+ h[i] = nil
+end
+
+50000.times do
+ k, v = h.shift
+ h[k] = v
+end
diff --git a/benchmark/bm_hash_shift_u16.rb b/benchmark/bm_hash_shift_u16.rb
new file mode 100644
index 0000000000..ec800d0342
--- /dev/null
+++ b/benchmark/bm_hash_shift_u16.rb
@@ -0,0 +1,10 @@
+h = {}
+
+(16384..65536).each do |i|
+ h[i] = nil
+end
+
+300000.times do
+ k, v = h.shift
+ h[k] = v
+end
diff --git a/benchmark/bm_hash_shift_u24.rb b/benchmark/bm_hash_shift_u24.rb
new file mode 100644
index 0000000000..de4e0fa696
--- /dev/null
+++ b/benchmark/bm_hash_shift_u24.rb
@@ -0,0 +1,10 @@
+h = {}
+
+(0xff4000..0xffffff).each do |i|
+ h[i] = nil
+end
+
+300000.times do
+ k, v = h.shift
+ h[k] = v
+end
diff --git a/benchmark/bm_hash_shift_u32.rb b/benchmark/bm_hash_shift_u32.rb
new file mode 100644
index 0000000000..656aa55583
--- /dev/null
+++ b/benchmark/bm_hash_shift_u32.rb
@@ -0,0 +1,10 @@
+h = {}
+
+(0xffff4000..0xffffffff).each do |i|
+ h[i] = nil
+end
+
+300000.times do
+ k, v = h.shift
+ h[k] = v
+end
diff --git a/benchmark/bm_hash_small2.rb b/benchmark/bm_hash_small2.rb
new file mode 100644
index 0000000000..45485d9c71
--- /dev/null
+++ b/benchmark/bm_hash_small2.rb
@@ -0,0 +1 @@
+1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a}
diff --git a/benchmark/bm_hash_small4.rb b/benchmark/bm_hash_small4.rb
new file mode 100644
index 0000000000..acd4084334
--- /dev/null
+++ b/benchmark/bm_hash_small4.rb
@@ -0,0 +1 @@
+1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a}
diff --git a/benchmark/bm_hash_small8.rb b/benchmark/bm_hash_small8.rb
new file mode 100644
index 0000000000..9cffcc91b6
--- /dev/null
+++ b/benchmark/bm_hash_small8.rb
@@ -0,0 +1 @@
+1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a}
diff --git a/benchmark/bm_hash_to_proc.rb b/benchmark/bm_hash_to_proc.rb
new file mode 100644
index 0000000000..2b675bf509
--- /dev/null
+++ b/benchmark/bm_hash_to_proc.rb
@@ -0,0 +1,9 @@
+h = {}
+
+10000.times do |i|
+ h[i] = nil
+end
+
+5000.times do |i|
+ [i].map(&h)
+end
diff --git a/benchmark/bm_hash_values.rb b/benchmark/bm_hash_values.rb
new file mode 100644
index 0000000000..069441302f
--- /dev/null
+++ b/benchmark/bm_hash_values.rb
@@ -0,0 +1,9 @@
+h = {}
+
+10000.times do |i|
+ h[i] = nil
+end
+
+5000.times do
+ h.values
+end
diff --git a/benchmark/bm_int_quo.rb b/benchmark/bm_int_quo.rb
new file mode 100644
index 0000000000..e22a3f8c30
--- /dev/null
+++ b/benchmark/bm_int_quo.rb
@@ -0,0 +1 @@
+5000000.times { 42.quo(3) }
diff --git a/benchmark/bm_io_copy_stream_write.rb b/benchmark/bm_io_copy_stream_write.rb
new file mode 100644
index 0000000000..3fd87250a4
--- /dev/null
+++ b/benchmark/bm_io_copy_stream_write.rb
@@ -0,0 +1,24 @@
+# The goal of this is to use a synthetic (non-IO) reader
+# to trigger the read/write loop of IO.copy_stream,
+# bypassing in-kernel mechanisms like sendfile for zero copy,
+# so we wrap the /dev/zero IO object:
+
+class Zero
+ def initialize
+ @n = 100000
+ @in = File.open('/dev/zero', 'rb')
+ end
+
+ def read(len, buf)
+ return if (@n -= 1) == 0
+ @in.read(len, buf)
+ end
+end
+
+begin
+ src = Zero.new
+ dst = File.open(IO::NULL, 'wb')
+ n = IO.copy_stream(src, dst)
+rescue Errno::ENOENT
+ # not *nix
+end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL)
diff --git a/benchmark/bm_io_copy_stream_write_socket.rb b/benchmark/bm_io_copy_stream_write_socket.rb
new file mode 100644
index 0000000000..11f369bd0d
--- /dev/null
+++ b/benchmark/bm_io_copy_stream_write_socket.rb
@@ -0,0 +1,35 @@
+# The goal of this is to use a synthetic (non-IO) reader
+# to trigger the read/write loop of IO.copy_stream,
+# bypassing in-kernel mechanisms like sendfile for zero copy,
+# so we wrap the /dev/zero IO object:
+class Zero
+ def initialize
+ @n = 100000
+ @in = File.open('/dev/zero', 'rb')
+ end
+
+ def read(len, buf)
+ return if (@n -= 1) == 0
+ @in.read(len, buf)
+ end
+end
+
+begin
+ require 'socket'
+ src = Zero.new
+ rd, wr = UNIXSocket.pair
+ pid = fork do
+ wr.close
+ buf = String.new
+ while rd.read(16384, buf)
+ end
+ end
+ rd.close
+ IO.copy_stream(src, wr)
+rescue Errno::ENOENT, NotImplementedError, NameError
+ # not *nix: missing /dev/zero, fork, or UNIXSocket
+rescue LoadError # no socket?
+ensure
+ wr.close if wr
+ Process.waitpid(pid) if pid
+end if IO.respond_to?(:copy_stream)
diff --git a/benchmark/bm_io_file_create.rb b/benchmark/bm_io_file_create.rb
new file mode 100644
index 0000000000..2f205c1333
--- /dev/null
+++ b/benchmark/bm_io_file_create.rb
@@ -0,0 +1,13 @@
+#
+# Create files
+#
+
+max = 200_000
+file = './tmpfile_of_bm_io_file_create'
+
+max.times{
+ f = open(file, 'w')
+ f.close#(true)
+}
+File.unlink(file)
+
diff --git a/benchmark/bm_io_file_read.rb b/benchmark/bm_io_file_read.rb
new file mode 100644
index 0000000000..b9e796ed30
--- /dev/null
+++ b/benchmark/bm_io_file_read.rb
@@ -0,0 +1,15 @@
+#
+# Seek and Read file.
+#
+
+require 'tempfile'
+
+max = 200_000
+str = "Hello world! " * 1000
+f = Tempfile.new('yarv-benchmark')
+f.write str
+
+max.times{
+ f.seek 0
+ f.read
+}
diff --git a/benchmark/bm_io_file_write.rb b/benchmark/bm_io_file_write.rb
new file mode 100644
index 0000000000..aa1be0e5fe
--- /dev/null
+++ b/benchmark/bm_io_file_write.rb
@@ -0,0 +1,14 @@
+#
+# Seek and Write file.
+#
+
+require 'tempfile'
+
+max = 200_000
+str = "Hello world! " * 1000
+f = Tempfile.new('yarv-benchmark')
+
+max.times{
+ f.seek 0
+ f.write str
+}
diff --git a/benchmark/bm_io_nonblock_noex.rb b/benchmark/bm_io_nonblock_noex.rb
new file mode 100644
index 0000000000..da9357fdc6
--- /dev/null
+++ b/benchmark/bm_io_nonblock_noex.rb
@@ -0,0 +1,22 @@
+nr = 1_000_000
+i = 0
+msg = '.'
+buf = '.'
+noex = { exception: false }
+begin
+ r, w = IO.pipe
+ while i < nr
+ i += 1
+ w.write_nonblock(msg, noex)
+ r.read_nonblock(1, buf, noex)
+ end
+rescue ArgumentError # old Rubies
+ while i < nr
+ i += 1
+ w.write_nonblock(msg)
+ r.read_nonblock(1, buf)
+ end
+ensure
+ r.close
+ w.close
+end
diff --git a/benchmark/bm_io_nonblock_noex2.rb b/benchmark/bm_io_nonblock_noex2.rb
new file mode 100644
index 0000000000..56819d049b
--- /dev/null
+++ b/benchmark/bm_io_nonblock_noex2.rb
@@ -0,0 +1,21 @@
+nr = 1_000_000
+i = 0
+msg = '.'
+buf = '.'
+begin
+ r, w = IO.pipe
+ while i < nr
+ i += 1
+ w.write_nonblock(msg, exception: false)
+ r.read_nonblock(1, buf, exception: false)
+ end
+rescue ArgumentError # old Rubies
+ while i < nr
+ i += 1
+ w.write_nonblock(msg)
+ r.read_nonblock(1, buf)
+ end
+ensure
+ r.close
+ w.close
+end
diff --git a/benchmark/bm_io_pipe_rw.rb b/benchmark/bm_io_pipe_rw.rb
new file mode 100644
index 0000000000..6862a8ae61
--- /dev/null
+++ b/benchmark/bm_io_pipe_rw.rb
@@ -0,0 +1,13 @@
+# Measure uncontended GVL performance via read/write with 1:1 threading
+# If we switch to M:N threading, this will benchmark something else...
+r, w = IO.pipe
+src = '0'.freeze
+dst = String.new
+i = 0
+while i < 1_000_000
+ i += 1
+ w.write(src)
+ r.read(1, dst)
+end
+w.close
+r.close
diff --git a/benchmark/bm_io_select.rb b/benchmark/bm_io_select.rb
new file mode 100644
index 0000000000..19248daeb1
--- /dev/null
+++ b/benchmark/bm_io_select.rb
@@ -0,0 +1,9 @@
+# IO.select performance
+
+w = [ IO.pipe[1] ];
+
+nr = 1000000
+nr.times {
+ IO.select nil, w
+}
+
diff --git a/benchmark/bm_io_select2.rb b/benchmark/bm_io_select2.rb
new file mode 100644
index 0000000000..10e37d71b2
--- /dev/null
+++ b/benchmark/bm_io_select2.rb
@@ -0,0 +1,22 @@
+# IO.select performance. worst case of single fd.
+
+ios = []
+nr = 1000000
+if defined?(Process::RLIMIT_NOFILE)
+ max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
+else
+ max = 64
+end
+puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
+
+((max / 2) - 10).times do
+ ios.concat IO.pipe
+end
+
+last = [ ios[-1] ]
+puts "last IO: #{last[0].inspect}"
+
+nr.times do
+ IO.select nil, last
+end
+
diff --git a/benchmark/bm_io_select3.rb b/benchmark/bm_io_select3.rb
new file mode 100644
index 0000000000..7d0ba1f092
--- /dev/null
+++ b/benchmark/bm_io_select3.rb
@@ -0,0 +1,21 @@
+# IO.select performance. a lot of fd
+
+ios = []
+nr = 100
+if defined?(Process::RLIMIT_NOFILE)
+ max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
+else
+ max = 64
+end
+puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
+
+(max - 10).times do
+ r, w = IO.pipe
+ r.close
+ ios.push w
+end
+
+nr.times do
+ IO.select nil, ios
+end
+
diff --git a/benchmark/bm_loop_for.rb b/benchmark/bm_loop_for.rb
new file mode 100644
index 0000000000..0fc4cc1511
--- /dev/null
+++ b/benchmark/bm_loop_for.rb
@@ -0,0 +1,3 @@
+for i in 1..30_000_000
+ #
+end
diff --git a/benchmark/bm_loop_generator.rb b/benchmark/bm_loop_generator.rb
new file mode 100644
index 0000000000..d3375c744c
--- /dev/null
+++ b/benchmark/bm_loop_generator.rb
@@ -0,0 +1,14 @@
+max = 600000
+
+if defined? Fiber
+ gen = (1..max).each
+ loop do
+ gen.next
+ end
+else
+ require 'generator'
+ gen = Generator.new((0..max))
+ while gen.next?
+ gen.next
+ end
+end
diff --git a/benchmark/bm_loop_times.rb b/benchmark/bm_loop_times.rb
new file mode 100644
index 0000000000..521f72ad1a
--- /dev/null
+++ b/benchmark/bm_loop_times.rb
@@ -0,0 +1 @@
+30_000_000.times{|e|}
diff --git a/benchmark/bm_loop_whileloop.rb b/benchmark/bm_loop_whileloop.rb
new file mode 100644
index 0000000000..0072822c06
--- /dev/null
+++ b/benchmark/bm_loop_whileloop.rb
@@ -0,0 +1,4 @@
+i = 0
+while i<30_000_000 # benchmark loop 1
+ i += 1
+end
diff --git a/benchmark/bm_loop_whileloop2.rb b/benchmark/bm_loop_whileloop2.rb
new file mode 100644
index 0000000000..47d02dffc4
--- /dev/null
+++ b/benchmark/bm_loop_whileloop2.rb
@@ -0,0 +1,4 @@
+i = 0
+while i< 6_000_000 # benchmark loop 2
+ i += 1
+end
diff --git a/benchmark/bm_marshal_dump_flo.rb b/benchmark/bm_marshal_dump_flo.rb
new file mode 100644
index 0000000000..9b8d0c6afb
--- /dev/null
+++ b/benchmark/bm_marshal_dump_flo.rb
@@ -0,0 +1,2 @@
+bug10761 = 10000.times.map { |x| x.to_f }
+100.times { Marshal.dump(bug10761) }
diff --git a/benchmark/bm_marshal_dump_load_geniv.rb b/benchmark/bm_marshal_dump_load_geniv.rb
new file mode 100644
index 0000000000..8252ad90fa
--- /dev/null
+++ b/benchmark/bm_marshal_dump_load_geniv.rb
@@ -0,0 +1,10 @@
+a = ''
+a.instance_eval do
+ @a = :a
+ @b = :b
+ @c = :c
+end
+100000.times do
+ a = Marshal.load(Marshal.dump(a))
+end
+#p(a.instance_eval { @a == :a && @b == :b && @c == :c })
diff --git a/benchmark/bm_marshal_dump_load_time.rb b/benchmark/bm_marshal_dump_load_time.rb
new file mode 100644
index 0000000000..e29743b791
--- /dev/null
+++ b/benchmark/bm_marshal_dump_load_time.rb
@@ -0,0 +1 @@
+100000.times { Marshal.load(Marshal.dump(Time.now)) }
diff --git a/benchmark/bm_securerandom.rb b/benchmark/bm_securerandom.rb
new file mode 100644
index 0000000000..a082ea6d5b
--- /dev/null
+++ b/benchmark/bm_securerandom.rb
@@ -0,0 +1,5 @@
+require "securerandom"
+
+20_0000.times do
+ SecureRandom.random_number(100)
+end
diff --git a/benchmark/bm_so_ackermann.rb b/benchmark/bm_so_ackermann.rb
new file mode 100644
index 0000000000..7db5be9050
--- /dev/null
+++ b/benchmark/bm_so_ackermann.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+NUM = 9
+ack(3, NUM)
+
+
diff --git a/benchmark/bm_so_array.rb b/benchmark/bm_so_array.rb
new file mode 100644
index 0000000000..2b8fce8f99
--- /dev/null
+++ b/benchmark/bm_so_array.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# with help from Paul Brannan and Mark Hubbart
+
+n = 9000 # Integer(ARGV.shift || 1)
+
+x = Array.new(n)
+y = Array.new(n, 0)
+
+n.times{|bi|
+ x[bi] = bi + 1
+}
+
+(0 .. 999).each do |e|
+ (n-1).step(0,-1) do |bi|
+ y[bi] += x.at(bi)
+ end
+end
+# puts "#{y.first} #{y.last}"
+
+
diff --git a/benchmark/bm_so_binary_trees.rb b/benchmark/bm_so_binary_trees.rb
new file mode 100644
index 0000000000..b1693e4109
--- /dev/null
+++ b/benchmark/bm_so_binary_trees.rb
@@ -0,0 +1,62 @@
+# The Computer Language Shootout Benchmarks
+# http://shootout.alioth.debian.org
+#
+# contributed by Jesse Millikan
+
+# disable output
+alias puts_orig puts
+def puts str
+ # disable puts
+end
+
+def item_check(tree)
+ if tree[0] == nil
+ tree[1]
+ else
+ tree[1] + item_check(tree[0]) - item_check(tree[2])
+ end
+end
+
+def bottom_up_tree(item, depth)
+ if depth > 0
+ item_item = 2 * item
+ depth -= 1
+ [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
+ else
+ [nil, item, nil]
+ end
+end
+
+max_depth = 16 # ARGV[0].to_i
+min_depth = 4
+
+max_depth = min_depth + 2 if min_depth + 2 > max_depth
+
+stretch_depth = max_depth + 1
+stretch_tree = bottom_up_tree(0, stretch_depth)
+
+puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
+stretch_tree = nil
+
+long_lived_tree = bottom_up_tree(0, max_depth)
+
+min_depth.step(max_depth + 1, 2) do |depth|
+ iterations = 2**(max_depth - depth + min_depth)
+
+ check = 0
+
+ for i in 1..iterations
+ temp_tree = bottom_up_tree(i, depth)
+ check += item_check(temp_tree)
+
+ temp_tree = bottom_up_tree(-i, depth)
+ check += item_check(temp_tree)
+ end
+
+ puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
+end
+
+puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"
+
+undef puts
+alias puts puts_orig
diff --git a/benchmark/bm_so_concatenate.rb b/benchmark/bm_so_concatenate.rb
new file mode 100644
index 0000000000..873214de7c
--- /dev/null
+++ b/benchmark/bm_so_concatenate.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# based on code from Aristarkh A Zagorodnikov and Dat Nguyen
+
+STUFF = "hello\n"
+i = 0
+while i<10
+ i += 1
+ hello = ''
+ 4_000_000.times do |e|
+ hello << STUFF
+ end
+end
+# puts hello.length
+
+
diff --git a/benchmark/bm_so_exception.rb b/benchmark/bm_so_exception.rb
new file mode 100644
index 0000000000..deb003a594
--- /dev/null
+++ b/benchmark/bm_so_exception.rb
@@ -0,0 +1,61 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+$HI = 0
+$LO = 0
+NUM = 250000 # Integer(ARGV[0] || 1)
+
+
+class Lo_Exception < Exception
+ def initialize(num)
+ @value = num
+ end
+end
+
+class Hi_Exception < Exception
+ def initialize(num)
+ @value = num
+ end
+end
+
+def some_function(num)
+ begin
+ hi_function(num)
+ rescue
+ print "We shouldn't get here, exception is: #{$!.type}\n"
+ end
+end
+
+def hi_function(num)
+ begin
+ lo_function(num)
+ rescue Hi_Exception
+ $HI = $HI + 1
+ end
+end
+
+def lo_function(num)
+ begin
+ blowup(num)
+ rescue Lo_Exception
+ $LO = $LO + 1
+ end
+end
+
+def blowup(num)
+ if num % 2 == 0
+ raise Lo_Exception.new(num)
+ else
+ raise Hi_Exception.new(num)
+ end
+end
+
+
+i = 1
+max = NUM+1
+while i < max
+ i += 1
+ some_function(i+1)
+end
diff --git a/benchmark/bm_so_fannkuch.rb b/benchmark/bm_so_fannkuch.rb
new file mode 100644
index 0000000000..bac5ecd44c
--- /dev/null
+++ b/benchmark/bm_so_fannkuch.rb
@@ -0,0 +1,45 @@
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org/
+# Contributed by Sokolov Yura
+# Modified by Ryan Williams
+
+def fannkuch(n)
+ maxFlips, m, r, check = 0, n-1, n, 0
+ count = (1..n).to_a
+ perm = (1..n).to_a
+
+ while true
+ if check < 30
+ puts "#{perm}"
+ check += 1
+ end
+
+ while r != 1
+ count[r-1] = r
+ r -= 1
+ end
+
+ if perm[0] != 1 and perm[m] != n
+ perml = perm.clone #.dup
+ flips = 0
+ while (k = perml.first ) != 1
+ perml = perml.slice!(0, k).reverse + perml
+ flips += 1
+ end
+ maxFlips = flips if flips > maxFlips
+ end
+ while true
+ if r==n then return maxFlips end
+ perm.insert r,perm.shift
+ break if (count[r] -= 1) > 0
+ r += 1
+ end
+ end
+end
+
+def puts *args
+end
+
+N = 9 # (ARGV[0] || 1).to_i
+puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"
+
diff --git a/benchmark/bm_so_fasta.rb b/benchmark/bm_so_fasta.rb
new file mode 100644
index 0000000000..dcc6b39507
--- /dev/null
+++ b/benchmark/bm_so_fasta.rb
@@ -0,0 +1,81 @@
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org/
+# Contributed by Sokolov Yura
+
+$last = 42.0
+def gen_random(max, im=139968, ia=3877, ic=29573)
+ (max * ($last = ($last * ia + ic) % im)) / im
+end
+
+alu =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
+
+iub = [
+ ["a", 0.27],
+ ["c", 0.12],
+ ["g", 0.12],
+ ["t", 0.27],
+
+ ["B", 0.02],
+ ["D", 0.02],
+ ["H", 0.02],
+ ["K", 0.02],
+ ["M", 0.02],
+ ["N", 0.02],
+ ["R", 0.02],
+ ["S", 0.02],
+ ["V", 0.02],
+ ["W", 0.02],
+ ["Y", 0.02],
+]
+homosapiens = [
+ ["a", 0.3029549426680],
+ ["c", 0.1979883004921],
+ ["g", 0.1975473066391],
+ ["t", 0.3015094502008],
+]
+
+def make_repeat_fasta(id, desc, src, n)
+ puts ">#{id} #{desc}"
+ v = nil
+ width = 60
+ l = src.length
+ s = src * ((n / l) + 1)
+ s.slice!(n, l)
+ puts(s.scan(/.{1,#{width}}/).join("\n"))
+end
+
+def make_random_fasta(id, desc, table, n)
+ puts ">#{id} #{desc}"
+ rand, v = nil,nil
+ width = 60
+ chunk = 1 * width
+ prob = 0.0
+ table.each{|v| v[1]= (prob += v[1])}
+ for i in 1..(n/width)
+ puts((1..width).collect{
+ rand = gen_random(1.0)
+ table.find{|v| v[1]>rand}[0]
+ }.join)
+ end
+ if n%width != 0
+ puts((1..(n%width)).collect{
+ rand = gen_random(1.0)
+ table.find{|v| v[1]>rand}[0]
+ }.join)
+ end
+end
+
+
+n = (ARGV[0] or 250_000).to_i
+
+make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
+make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
+make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
+
diff --git a/benchmark/bm_so_lists.rb b/benchmark/bm_so_lists.rb
new file mode 100644
index 0000000000..e8f4a2a5f7
--- /dev/null
+++ b/benchmark/bm_so_lists.rb
@@ -0,0 +1,47 @@
+#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
+
+NUM = 300
+SIZE = 10000
+
+def test_lists()
+ # create a list of integers (Li1) from 1 to SIZE
+ li1 = (1..SIZE).to_a
+ # copy the list to li2 (not by individual items)
+ li2 = li1.dup
+ # remove each individual item from left side of li2 and
+ # append to right side of li3 (preserving order)
+ li3 = Array.new
+ while (not li2.empty?)
+ li3.push(li2.shift)
+ end
+ # li2 must now be empty
+ # remove each individual item from right side of li3 and
+ # append to right side of li2 (reversing list)
+ while (not li3.empty?)
+ li2.push(li3.pop)
+ end
+ # li3 must now be empty
+ # reverse li1 in place
+ li1.reverse!
+ # check that first item is now SIZE
+ if li1[0] != SIZE then
+ p "not SIZE"
+ 0
+ else
+ # compare li1 and li2 for equality
+ if li1 != li2 then
+ return(0)
+ else
+ # return the length of the list
+ li1.length
+ end
+ end
+end
+
+i = 0
+while i<NUM
+ i += 1
+ result = test_lists()
+end
+
+result
diff --git a/benchmark/bm_so_mandelbrot.rb b/benchmark/bm_so_mandelbrot.rb
new file mode 100644
index 0000000000..76331c64b8
--- /dev/null
+++ b/benchmark/bm_so_mandelbrot.rb
@@ -0,0 +1,57 @@
+# The Computer Language Benchmarks Game
+# http://shootout.alioth.debian.org/
+#
+# contributed by Karl von Laudermann
+# modified by Jeremy Echols
+
+size = 600 # ARGV[0].to_i
+
+puts "P4\n#{size} #{size}"
+
+ITER = 49 # Iterations - 1 for easy for..in looping
+LIMIT_SQUARED = 4.0 # Presquared limit
+
+byte_acc = 0
+bit_num = 0
+
+count_size = size - 1 # Precomputed size for easy for..in looping
+
+# For..in loops are faster than .upto, .downto, .times, etc.
+for y in 0..count_size
+ for x in 0..count_size
+ zr = 0.0
+ zi = 0.0
+ cr = (2.0*x/size)-1.5
+ ci = (2.0*y/size)-1.0
+ escape = false
+
+ # To make use of the for..in code, we use a dummy variable,
+ # like one would in C
+ for dummy in 0..ITER
+ tr = zr*zr - zi*zi + cr
+ ti = 2*zr*zi + ci
+ zr, zi = tr, ti
+
+ if (zr*zr+zi*zi) > LIMIT_SQUARED
+ escape = true
+ break
+ end
+ end
+
+ byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
+ bit_num += 1
+
+ # Code is very similar for these cases, but using separate blocks
+ # ensures we skip the shifting when it's unnecessary, which is most cases.
+ if (bit_num == 8)
+ print byte_acc.chr
+ byte_acc = 0
+ bit_num = 0
+ elsif (x == count_size)
+ byte_acc <<= (8 - bit_num)
+ print byte_acc.chr
+ byte_acc = 0
+ bit_num = 0
+ end
+ end
+end
diff --git a/benchmark/bm_so_matrix.rb b/benchmark/bm_so_matrix.rb
new file mode 100644
index 0000000000..e2c5c8e559
--- /dev/null
+++ b/benchmark/bm_so_matrix.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+n = 60 #Integer(ARGV.shift || 1)
+
+size = 40
+
+def mkmatrix(rows, cols)
+ count = 1
+ mx = Array.new(rows)
+ (0 .. (rows - 1)).each do |bi|
+ row = Array.new(cols, 0)
+ (0 .. (cols - 1)).each do |j|
+ row[j] = count
+ count += 1
+ end
+ mx[bi] = row
+ end
+ mx
+end
+
+def mmult(rows, cols, m1, m2)
+ m3 = Array.new(rows)
+ (0 .. (rows - 1)).each do |bi|
+ row = Array.new(cols, 0)
+ (0 .. (cols - 1)).each do |j|
+ val = 0
+ (0 .. (cols - 1)).each do |k|
+ val += m1.at(bi).at(k) * m2.at(k).at(j)
+ end
+ row[j] = val
+ end
+ m3[bi] = row
+ end
+ m3
+end
+
+m1 = mkmatrix(size, size)
+m2 = mkmatrix(size, size)
+mm = Array.new
+n.times do
+ mm = mmult(size, size, m1, m2)
+end
+# puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"
+
+
diff --git a/benchmark/bm_so_meteor_contest.rb b/benchmark/bm_so_meteor_contest.rb
new file mode 100755
index 0000000000..8c136baa6c
--- /dev/null
+++ b/benchmark/bm_so_meteor_contest.rb
@@ -0,0 +1,563 @@
+#!/usr/bin/env ruby
+#
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org
+# contributed by Kevin Barnes (Ruby novice)
+
+# PROGRAM: the main body is at the bottom.
+# 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
+# 2) see how I represent a board as a bitmask by reading the blank_board comments
+# 3) read as your mental paths take you
+
+def print *args
+end
+
+# class to represent all information about a particular rotation of a particular piece
+class Rotation
+ # an array (by location) containing a bit mask for how the piece maps at the given location.
+ # if the rotation is invalid at that location the mask will contain false
+ attr_reader :start_masks
+
+ # maps a direction to a relative location. these differ depending on whether it is an even or
+ # odd row being mapped from
+ @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 }
+ @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 }
+
+ def initialize( directions )
+ @even_offsets, @odd_offsets = normalize_offsets( get_values( directions ))
+
+ @even_mask = mask_for_offsets( @even_offsets)
+ @odd_mask = mask_for_offsets( @odd_offsets)
+
+ @start_masks = Array.new(60)
+
+ # create the rotational masks by placing the base mask at the location and seeing if
+ # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these
+ # is true the piece cannot be placed
+ 0.upto(59) do | offset |
+ mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset)
+ if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then
+ imask = compute_required( mask, offset)
+ @start_masks[offset] = [ mask, imask, imask | mask ]
+ else
+ @start_masks[offset] = false
+ end
+ end
+ end
+
+ def compute_required( mask, offset )
+ board = blank_board
+ 0.upto(offset) { | i | board |= 1 << i }
+ board |= mask
+ return 0 if (!prunable(board | mask, offset))
+ board = flood_fill(board,58)
+ count = 0
+ imask = 0
+ 0.upto(59) do | i |
+ if (board[i] == 0) then
+ imask |= (1 << i)
+ count += 1
+ end
+ end
+ (count > 0 && count < 5) ? imask : 0
+ end
+
+ def flood_fill( board, location)
+ return board if (board[location] == 1)
+ board |= 1 << location
+ row, col = location.divmod(6)
+ board = flood_fill( board, location - 1) if (col > 0)
+ board = flood_fill( board, location + 1) if (col < 4)
+ if (row % 2 == 0) then
+ board = flood_fill( board, location - 7) if (col > 0 && row > 0)
+ board = flood_fill( board, location - 6) if (row > 0)
+ board = flood_fill( board, location + 6) if (row < 9)
+ board = flood_fill( board, location + 5) if (col > 0 && row < 9)
+ else
+ board = flood_fill( board, location - 5) if (col < 4 && row > 0)
+ board = flood_fill( board, location - 6) if (row > 0)
+ board = flood_fill( board, location + 6) if (row < 9)
+ board = flood_fill( board, location + 7) if (col < 4 && row < 9)
+ end
+ board
+ end
+
+ # given a location, produces a list of relative locations covered by the piece at this rotation
+ def offsets( location)
+ if is_even( location) then
+ @even_offsets.collect { | value | value + location }
+ else
+ @odd_offsets.collect { | value | value + location }
+ end
+ end
+
+ # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows)
+ # this is hard to explain. imagine we have this partial board:
+ # 0 0 0 0 0 x [positions 0-5]
+ # 0 0 1 1 0 x [positions 6-11]
+ # 0 0 1 0 0 x [positions 12-17]
+ # 0 1 0 0 0 x [positions 18-23]
+ # 0 1 0 0 0 x [positions 24-29]
+ # 0 0 0 0 0 x [positions 30-35]
+ # ...
+ # The top-left of the piece is at position 8, the
+ # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that
+ # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained
+ # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row:
+ # 0 0 0 1 1 x [positions 0-5]
+ # 0 0 1 0 0 x [positions 6-11]
+ # 0 0 1 0 0 x [positions 12-17]
+ # 0 1 0 0 0 x [positions 18-23]
+ # 0 0 0 0 0 x [positions 24-29]
+ # 0 0 0 0 0 x [positions 30-35]
+ # ...
+ # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the
+ # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what
+ # this function would return
+ def normalize_offsets( values)
+ min = values.min
+ even_min = is_even(min)
+ other_min = even_min ? min + 6 : min + 7
+ other_values = values.collect do | value |
+ if is_even(value) then
+ value + 6 - other_min
+ else
+ value + 7 - other_min
+ end
+ end
+ values.collect! { | value | value - min }
+
+ if even_min then
+ [values, other_values]
+ else
+ [other_values, values]
+ end
+ end
+
+ # produce a bitmask representation of an array of offset locations
+ def mask_for_offsets( offsets )
+ mask = 0
+ offsets.each { | value | mask = mask + ( 1 << value ) }
+ mask
+ end
+
+ # finds a "safe" position that a position as described by a list of directions can be placed
+ # without falling off any edge of the board. the values returned a location to place the first piece
+ # at so it will fit after making the described moves
+ def start_adjust( directions )
+ south = east = 0;
+ directions.each do | direction |
+ east += 1 if ( direction == :sw || direction == :nw || direction == :west )
+ south += 1 if ( direction == :nw || direction == :ne )
+ end
+ south * 6 + east
+ end
+
+ # given a set of directions places the piece (as defined by a set of directions) on the board at
+ # a location that will not take it off the edge
+ def get_values( directions )
+ start = start_adjust(directions)
+ values = [ start ]
+ directions.each do | direction |
+ if (start % 12 >= 6) then
+ start += @@rotation_odd_adder[direction]
+ else
+ start += @@rotation_even_adder[direction]
+ end
+ values += [ start ]
+ end
+
+ # some moves take you back to an existing location, we'll strip duplicates
+ values.uniq
+ end
+end
+
+# describes a piece and caches information about its rotations to as to be efficient for iteration
+# ATTRIBUTES:
+# rotations -- all the rotations of the piece
+# type -- a numeic "name" of the piece
+# masks -- an array by location of all legal rotational masks (a n inner array) for that location
+# placed -- the mask that this piece was last placed at (not a location, but the actual mask used)
+class Piece
+ attr_reader :rotations, :type, :masks
+ attr_accessor :placed
+
+ # transform hashes that change one direction into another when you either flip or rotate a set of directions
+ @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne }
+ @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw }
+
+ def initialize( directions, type )
+ @type = type
+ @rotations = Array.new();
+ @map = {}
+
+ generate_rotations( directions )
+ directions.collect! { | value | @@flip_converter[value] }
+ generate_rotations( directions )
+
+ # creates the masks AND a map that returns [location, rotation] for any given mask
+ # this is used when a board is found and we want to draw it, otherwise the map is unused
+ @masks = Array.new();
+ 0.upto(59) do | i |
+ even = true
+ @masks[i] = @rotations.collect do | rotation |
+ mask = rotation.start_masks[i]
+ @map[mask[0]] = [ i, rotation ] if (mask)
+ mask || nil
+ end
+ @masks[i].compact!
+ end
+ end
+
+ # rotates a set of directions through all six angles and adds a Rotation to the list for each one
+ def generate_rotations( directions )
+ 6.times do
+ rotations.push( Rotation.new(directions))
+ directions.collect! { | value | @@rotate_converter[value] }
+ end
+ end
+
+ # given a board string, adds this piece to the board at whatever location/rotation
+ # important: the outbound board string is 5 wide, the normal location notation is six wide (padded)
+ def fill_string( board_string)
+ location, rotation = @map[@placed]
+ rotation.offsets(location).each do | offset |
+ row, col = offset.divmod(6)
+ board_string[ row*5 + col, 1 ] = @type.to_s
+ end
+ end
+end
+
+# a blank bit board having this form:
+#
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 0 0 0 0 0 1
+# 1 1 1 1 1 1
+#
+# where left lest significant bit is the top left and the most significant is the lower right
+# the actual board only consists of the 0 places, the 1 places are blockers to keep things from running
+# off the edges or bottom
+def blank_board
+ 0b111111100000100000100000100000100000100000100000100000100000100000
+end
+
+def full_board
+ 0b111111111111111111111111111111111111111111111111111111111111111111
+end
+
+# determines if a location (bit position) is in an even row
+def is_even( location)
+ (location % 12) < 6
+end
+
+# support function that create three utility maps:
+# $converter -- for each row an array that maps a five bit row (via array mapping)
+# to the a five bit representation of the bits below it
+# $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row
+# @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays
+# a region array has three values the first is a mask of bits in the region,
+# the second is the count of those bits and the third is identical to the first
+# examples:
+# 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001]
+# 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001]
+# 0b10001 => [ 0b01110, 3, 0b01110 ]
+def create_collector_support
+ odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000]
+ even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000]
+
+ all_odds = Array.new(0b100000)
+ all_evens = Array.new(0b100000)
+ bit_counts = Array.new(0b100000)
+ new_regions = Array.new(0b100000)
+ 0.upto(0b11111) do | i |
+ bit_count = odd = even = 0
+ 0.upto(4) do | bit |
+ if (i[bit] == 1) then
+ bit_count += 1
+ odd |= odd_map[bit]
+ even |= even_map[bit]
+ end
+ end
+ all_odds[i] = odd
+ all_evens[i] = even
+ bit_counts[i] = bit_count
+ new_regions[i] = create_regions( i)
+ end
+
+ $converter = []
+ 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) }
+ $bit_counts = bit_counts
+ $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } }
+end
+
+# determines if a board is punable, meaning that there is no possibility that it
+# can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces
+# that are not a multiple of five. The following board is an example of a prunable board:
+# 0 0 1 0 0
+# 0 1 0 0 0
+# 1 1 0 0 0
+# 0 1 0 0 0
+# 0 0 0 0 0
+# ...
+#
+# This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it
+# parameters:
+# board -- an initial bit board (6 bit padded rows, see blank_board for format)
+# location -- starting location, everything above and to the left is already full
+# slotting -- set to true only when testing initial pieces, when filling normally
+# additional assumptions are possible
+#
+# Algorithm:
+# The algorithm starts at the top row (as determined by location) and iterates a row at a time
+# maintainng counts of active open areas (kept in the collector array) each collector contains
+# three values at the start of an iteration:
+# 0: mask of bits that would be adjacent to the collector in this row
+# 1: the number of bits collected so far
+# 2: a scratch space starting as zero, but used during the computation to represent
+# the empty bits in the new row that are adjacent (position 0)
+# The exact procedure is described in-code
+def prunable( board, location, slotting = false)
+ collectors = []
+ # loop across the rows
+ (location / 6).to_i.upto(9) do | row_on |
+ # obtain a set of regions representing the bits of the current row.
+ regions = $regions[(board >> (row_on * 6)) & 0b11111]
+ converter = $converter[row_on]
+
+ # track the number of collectors at the start of the cycle so that
+ # we don't compute against newly created collectors, only existing collectors
+ initial_collector_count = collectors.length
+
+ # loop against the regions. For each region of the row
+ # we will see if it connects to one or more existing collectors.
+ # if it connects to 1 collector, the bits from the region are added to the
+ # bits of the collector and the mask is placed in collector[2]
+ # If the region overlaps more than one collector then all the collectors
+ # it overlaps with are merged into the first one (the others are set to nil in the array)
+ # if NO collectors are found then the region is copied as a new collector
+ regions.each do | region |
+ collector_found = nil
+ region_mask = region[2]
+ initial_collector_count.times do | collector_num |
+ collector = collectors[collector_num]
+ if (collector) then
+ collector_mask = collector[0]
+ if (collector_mask & region_mask != 0) then
+ if (collector_found) then
+ collector_found[0] |= collector_mask
+ collector_found[1] += collector[1]
+ collector_found[2] |= collector[2]
+ collectors[collector_num] = nil
+ else
+ collector_found = collector
+ collector[1] += region[1]
+ collector[2] |= region_mask
+ end
+ end
+ end
+ end
+ if (collector_found == nil) then
+ collectors.push(Array.new(region))
+ end
+ end
+
+ # check the existing collectors, if any collector overlapped no bits in the region its [2] value will
+ # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since
+ # the board is prunable. if it is a multiple of five it is removed.
+ # Collector that are still active have a new adjacent value [0] set based n the matched bits
+ # and have [2] cleared out for the next cycle.
+ collectors.length.times do | collector_num |
+ collector = collectors[collector_num]
+ if (collector) then
+ if (collector[2] == 0) then
+ return true if (collector[1] % 5 != 0)
+ collectors[collector_num] = nil
+ else
+ # if a collector matches all bits in the row then we can return unprunable early for the
+ # following reasons:
+ # 1) there can be no more unavailable bits bince we fill from the top left downward
+ # 2) all previous regions have been closed or joined so only this region can fail
+ # 3) this region must be good since there can never be only 1 region that is nuot
+ # a multiple of five
+ # this rule only applies when filling normally, so we ignore the rule if we are "slotting"
+ # in pieces to see what configurations work for them (the only other time this algorithm is used).
+ return false if (collector[2] == 0b11111 && !slotting)
+ collector[0] = converter[collector[2]]
+ collector[2] = 0
+ end
+ end
+ end
+
+ # get rid of all the empty converters for the next round
+ collectors.compact!
+ end
+ return false if (collectors.length <= 1) # 1 collector or less and the region is fine
+ collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size
+end
+
+# creates a region given a row mask. see prunable for what a "region" is
+def create_regions( value )
+ regions = []
+ cur_region = 0
+ 5.times do | bit |
+ if (value[bit] == 0) then
+ cur_region |= 1 << bit
+ else
+ if (cur_region != 0 ) then
+ regions.push( cur_region)
+ cur_region = 0;
+ end
+ end
+ end
+ regions.push(cur_region) if (cur_region != 0)
+ regions
+end
+
+# find up to the counted number of solutions (or all solutions) and prints the final result
+def find_all
+ find_top( 1)
+ find_top( 0)
+ print_results
+end
+
+# show the board
+def print_results
+ print "#{@boards_found} solutions found\n\n"
+ print_full_board( @min_board)
+ print "\n"
+ print_full_board( @max_board)
+ print "\n"
+end
+
+# finds solutions. This special version of the main function is only used for the top level
+# the reason for it is basically to force a particular ordering on how the rotations are tested for
+# the first piece. It is called twice, first looking for placements of the odd rotations and then
+# looking for placements of the even locations.
+#
+# WHY?
+# Since any found solution has an inverse we want to maximize finding solutions that are not already found
+# as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away
+# (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier
+# in the cycle. We still need to keep checking all the permutations, but our probability of finding one will
+# diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces
+# this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the
+# maximum number
+def find_top( rotation_skip)
+ board = blank_board
+ (@pieces.length-1).times do
+ piece = @pieces.shift
+ piece.masks[0].each do | mask, imask, cmask |
+ if ((rotation_skip += 1) % 2 == 0) then
+ piece.placed = mask
+ find( 1, 1, board | mask)
+ end
+ end
+ @pieces.push(piece)
+ end
+ piece = @pieces.shift
+ @pieces.push(piece)
+end
+
+# the normail find routine, iterates through the available pieces, checks all rotations at the current location
+# and adds any boards found. depth is achieved via recursion. the overall approach is described
+# here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
+# parameters:
+# start_location -- where to start looking for place for the next piece at
+# placed -- number of pieces placed
+# board -- current state of the board
+#
+# see in-code comments
+def find( start_location, placed, board)
+ # find the next location to place a piece by looking for an empty bit
+ while board[start_location] == 1
+ start_location += 1
+ end
+
+ @pieces.length.times do
+ piece = @pieces.shift
+ piece.masks[start_location].each do | mask, imask, cmask |
+ if ( board & cmask == imask) then
+ piece.placed = mask
+ if (placed == 9) then
+ add_board
+ else
+ find( start_location + 1, placed + 1, board | mask)
+ end
+ end
+ end
+ @pieces.push(piece)
+ end
+end
+
+# print the board
+def print_full_board( board_string)
+ 10.times do | row |
+ print " " if (row % 2 == 1)
+ 5.times do | col |
+ print "#{board_string[row*5 + col,1]} "
+ end
+ print "\n"
+ end
+end
+
+# when a board is found we "draw it" into a string and then flip that string, adding both to
+# the list (hash) of solutions if they are unique.
+def add_board
+ board_string = "99999999999999999999999999999999999999999999999999"
+ @all_pieces.each { | piece | piece.fill_string( board_string ) }
+ save( board_string)
+ save( board_string.reverse)
+end
+
+# adds a board string to the list (if new) and updates the current best/worst board
+def save( board_string)
+ if (@all_boards[board_string] == nil) then
+ @min_board = board_string if (board_string < @min_board)
+ @max_board = board_string if (board_string > @max_board)
+ @all_boards.store(board_string,true)
+ @boards_found += 1
+
+ # the exit motif is a time saver. Ideally the function should return, but those tests
+ # take noticeable time (performance).
+ if (@boards_found == @stop_count) then
+ print_results
+ exit(0)
+ end
+ end
+end
+
+
+##
+## MAIN BODY :)
+##
+create_collector_support
+@pieces = [
+ Piece.new( [ :nw, :ne, :east, :east ], 2),
+ Piece.new( [ :ne, :se, :east, :ne ], 7),
+ Piece.new( [ :ne, :east, :ne, :nw ], 1),
+ Piece.new( [ :east, :sw, :sw, :se ], 6),
+ Piece.new( [ :east, :ne, :se, :ne ], 5),
+ Piece.new( [ :east, :east, :east, :se ], 0),
+ Piece.new( [ :ne, :nw, :se, :east, :se ], 4),
+ Piece.new( [ :se, :se, :se, :west ], 9),
+ Piece.new( [ :se, :se, :east, :se ], 8),
+ Piece.new( [ :east, :east, :sw, :se ], 3)
+ ];
+
+@all_pieces = Array.new( @pieces)
+
+@min_board = "99999999999999999999999999999999999999999999999999"
+@max_board = "00000000000000000000000000000000000000000000000000"
+@stop_count = ARGV[0].to_i || 2089
+@all_boards = {}
+@boards_found = 0
+
+find_all ######## DO IT!!!
diff --git a/benchmark/bm_so_nbody.rb b/benchmark/bm_so_nbody.rb
new file mode 100644
index 0000000000..d6c5bb9e61
--- /dev/null
+++ b/benchmark/bm_so_nbody.rb
@@ -0,0 +1,148 @@
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org
+#
+# Optimized for Ruby by Jesse Millikan
+# From version ported by Michael Neumann from the C gcc version,
+# which was written by Christoph Bauer.
+
+SOLAR_MASS = 4 * Math::PI**2
+DAYS_PER_YEAR = 365.24
+
+def _puts *args
+end
+
+class Planet
+ attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass
+
+ def initialize(x, y, z, vx, vy, vz, mass)
+ @x, @y, @z = x, y, z
+ @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
+ @mass = mass * SOLAR_MASS
+ end
+
+ def move_from_i(bodies, nbodies, dt, i)
+ while i < nbodies
+ b2 = bodies[i]
+ dx = @x - b2.x
+ dy = @y - b2.y
+ dz = @z - b2.z
+
+ distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
+ mag = dt / (distance * distance * distance)
+ b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag
+
+ @vx -= dx * b2_mass_mag
+ @vy -= dy * b2_mass_mag
+ @vz -= dz * b2_mass_mag
+ b2.vx += dx * b_mass_mag
+ b2.vy += dy * b_mass_mag
+ b2.vz += dz * b_mass_mag
+ i += 1
+ end
+
+ @x += dt * @vx
+ @y += dt * @vy
+ @z += dt * @vz
+ end
+end
+
+def energy(bodies)
+ e = 0.0
+ nbodies = bodies.size
+
+ for i in 0 ... nbodies
+ b = bodies[i]
+ e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
+ for j in (i + 1) ... nbodies
+ b2 = bodies[j]
+ dx = b.x - b2.x
+ dy = b.y - b2.y
+ dz = b.z - b2.z
+ distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
+ e -= (b.mass * b2.mass) / distance
+ end
+ end
+ e
+end
+
+def offset_momentum(bodies)
+ px, py, pz = 0.0, 0.0, 0.0
+
+ for b in bodies
+ m = b.mass
+ px += b.vx * m
+ py += b.vy * m
+ pz += b.vz * m
+ end
+
+ b = bodies[0]
+ b.vx = - px / SOLAR_MASS
+ b.vy = - py / SOLAR_MASS
+ b.vz = - pz / SOLAR_MASS
+end
+
+BODIES = [
+ # sun
+ Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
+
+ # jupiter
+ Planet.new(
+ 4.84143144246472090e+00,
+ -1.16032004402742839e+00,
+ -1.03622044471123109e-01,
+ 1.66007664274403694e-03,
+ 7.69901118419740425e-03,
+ -6.90460016972063023e-05,
+ 9.54791938424326609e-04),
+
+ # saturn
+ Planet.new(
+ 8.34336671824457987e+00,
+ 4.12479856412430479e+00,
+ -4.03523417114321381e-01,
+ -2.76742510726862411e-03,
+ 4.99852801234917238e-03,
+ 2.30417297573763929e-05,
+ 2.85885980666130812e-04),
+
+ # uranus
+ Planet.new(
+ 1.28943695621391310e+01,
+ -1.51111514016986312e+01,
+ -2.23307578892655734e-01,
+ 2.96460137564761618e-03,
+ 2.37847173959480950e-03,
+ -2.96589568540237556e-05,
+ 4.36624404335156298e-05),
+
+ # neptune
+ Planet.new(
+ 1.53796971148509165e+01,
+ -2.59193146099879641e+01,
+ 1.79258772950371181e-01,
+ 2.68067772490389322e-03,
+ 1.62824170038242295e-03,
+ -9.51592254519715870e-05,
+ 5.15138902046611451e-05)
+]
+
+init = 200_000 # ARGV[0]
+n = Integer(init)
+
+offset_momentum(BODIES)
+
+puts "%.9f" % energy(BODIES)
+
+nbodies = BODIES.size
+dt = 0.01
+
+n.times do
+ i = 0
+ while i < nbodies
+ b = BODIES[i]
+ b.move_from_i(BODIES, nbodies, dt, i + 1)
+ i += 1
+ end
+end
+
+puts "%.9f" % energy(BODIES)
diff --git a/benchmark/bm_so_nested_loop.rb b/benchmark/bm_so_nested_loop.rb
new file mode 100644
index 0000000000..a0513f8c47
--- /dev/null
+++ b/benchmark/bm_so_nested_loop.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# from Avi Bryant
+
+n = 16 # Integer(ARGV.shift || 1)
+x = 0
+n.times do
+ n.times do
+ n.times do
+ n.times do
+ n.times do
+ n.times do
+ x += 1
+ end
+ end
+ end
+ end
+ end
+end
+# puts x
+
+
diff --git a/benchmark/bm_so_nsieve.rb b/benchmark/bm_so_nsieve.rb
new file mode 100644
index 0000000000..a65cc78233
--- /dev/null
+++ b/benchmark/bm_so_nsieve.rb
@@ -0,0 +1,35 @@
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org/
+#
+# contributed by Glenn Parker, March 2005
+# modified by Evan Phoenix, Sept 2006
+
+def sieve(m)
+ flags = Flags.dup[0,m]
+ count = 0
+ pmax = m - 1
+ p = 2
+ while p <= pmax
+ unless flags[p].zero?
+ count += 1
+ mult = p
+ while mult <= pmax
+ flags[mult] = 0
+ mult += p
+ end
+ end
+ p += 1
+ end
+ count
+end
+
+n = 9 # (ARGV[0] || 2).to_i
+Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*")
+
+n.downto(n-2) do |exponent|
+ break if exponent < 0
+ m = (1 << exponent) * 10_000
+ # m = (2 ** exponent) * 10_000
+ count = sieve(m)
+ printf "Primes up to %8d %8d\n", m, count
+end
diff --git a/benchmark/bm_so_nsieve_bits.rb b/benchmark/bm_so_nsieve_bits.rb
new file mode 100644
index 0000000000..6f958ee44e
--- /dev/null
+++ b/benchmark/bm_so_nsieve_bits.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+#coding: us-ascii
+#
+# The Great Computer Language Shootout
+# http://shootout.alioth.debian.org/
+#
+# nsieve-bits in Ruby
+# Contributed by Glenn Parker, March 2005
+
+CharExponent = 3
+BitsPerChar = 1 << CharExponent
+LowMask = BitsPerChar - 1
+
+def sieve(m)
+ items = "\xFF" * ((m / BitsPerChar) + 1)
+ masks = ""
+ BitsPerChar.times do |b|
+ masks << (1 << b).chr
+ end
+
+ count = 0
+ pmax = m - 1
+ 2.step(pmax, 1) do |p|
+ if items[p >> CharExponent][p & LowMask] == 1
+ count += 1
+ p.step(pmax, p) do |mult|
+ a = mult >> CharExponent
+ b = mult & LowMask
+ items[a] -= masks[b] if items[a][b] != 0
+ end
+ end
+ end
+ count
+end
+
+n = 9 # (ARGV[0] || 2).to_i
+n.step(n - 2, -1) do |exponent|
+ break if exponent < 0
+ m = 2 ** exponent * 10_000
+ count = sieve(m)
+ printf "Primes up to %8d %8d\n", m, count
+end
+
diff --git a/benchmark/bm_so_object.rb b/benchmark/bm_so_object.rb
new file mode 100644
index 0000000000..e8607c7199
--- /dev/null
+++ b/benchmark/bm_so_object.rb
@@ -0,0 +1,56 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# with help from Aristarkh Zagorodnikov
+
+class Toggle
+ def initialize(start_state)
+ @bool = start_state
+ end
+
+ def value
+ @bool
+ end
+
+ def activate
+ @bool = !@bool
+ self
+ end
+end
+
+class NthToggle < Toggle
+ def initialize(start_state, max_counter)
+ super start_state
+ @count_max = max_counter
+ @counter = 0
+ end
+
+ def activate
+ @counter += 1
+ if @counter >= @count_max
+ @bool = !@bool
+ @counter = 0
+ end
+ self
+ end
+end
+
+n = 1500000 # (ARGV.shift || 1).to_i
+
+toggle = Toggle.new 1
+5.times do
+ toggle.activate.value ? 'true' : 'false'
+end
+n.times do
+ toggle = Toggle.new 1
+end
+
+ntoggle = NthToggle.new 1, 3
+8.times do
+ ntoggle.activate.value ? 'true' : 'false'
+end
+n.times do
+ ntoggle = NthToggle.new 1, 3
+end
+
diff --git a/benchmark/bm_so_partial_sums.rb b/benchmark/bm_so_partial_sums.rb
new file mode 100644
index 0000000000..630b45cb8d
--- /dev/null
+++ b/benchmark/bm_so_partial_sums.rb
@@ -0,0 +1,31 @@
+n = 2_500_000 # (ARGV.shift || 1).to_i
+
+alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0
+
+1.upto(n) do |d|
+ d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)
+
+ s0 += (2.0 / 3.0) ** (d - 1.0)
+ s1 += 1.0 / Math.sqrt(d)
+ s2 += 1.0 / (d * (d + 1.0))
+ s3 += 1.0 / (d3 * ds * ds)
+ s4 += 1.0 / (d3 * dc * dc)
+ s5 += 1.0 / d
+ s6 += 1.0 / d2
+ s7 += alt / d
+ s8 += alt / (2.0 * d - 1.0)
+
+ alt = -alt
+end
+
+if false
+ printf("%.9f\t(2/3)^k\n", s0)
+ printf("%.9f\tk^-0.5\n", s1)
+ printf("%.9f\t1/k(k+1)\n", s2)
+ printf("%.9f\tFlint Hills\n", s3)
+ printf("%.9f\tCookson Hills\n", s4)
+ printf("%.9f\tHarmonic\n", s5)
+ printf("%.9f\tRiemann Zeta\n", s6)
+ printf("%.9f\tAlternating Harmonic\n", s7)
+ printf("%.9f\tGregory\n", s8)
+end
diff --git a/benchmark/bm_so_pidigits.rb b/benchmark/bm_so_pidigits.rb
new file mode 100644
index 0000000000..9a537b2d1c
--- /dev/null
+++ b/benchmark/bm_so_pidigits.rb
@@ -0,0 +1,92 @@
+# The Great Computer Language Shootout
+# http://shootout.alioth.debian.org/
+#
+# contributed by Gabriele Renzi
+
+class PiDigitSpigot
+
+ def initialize()
+ @z = Transformation.new 1,0,0,1
+ @x = Transformation.new 0,0,0,0
+ @inverse = Transformation.new 0,0,0,0
+ end
+
+ def next!
+ @y = @z.extract(3)
+ if safe? @y
+ @z = produce(@y)
+ @y
+ else
+ @z = consume @x.next!()
+ next!()
+ end
+ end
+
+ def safe?(digit)
+ digit == @z.extract(4)
+ end
+
+ def produce(i)
+ @inverse.qrst(10,-10*i,0,1).compose(@z)
+ end
+
+ def consume(a)
+ @z.compose(a)
+ end
+end
+
+
+class Transformation
+ attr_reader :q, :r, :s, :t
+ def initialize(q, r, s, t)
+ @q,@r,@s,@t,@k = q,r,s,t,0
+ end
+
+ def next!()
+ @q = @k = @k + 1
+ @r = 4 * @k + 2
+ @s = 0
+ @t = 2 * @k + 1
+ self
+ end
+
+ def extract(j)
+ (@q * j + @r) / (@s * j + @t)
+ end
+
+ def compose(a)
+ self.class.new( @q * a.q,
+ @q * a.r + r * a.t,
+ @s * a.q + t * a.s,
+ @s * a.r + t * a.t
+ )
+ end
+
+ def qrst *args
+ initialize *args
+ self
+ end
+
+
+end
+
+
+WIDTH = 10
+n = 2_500 # Integer(ARGV[0])
+j = 0
+
+digits = PiDigitSpigot.new
+
+while n > 0
+ if n >= WIDTH
+ WIDTH.times {print digits.next!}
+ j += WIDTH
+ else
+ n.times {print digits.next!}
+ (WIDTH-n).times {print " "}
+ j += n
+ end
+ puts "\t:"+j.to_s
+ n -= WIDTH
+end
+
diff --git a/benchmark/bm_so_random.rb b/benchmark/bm_so_random.rb
new file mode 100644
index 0000000000..a66b9e8e63
--- /dev/null
+++ b/benchmark/bm_so_random.rb
@@ -0,0 +1,20 @@
+# from http://www.bagley.org/~doug/shootout/bench/random/random.ruby
+
+IM = 139968.0
+IA = 3877.0
+IC = 29573.0
+
+$last = 42.0
+
+def gen_random(max)
+ (max * ($last = ($last * IA + IC) % IM)) / IM
+end
+
+N = 3_000_000
+
+i = 0
+while i<N
+ i +=1
+ gen_random(100.0)
+end
+# "%.9f" % gen_random(100.0)
diff --git a/benchmark/bm_so_sieve.rb b/benchmark/bm_so_sieve.rb
new file mode 100644
index 0000000000..43dc302648
--- /dev/null
+++ b/benchmark/bm_so_sieve.rb
@@ -0,0 +1,24 @@
+# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
+num = 500
+count = i = j = 0
+flags0 = Array.new(8192,1)
+k = 0
+while k < num
+ k += 1
+ count = 0
+ flags = flags0.dup
+ i = 2
+ while i<8192
+ i += 1
+ if flags[i]
+ # remove all multiples of prime: i
+ j = i*i
+ while j < 8192
+ j += i
+ flags[j] = nil
+ end
+ count += 1
+ end
+ end
+end
+count
diff --git a/benchmark/bm_so_spectralnorm.rb b/benchmark/bm_so_spectralnorm.rb
new file mode 100644
index 0000000000..6b97206689
--- /dev/null
+++ b/benchmark/bm_so_spectralnorm.rb
@@ -0,0 +1,50 @@
+# The Computer Language Shootout
+# http://shootout.alioth.debian.org/
+# Contributed by Sokolov Yura
+
+def eval_A(i,j)
+ return 1.0/((i+j)*(i+j+1)/2+i+1)
+end
+
+def eval_A_times_u(u)
+ v, i = nil, nil
+ (0..u.length-1).collect { |i|
+ v = 0
+ for j in 0..u.length-1
+ v += eval_A(i,j)*u[j]
+ end
+ v
+ }
+end
+
+def eval_At_times_u(u)
+ v, i = nil, nil
+ (0..u.length-1).collect{|i|
+ v = 0
+ for j in 0..u.length-1
+ v += eval_A(j,i)*u[j]
+ end
+ v
+ }
+end
+
+def eval_AtA_times_u(u)
+ return eval_At_times_u(eval_A_times_u(u))
+end
+
+n = 500 # ARGV[0].to_i
+
+u=[1]*n
+for i in 1..10
+ v=eval_AtA_times_u(u)
+ u=eval_AtA_times_u(v)
+end
+vBv=0
+vv=0
+for i in 0..n-1
+ vBv += u[i]*v[i]
+ vv += v[i]*v[i]
+end
+
+str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
+# print str
diff --git a/benchmark/bm_string_index.rb b/benchmark/bm_string_index.rb
new file mode 100644
index 0000000000..7783111082
--- /dev/null
+++ b/benchmark/bm_string_index.rb
@@ -0,0 +1,3 @@
+str1 = "あ" * 1024 + "い" # not single byte optimizable
+str2 = "い"
+100_000.times { str1.index(str2) }
diff --git a/benchmark/bm_string_scan_re.rb b/benchmark/bm_string_scan_re.rb
new file mode 100644
index 0000000000..b0d60201a9
--- /dev/null
+++ b/benchmark/bm_string_scan_re.rb
@@ -0,0 +1,2 @@
+str = Array.new(1_000, 'abc').join(',')
+1_000.times { str.scan(/abc/) }
diff --git a/benchmark/bm_string_scan_str.rb b/benchmark/bm_string_scan_str.rb
new file mode 100644
index 0000000000..42440bd948
--- /dev/null
+++ b/benchmark/bm_string_scan_str.rb
@@ -0,0 +1,2 @@
+str = Array.new(1_000, 'abc').join(',')
+1_000.times { str.scan('abc') }
diff --git a/benchmark/bm_time_subsec.rb b/benchmark/bm_time_subsec.rb
new file mode 100644
index 0000000000..505021c701
--- /dev/null
+++ b/benchmark/bm_time_subsec.rb
@@ -0,0 +1,2 @@
+t = Time.now
+4000000.times { t.subsec }
diff --git a/benchmark/bm_vm3_backtrace.rb b/benchmark/bm_vm3_backtrace.rb
new file mode 100644
index 0000000000..0fbf73e1ca
--- /dev/null
+++ b/benchmark/bm_vm3_backtrace.rb
@@ -0,0 +1,22 @@
+# get last backtrace
+
+begin
+ caller(0, 0)
+rescue ArgumentError
+ alias caller_orig caller
+ def caller lev, n
+ caller_orig(lev)[0..n]
+ end
+end
+
+def rec n
+ if n < 0
+ 100_000.times{
+ caller(0, 1)
+ }
+ else
+ rec(n-1)
+ end
+end
+
+rec 50
diff --git a/benchmark/bm_vm3_clearmethodcache.rb b/benchmark/bm_vm3_clearmethodcache.rb
new file mode 100644
index 0000000000..9661323cd2
--- /dev/null
+++ b/benchmark/bm_vm3_clearmethodcache.rb
@@ -0,0 +1,8 @@
+i = 0
+while i<200_000
+ i += 1
+
+ Class.new{
+ def m; end
+ }
+end
diff --git a/benchmark/bm_vm3_gc.rb b/benchmark/bm_vm3_gc.rb
new file mode 100644
index 0000000000..e668026915
--- /dev/null
+++ b/benchmark/bm_vm3_gc.rb
@@ -0,0 +1,6 @@
+5000.times do
+ 100.times do
+ {"xxxx"=>"yyyy"}
+ end
+ GC.start
+end
diff --git a/benchmark/bm_vm3_gc_old_full.rb b/benchmark/bm_vm3_gc_old_full.rb
new file mode 100644
index 0000000000..cfdfc8c5a5
--- /dev/null
+++ b/benchmark/bm_vm3_gc_old_full.rb
@@ -0,0 +1,4 @@
+old_object = Array.new(1_000_000){''}
+100.times do
+ GC.start
+end
diff --git a/benchmark/bm_vm3_gc_old_immediate.rb b/benchmark/bm_vm3_gc_old_immediate.rb
new file mode 100644
index 0000000000..ad22feb655
--- /dev/null
+++ b/benchmark/bm_vm3_gc_old_immediate.rb
@@ -0,0 +1,4 @@
+old_object = Array.new(1_000_000){''}
+30_000.times do
+ GC.start(full_mark: false, immediate_sweep: true)
+end
diff --git a/benchmark/bm_vm3_gc_old_lazy.rb b/benchmark/bm_vm3_gc_old_lazy.rb
new file mode 100644
index 0000000000..b74d44baf1
--- /dev/null
+++ b/benchmark/bm_vm3_gc_old_lazy.rb
@@ -0,0 +1,4 @@
+old_object = Array.new(1_000_000){''}
+30_000.times do
+ GC.start(full_mark: false, immediate_sweep: false)
+end
diff --git a/benchmark/bm_vm_symbol_block_pass.rb b/benchmark/bm_vm_symbol_block_pass.rb
new file mode 100644
index 0000000000..1d433353e1
--- /dev/null
+++ b/benchmark/bm_vm_symbol_block_pass.rb
@@ -0,0 +1,13 @@
+class C
+ 1000.times {|i|
+ eval("def i#{i};end")
+ }
+end
+
+c = C.new
+m = C.instance_methods(false)
+5_000.times do
+ m.each do |n|
+ c.tap(&n)
+ end
+end
diff --git a/benchmark/bm_vm_thread_alive_check1.rb b/benchmark/bm_vm_thread_alive_check1.rb
new file mode 100644
index 0000000000..c993accdda
--- /dev/null
+++ b/benchmark/bm_vm_thread_alive_check1.rb
@@ -0,0 +1,6 @@
+5_000.times{
+ t = Thread.new{}
+ while t.alive?
+ Thread.pass
+ end
+}
diff --git a/benchmark/bm_vm_thread_close.rb b/benchmark/bm_vm_thread_close.rb
new file mode 100644
index 0000000000..3e9a265ce8
--- /dev/null
+++ b/benchmark/bm_vm_thread_close.rb
@@ -0,0 +1,6 @@
+1000.times { Thread.new { sleep } }
+i = 0
+while i<100_000 # benchmark loop 3
+ i += 1
+ IO.pipe.each(&:close)
+end
diff --git a/benchmark/bm_vm_thread_condvar1.rb b/benchmark/bm_vm_thread_condvar1.rb
new file mode 100644
index 0000000000..cf5706b23e
--- /dev/null
+++ b/benchmark/bm_vm_thread_condvar1.rb
@@ -0,0 +1,28 @@
+# two threads, two mutex, two condvar ping-pong
+require 'thread'
+m1 = Mutex.new
+m2 = Mutex.new
+cv1 = ConditionVariable.new
+cv2 = ConditionVariable.new
+max = 100000
+i = 0
+wait = nil
+m2.synchronize do
+ wait = Thread.new do
+ m1.synchronize do
+ m2.synchronize { cv2.signal }
+ while (i += 1) < max
+ cv1.wait(m1)
+ cv2.signal
+ end
+ end
+ end
+ cv2.wait(m2)
+end
+m1.synchronize do
+ while i < max
+ cv1.signal
+ cv2.wait(m1)
+ end
+end
+wait.join
diff --git a/benchmark/bm_vm_thread_condvar2.rb b/benchmark/bm_vm_thread_condvar2.rb
new file mode 100644
index 0000000000..7c8dc19481
--- /dev/null
+++ b/benchmark/bm_vm_thread_condvar2.rb
@@ -0,0 +1,35 @@
+# many threads, one mutex, many condvars
+require 'thread'
+m = Mutex.new
+cv1 = ConditionVariable.new
+cv2 = ConditionVariable.new
+max = 1000
+n = 100
+waiting = 0
+scvs = []
+waiters = n.times.map do |i|
+ start_cv = ConditionVariable.new
+ scvs << start_cv
+ start_mtx = Mutex.new
+ start_mtx.synchronize do
+ th = Thread.new(start_mtx, start_cv) do |sm, scv|
+ m.synchronize do
+ sm.synchronize { scv.signal }
+ max.times do
+ cv2.signal if (waiting += 1) == n
+ cv1.wait(m)
+ end
+ end
+ end
+ start_cv.wait(start_mtx)
+ th
+ end
+end
+m.synchronize do
+ max.times do
+ cv2.wait(m) until waiting == n
+ waiting = 0
+ cv1.broadcast
+ end
+end
+waiters.each(&:join)
diff --git a/benchmark/bm_vm_thread_create_join.rb b/benchmark/bm_vm_thread_create_join.rb
new file mode 100644
index 0000000000..393cd45df9
--- /dev/null
+++ b/benchmark/bm_vm_thread_create_join.rb
@@ -0,0 +1,6 @@
+i = 0
+while i<100_000 # benchmark loop 3
+ i += 1
+ Thread.new{
+ }.join
+end
diff --git a/benchmark/bm_vm_thread_mutex1.rb b/benchmark/bm_vm_thread_mutex1.rb
new file mode 100644
index 0000000000..66e42c85e1
--- /dev/null
+++ b/benchmark/bm_vm_thread_mutex1.rb
@@ -0,0 +1,21 @@
+# one thread, one mutex (no contention)
+
+require 'thread'
+m = Thread::Mutex.new
+r = 0
+max = 2000
+lmax = max * max
+(1..1).map{
+ Thread.new{
+ i = 0
+ while i<lmax
+ i += 1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
diff --git a/benchmark/bm_vm_thread_mutex2.rb b/benchmark/bm_vm_thread_mutex2.rb
new file mode 100644
index 0000000000..6e6c804c31
--- /dev/null
+++ b/benchmark/bm_vm_thread_mutex2.rb
@@ -0,0 +1,21 @@
+# two threads, one mutex
+
+require 'thread'
+m = Thread::Mutex.new
+r = 0
+max = 2000
+lmax = (max * max)/2
+(1..2).map{
+ Thread.new{
+ i = 0
+ while i<lmax
+ i += 1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
diff --git a/benchmark/bm_vm_thread_mutex3.rb b/benchmark/bm_vm_thread_mutex3.rb
new file mode 100644
index 0000000000..c750dc542a
--- /dev/null
+++ b/benchmark/bm_vm_thread_mutex3.rb
@@ -0,0 +1,20 @@
+# 1000 threads, one mutex
+
+require 'thread'
+m = Thread::Mutex.new
+r = 0
+max = 2000
+(1..max).map{
+ Thread.new{
+ i = 0
+ while i<max
+ i += 1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
diff --git a/benchmark/bm_vm_thread_pass.rb b/benchmark/bm_vm_thread_pass.rb
new file mode 100644
index 0000000000..b5b3c0bc85
--- /dev/null
+++ b/benchmark/bm_vm_thread_pass.rb
@@ -0,0 +1,15 @@
+# Plenty Thtread.pass
+# A performance may depend on GVL implementation.
+
+tmax = (ARGV.shift || 2).to_i
+lmax = 200_000 / tmax
+
+(1..tmax).map{
+ Thread.new{
+ lmax.times{
+ Thread.pass
+ }
+ }
+}.each{|t| t.join}
+
+
diff --git a/benchmark/bm_vm_thread_pass_flood.rb b/benchmark/bm_vm_thread_pass_flood.rb
new file mode 100644
index 0000000000..a660aafc18
--- /dev/null
+++ b/benchmark/bm_vm_thread_pass_flood.rb
@@ -0,0 +1,10 @@
+# n.b. this is a good test for GVL when pinned to a single CPU
+
+1000.times{
+ Thread.new{loop{Thread.pass}}
+}
+
+i = 0
+while i<10000
+ i += 1
+end
diff --git a/benchmark/bm_vm_thread_pipe.rb b/benchmark/bm_vm_thread_pipe.rb
new file mode 100644
index 0000000000..112a621905
--- /dev/null
+++ b/benchmark/bm_vm_thread_pipe.rb
@@ -0,0 +1,17 @@
+# Measure small and plenty pipe read/write.
+# A performance may depend on GVL implementation.
+
+lmax = 100_000
+r, w = IO.pipe
+[Thread.new{
+ lmax.times{
+ w.write('a')
+ }
+ p "w:exit"
+}, Thread.new{
+ lmax.times{
+ r.read(1)
+ }
+ p "r:exit"
+}].each{|t| t.join}
+
diff --git a/benchmark/bm_vm_thread_queue.rb b/benchmark/bm_vm_thread_queue.rb
new file mode 100644
index 0000000000..274ceda366
--- /dev/null
+++ b/benchmark/bm_vm_thread_queue.rb
@@ -0,0 +1,18 @@
+require 'thread'
+
+n = 1_000_000
+q = Thread::Queue.new
+consumer = Thread.new{
+ while q.pop
+ # consuming
+ end
+}
+
+producer = Thread.new{
+ n.times{
+ q.push true
+ }
+ q.push nil
+}
+
+consumer.join
diff --git a/benchmark/bm_vm_thread_sized_queue.rb b/benchmark/bm_vm_thread_sized_queue.rb
new file mode 100644
index 0000000000..7b9af5482b
--- /dev/null
+++ b/benchmark/bm_vm_thread_sized_queue.rb
@@ -0,0 +1,20 @@
+require 'thread'
+# on producer, one consumer
+
+n = 1_000_000
+q = Thread::SizedQueue.new(100)
+consumer = Thread.new{
+ while q.pop
+ # consuming
+ end
+}
+
+producer = Thread.new{
+ while n > 0
+ q.push true
+ n -= 1
+ end
+ q.push nil
+}
+
+consumer.join
diff --git a/benchmark/bm_vm_thread_sized_queue2.rb b/benchmark/bm_vm_thread_sized_queue2.rb
new file mode 100644
index 0000000000..de9f55e978
--- /dev/null
+++ b/benchmark/bm_vm_thread_sized_queue2.rb
@@ -0,0 +1,23 @@
+require 'thread'
+# one producer, many consumers
+n = 1_000_000
+m = 10
+q = Thread::SizedQueue.new(100)
+consumers = m.times.map do
+ Thread.new do
+ while q.pop
+ # consuming
+ end
+ end
+end
+
+producer = Thread.new do
+ while n > 0
+ q.push true
+ n -= 1
+ end
+ m.times { q.push nil }
+end
+
+producer.join
+consumers.each(&:join)
diff --git a/benchmark/bm_vm_thread_sized_queue3.rb b/benchmark/bm_vm_thread_sized_queue3.rb
new file mode 100644
index 0000000000..ce5f1796d8
--- /dev/null
+++ b/benchmark/bm_vm_thread_sized_queue3.rb
@@ -0,0 +1,22 @@
+require 'thread'
+# many producers, one consumer
+n = 1_000_000
+m = 10
+q = Thread::SizedQueue.new(100)
+consumer = Thread.new do
+ while q.pop
+ # consuming
+ end
+end
+
+producers = m.times.map do
+ Thread.new do
+ while n > 0
+ q.push true
+ n -= 1
+ end
+ end
+end
+producers.each(&:join)
+q.push nil
+consumer.join
diff --git a/benchmark/bm_vm_thread_sized_queue4.rb b/benchmark/bm_vm_thread_sized_queue4.rb
new file mode 100644
index 0000000000..a9b7d80ec0
--- /dev/null
+++ b/benchmark/bm_vm_thread_sized_queue4.rb
@@ -0,0 +1,26 @@
+require 'thread'
+# many producers, many consumers
+nr = 1_000_000
+n = 10
+m = 10
+q = Thread::SizedQueue.new(100)
+consumers = n.times.map do
+ Thread.new do
+ while q.pop
+ # consuming
+ end
+ end
+end
+
+producers = m.times.map do
+ Thread.new do
+ while nr > 0
+ q.push true
+ nr -= 1
+ end
+ end
+end
+
+producers.each(&:join)
+n.times { q.push nil }
+consumers.each(&:join)
diff --git a/benchmark/dir_empty_p.yml b/benchmark/dir_empty_p.yml
deleted file mode 100644
index 73e59bec98..0000000000
--- a/benchmark/dir_empty_p.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-benchmark:
- dir_empty_p: |
- require 'tmpdir'
- max = 100_000
- Dir.mktmpdir('bm_dir_empty_p') do |dir|
- max.times { Dir.empty?(dir) }
- end
-loop_count: 1
diff --git a/benchmark/erb_render.yml b/benchmark/erb_render.yml
deleted file mode 100644
index 33f23b2761..0000000000
--- a/benchmark/erb_render.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-benchmark:
- erb_render: |
- require 'erb'
-
- data = <<erb
- <html>
- <head> <%= title %> </head>
- <body>
- <h1> <%= title %> </h1>
- <p>
- <%= content %>
- </p>
- </body>
- </html>
- erb
-
- max = 1_500_000
- title = "hello world!"
- content = "hello world!\n" * 10
-
- src = "def self.render(title, content); #{ERB.new(data).src}; end"
- mod = Module.new
- mod.instance_eval(src, "(ERB)")
-
- max.times do
- mod.render(title, content)
- end
-loop_count: 1
diff --git a/benchmark/file_chmod.yml b/benchmark/file_chmod.yml
deleted file mode 100644
index baa43ddd42..0000000000
--- a/benchmark/file_chmod.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-prelude: |
- # chmod file
-benchmark:
- file_chmod: |
- require 'tempfile'
- max = 200_000
- tmp = Tempfile.new('chmod')
- path = tmp.path
- max.times do
- File.chmod(0777, path)
- end
- tmp.close!
-loop_count: 1
diff --git a/benchmark/file_rename.yml b/benchmark/file_rename.yml
deleted file mode 100644
index f337026c14..0000000000
--- a/benchmark/file_rename.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-prelude: |
- # rename file
-benchmark:
- file_rename: |
- require 'tempfile'
-
- max = 100_000
- tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ]
- a, b = tmp.map { |x| x.path }
- tmp.each { |t| t.close } # Windows can't rename files without closing them
- max.times do
- File.rename(a, b)
- File.rename(b, a)
- end
-loop_count: 1
diff --git a/benchmark/hash_aref_dsym.yml b/benchmark/hash_aref_dsym.yml
deleted file mode 100644
index e862b5689c..0000000000
--- a/benchmark/hash_aref_dsym.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_aref_dsym: |
- h = {}
- syms = ('a'..'z').map { |s| s.to_sym }
- syms.each { |s| h[s] = 1 }
- 200_000.times { syms.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_dsym_long.yml b/benchmark/hash_aref_dsym_long.yml
deleted file mode 100644
index 5488e052cd..0000000000
--- a/benchmark/hash_aref_dsym_long.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-prelude: |
- # [ruby-core:70129] [Bug #11396]
-benchmark:
- hash_aref_dsym_long: |
- collection_size = 200000
- sample_size = 10000
-
- values = (1..collection_size).to_a.map do |x|
- "THIS IS A LONGER STRING THAT IS ALSO UNIQUE #{x}"
- end
-
- symbol_hash = {}
-
- values.each do |x|
- symbol_hash[x.to_sym] = 1
- end
-
- # use the same samples each time to minimize deviations
- rng = Random.new(0)
- symbol_sample_array = values.sample(sample_size, random: rng).map(&:to_sym)
-
- 3000.times do
- symbol_sample_array.each { |x| symbol_hash[x] }
- end
-loop_count: 1
diff --git a/benchmark/hash_aref_fix.yml b/benchmark/hash_aref_fix.yml
deleted file mode 100644
index 5469d2a2db..0000000000
--- a/benchmark/hash_aref_fix.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_aref_fix: |
- h = {}
- nums = (1..26).to_a
- nums.each { |i| h[i] = i }
- 200_000.times { nums.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_flo.yml b/benchmark/hash_aref_flo.yml
deleted file mode 100644
index 2e3d8c887b..0000000000
--- a/benchmark/hash_aref_flo.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_aref_flo: |
- h = {}
- strs = [*1..10000].map! {|i| i.fdiv(10)}
- strs.each { |s| h[s] = s }
- 50.times { strs.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_miss.yml b/benchmark/hash_aref_miss.yml
deleted file mode 100644
index 4bd541e2ff..0000000000
--- a/benchmark/hash_aref_miss.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-benchmark:
- hash_aref_miss: |
- h = {}
- strs = ('a'..'z').to_a.map!(&:freeze)
- strs.each { |s| h[s] = s }
- strs = ('A'..'Z').to_a
- 200_000.times { strs.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_str.yml b/benchmark/hash_aref_str.yml
deleted file mode 100644
index 0790320ec5..0000000000
--- a/benchmark/hash_aref_str.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_aref_str: |
- h = {}
- strs = ('a'..'z').to_a.map!(&:freeze)
- strs.each { |s| h[s] = s }
- 200_000.times { strs.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_sym.yml b/benchmark/hash_aref_sym.yml
deleted file mode 100644
index e289d4aff3..0000000000
--- a/benchmark/hash_aref_sym.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- hash_aref_sym: |
- h = {}
- syms = ('a'..'z').to_a
- begin
- syms = eval("%i[#{syms.join(' ')}]")
- rescue SyntaxError # <= 1.9.3
- syms.map!(&:to_sym)
- end
- syms.each { |s| h[s] = s }
- 200_000.times { syms.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_aref_sym_long.yml b/benchmark/hash_aref_sym_long.yml
deleted file mode 100644
index 4edccc12dd..0000000000
--- a/benchmark/hash_aref_sym_long.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-benchmark:
- hash_aref_sym_long: |
- h = {}
- syms = %w[puts warn syswrite write stat bacon lettuce tomato
- some symbols in this array may already be interned others should not be
- hash browns make good breakfast but not cooked using prime numbers
- shift for division entries delete_if keys exist?
- ]
- begin
- syms = eval("%i[#{syms.join(' ')}]")
- rescue SyntaxError # <= 1.9.3
- syms.map!(&:to_sym)
- end
- syms.each { |s| h[s] = s }
- 200_000.times { syms.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_flatten.yml b/benchmark/hash_flatten.yml
deleted file mode 100644
index 0412388417..0000000000
--- a/benchmark/hash_flatten.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- hash_flatten: |
- h = {}
-
- 10000.times do |i|
- h[i] = nil
- end
-
- 1000.times do
- h.flatten
- end
-loop_count: 1
diff --git a/benchmark/hash_ident_flo.yml b/benchmark/hash_ident_flo.yml
deleted file mode 100644
index ee2a78db44..0000000000
--- a/benchmark/hash_ident_flo.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_ident_flo: |
- h = {}.compare_by_identity
- strs = (1..10000).to_a.map!(&:to_f)
- strs.each { |s| h[s] = s }
- 50.times { strs.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_ident_num.yml b/benchmark/hash_ident_num.yml
deleted file mode 100644
index c9b58bd0c6..0000000000
--- a/benchmark/hash_ident_num.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_ident_num: |
- h = {}.compare_by_identity
- nums = (1..26).to_a
- nums.each { |n| h[n] = n }
- 200_000.times { nums.each { |n| h[n] } }
-loop_count: 1
diff --git a/benchmark/hash_ident_obj.yml b/benchmark/hash_ident_obj.yml
deleted file mode 100644
index 95c310985f..0000000000
--- a/benchmark/hash_ident_obj.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_ident_obj: |
- h = {}.compare_by_identity
- objs = 26.times.map { Object.new }
- objs.each { |o| h[o] = o }
- 200_000.times { objs.each { |o| h[o] } }
-loop_count: 1
diff --git a/benchmark/hash_ident_str.yml b/benchmark/hash_ident_str.yml
deleted file mode 100644
index c2423778f7..0000000000
--- a/benchmark/hash_ident_str.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_ident_str: |
- h = {}.compare_by_identity
- strs = ('a'..'z').to_a
- strs.each { |s| h[s] = s }
- 200_000.times { strs.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_ident_sym.yml b/benchmark/hash_ident_sym.yml
deleted file mode 100644
index e49bdba7f4..0000000000
--- a/benchmark/hash_ident_sym.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_ident_sym: |
- h = {}.compare_by_identity
- syms = ('a'..'z').to_a.map(&:to_sym)
- syms.each { |s| h[s] = s }
- 200_000.times { syms.each { |s| h[s] } }
-loop_count: 1
diff --git a/benchmark/hash_keys.yml b/benchmark/hash_keys.yml
deleted file mode 100644
index 18e9078640..0000000000
--- a/benchmark/hash_keys.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- hash_keys: |
- h = {}
-
- 10000.times do |i|
- h[i] = nil
- end
-
- 5000.times do
- h.keys
- end
-loop_count: 1
diff --git a/benchmark/hash_long.yml b/benchmark/hash_long.yml
deleted file mode 100644
index 33c0c38f49..0000000000
--- a/benchmark/hash_long.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- hash_long: |
- k1 = "Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong";
- k2 = "Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping Pong Ping";
- h = {k1 => 0, k2 => 0};
- 3000000.times{|i| k = i % 2 ? k2 : k1; h [k] = h[k] + 1}
-loop_count: 1
diff --git a/benchmark/hash_shift.yml b/benchmark/hash_shift.yml
deleted file mode 100644
index 954c1eb6fe..0000000000
--- a/benchmark/hash_shift.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- hash_shift: |
- h = {}
-
- 10000.times do |i|
- h[i] = nil
- end
-
- 50000.times do
- k, v = h.shift
- h[k] = v
- end
-loop_count: 1
diff --git a/benchmark/hash_shift_u16.yml b/benchmark/hash_shift_u16.yml
deleted file mode 100644
index b8e1ae75f4..0000000000
--- a/benchmark/hash_shift_u16.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- hash_shift_u16: |
- h = {}
-
- (16384..65536).each do |i|
- h[i] = nil
- end
-
- 300000.times do
- k, v = h.shift
- h[k] = v
- end
-loop_count: 1
diff --git a/benchmark/hash_shift_u24.yml b/benchmark/hash_shift_u24.yml
deleted file mode 100644
index 743d3cefc3..0000000000
--- a/benchmark/hash_shift_u24.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- hash_shift_u24: |
- h = {}
-
- (0xff4000..0xffffff).each do |i|
- h[i] = nil
- end
-
- 300000.times do
- k, v = h.shift
- h[k] = v
- end
-loop_count: 1
diff --git a/benchmark/hash_shift_u32.yml b/benchmark/hash_shift_u32.yml
deleted file mode 100644
index 96e9753dde..0000000000
--- a/benchmark/hash_shift_u32.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- hash_shift_u32: |
- h = {}
-
- (0xffff4000..0xffffffff).each do |i|
- h[i] = nil
- end
-
- 300000.times do
- k, v = h.shift
- h[k] = v
- end
-loop_count: 1
diff --git a/benchmark/hash_small2.yml b/benchmark/hash_small2.yml
deleted file mode 100644
index 0bf7ab6a1b..0000000000
--- a/benchmark/hash_small2.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- hash_small2: |
- 1000000.times.map{|i| a={}; 2.times{|j| a[j]=j}; a}
-loop_count: 1
diff --git a/benchmark/hash_small4.yml b/benchmark/hash_small4.yml
deleted file mode 100644
index 24bc334c63..0000000000
--- a/benchmark/hash_small4.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- hash_small4: |
- 1000000.times.map{|i| a={}; 4.times{|j| a[j]=j}; a}
-loop_count: 1
diff --git a/benchmark/hash_small8.yml b/benchmark/hash_small8.yml
deleted file mode 100644
index 30b50a789c..0000000000
--- a/benchmark/hash_small8.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- hash_small8: |
- 1000000.times.map{|i| a={}; 8.times{|j| a[j]=j}; a}
-loop_count: 1
diff --git a/benchmark/hash_to_proc.yml b/benchmark/hash_to_proc.yml
deleted file mode 100644
index 2ae8588b27..0000000000
--- a/benchmark/hash_to_proc.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- hash_to_proc: |
- h = {}
-
- 10000.times do |i|
- h[i] = nil
- end
-
- 5000.times do |i|
- [i].map(&h)
- end
-loop_count: 1
diff --git a/benchmark/hash_values.yml b/benchmark/hash_values.yml
deleted file mode 100644
index b645bcf4f8..0000000000
--- a/benchmark/hash_values.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-benchmark:
- hash_values: |
- h = {}
-
- 10000.times do |i|
- h[i] = nil
- end
-
- 5000.times do
- h.values
- end
-loop_count: 1
diff --git a/benchmark/int_quo.yml b/benchmark/int_quo.yml
deleted file mode 100644
index 1527de3dfc..0000000000
--- a/benchmark/int_quo.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- int_quo: |
- 5000000.times { 42.quo(3) }
-loop_count: 1
diff --git a/benchmark/io_copy_stream_write.yml b/benchmark/io_copy_stream_write.yml
deleted file mode 100644
index 32fa920951..0000000000
--- a/benchmark/io_copy_stream_write.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-prelude: |
- # The goal of this is to use a synthetic (non-IO) reader
- # to trigger the read/write loop of IO.copy_stream,
- # bypassing in-kernel mechanisms like sendfile for zero copy,
- # so we wrap the /dev/zero IO object:
-benchmark:
- io_copy_stream_write: |
-
- class Zero
- def initialize
- @n = 100000
- @in = File.open('/dev/zero', 'rb')
- end
-
- def read(len, buf)
- return if (@n -= 1) == 0
- @in.read(len, buf)
- end
- end
-
- begin
- src = Zero.new
- dst = File.open(IO::NULL, 'wb')
- n = IO.copy_stream(src, dst)
- rescue Errno::ENOENT
- # not *nix
- end if IO.respond_to?(:copy_stream) && IO.const_defined?(:NULL)
-loop_count: 1
diff --git a/benchmark/io_copy_stream_write_socket.yml b/benchmark/io_copy_stream_write_socket.yml
deleted file mode 100644
index 2207eca8c6..0000000000
--- a/benchmark/io_copy_stream_write_socket.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-prelude: |
- # The goal of this is to use a synthetic (non-IO) reader
- # to trigger the read/write loop of IO.copy_stream,
- # bypassing in-kernel mechanisms like sendfile for zero copy,
- # so we wrap the /dev/zero IO object:
-benchmark:
- io_copy_stream_write_socket: |
- class Zero
- def initialize
- @n = 100000
- @in = File.open('/dev/zero', 'rb')
- end
-
- def read(len, buf)
- return if (@n -= 1) == 0
- @in.read(len, buf)
- end
- end
-
- begin
- require 'socket'
- src = Zero.new
- rd, wr = UNIXSocket.pair
- pid = fork do
- wr.close
- buf = String.new
- while rd.read(16384, buf)
- end
- end
- rd.close
- IO.copy_stream(src, wr)
- rescue Errno::ENOENT, NotImplementedError, NameError
- # not *nix: missing /dev/zero, fork, or UNIXSocket
- rescue LoadError # no socket?
- ensure
- wr.close if wr
- Process.waitpid(pid) if pid
- end if IO.respond_to?(:copy_stream)
-loop_count: 1
diff --git a/benchmark/io_file_create.yml b/benchmark/io_file_create.yml
deleted file mode 100644
index ece11cc332..0000000000
--- a/benchmark/io_file_create.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-benchmark:
- io_file_create: |
- #
- # Create files
- #
-
- max = 200_000
- file = './tmpfile_of_bm_io_file_create'
-
- max.times{
- f = open(file, 'w')
- f.close#(true)
- }
- File.unlink(file)
-loop_count: 1
diff --git a/benchmark/io_file_read.yml b/benchmark/io_file_read.yml
deleted file mode 100644
index f8f0c1c871..0000000000
--- a/benchmark/io_file_read.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-benchmark:
- io_file_read: |
- #
- # Seek and Read file.
- #
-
- require 'tempfile'
-
- max = 200_000
- str = "Hello world! " * 1000
- f = Tempfile.new('yarv-benchmark')
- f.write str
-
- max.times{
- f.seek 0
- f.read
- }
-loop_count: 1
diff --git a/benchmark/io_file_write.yml b/benchmark/io_file_write.yml
deleted file mode 100644
index 68af6d588c..0000000000
--- a/benchmark/io_file_write.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-benchmark:
- io_file_write: |
- #
- # Seek and Write file.
- #
-
- require 'tempfile'
-
- max = 200_000
- str = "Hello world! " * 1000
- f = Tempfile.new('yarv-benchmark')
-
- max.times{
- f.seek 0
- f.write str
- }
-loop_count: 1
diff --git a/benchmark/io_nonblock_noex.yml b/benchmark/io_nonblock_noex.yml
deleted file mode 100644
index 6e29240bd7..0000000000
--- a/benchmark/io_nonblock_noex.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-benchmark:
- io_nonblock_noex: |
- nr = 1_000_000
- i = 0
- msg = '.'
- buf = '.'
- noex = { exception: false }
- begin
- r, w = IO.pipe
- while i < nr
- i += 1
- w.write_nonblock(msg, noex)
- r.read_nonblock(1, buf, noex)
- end
- rescue ArgumentError # old Rubies
- while i < nr
- i += 1
- w.write_nonblock(msg)
- r.read_nonblock(1, buf)
- end
- ensure
- r.close
- w.close
- end
-loop_count: 1
diff --git a/benchmark/io_nonblock_noex2.yml b/benchmark/io_nonblock_noex2.yml
deleted file mode 100644
index eda8687028..0000000000
--- a/benchmark/io_nonblock_noex2.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-benchmark:
- io_nonblock_noex2: |
- nr = 1_000_000
- i = 0
- msg = '.'
- buf = '.'
- begin
- r, w = IO.pipe
- while i < nr
- i += 1
- w.write_nonblock(msg, exception: false)
- r.read_nonblock(1, buf, exception: false)
- end
- rescue ArgumentError # old Rubies
- while i < nr
- i += 1
- w.write_nonblock(msg)
- r.read_nonblock(1, buf)
- end
- ensure
- r.close
- w.close
- end
-loop_count: 1
diff --git a/benchmark/io_pipe_rw.yml b/benchmark/io_pipe_rw.yml
deleted file mode 100644
index cd9e6c3826..0000000000
--- a/benchmark/io_pipe_rw.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-prelude: |
- # Measure uncontended GVL performance via read/write with 1:1 threading
- # If we switch to M:N threading, this will benchmark something else...
-benchmark:
- io_pipe_rw: |
- r, w = IO.pipe
- src = '0'.freeze
- dst = String.new
- i = 0
- while i < 1_000_000
- i += 1
- w.write(src)
- r.read(1, dst)
- end
- w.close
- r.close
-loop_count: 1
diff --git a/benchmark/io_select.yml b/benchmark/io_select.yml
deleted file mode 100644
index bcea6b9a70..0000000000
--- a/benchmark/io_select.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-prelude: |
- # IO.select performance
-benchmark:
- io_select: |
-
- w = [ IO.pipe[1] ];
-
- nr = 1000000
- nr.times {
- IO.select nil, w
- }
-loop_count: 1
diff --git a/benchmark/io_select2.yml b/benchmark/io_select2.yml
deleted file mode 100644
index 3c8078dc11..0000000000
--- a/benchmark/io_select2.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-prelude: |
- # IO.select performance. worst case of single fd.
-benchmark:
- io_select2: |
-
- ios = []
- nr = 1000000
- if defined?(Process::RLIMIT_NOFILE)
- max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
- else
- max = 64
- end
- puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
-
- ((max / 2) - 10).times do
- ios.concat IO.pipe
- end
-
- last = [ ios[-1] ]
- puts "last IO: #{last[0].inspect}"
-
- nr.times do
- IO.select nil, last
- end
-loop_count: 1
diff --git a/benchmark/io_select3.yml b/benchmark/io_select3.yml
deleted file mode 100644
index c97d0e0cd1..0000000000
--- a/benchmark/io_select3.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-prelude: |
- # IO.select performance. a lot of fd
-benchmark:
- io_select3: |
-
- ios = []
- nr = 100
- if defined?(Process::RLIMIT_NOFILE)
- max = Process.getrlimit(Process::RLIMIT_NOFILE)[0]
- else
- max = 64
- end
- puts "max fd: #{max} (results not apparent with <= 1024 max fd)"
-
- (max - 10).times do
- r, w = IO.pipe
- r.close
- ios.push w
- end
-
- nr.times do
- IO.select nil, ios
- end
-loop_count: 1
diff --git a/benchmark/loop_for.yml b/benchmark/loop_for.yml
deleted file mode 100644
index 99279f014a..0000000000
--- a/benchmark/loop_for.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-benchmark:
- loop_for: |
- for i in 1..30_000_000
- #
- end
-loop_count: 1
diff --git a/benchmark/loop_generator.yml b/benchmark/loop_generator.yml
deleted file mode 100644
index a5a39c085a..0000000000
--- a/benchmark/loop_generator.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-benchmark:
- loop_generator: |
- max = 600000
-
- if defined? Fiber
- gen = (1..max).each
- loop do
- gen.next
- end
- else
- require 'generator'
- gen = Generator.new((0..max))
- while gen.next?
- gen.next
- end
- end
-loop_count: 1
diff --git a/benchmark/loop_times.yml b/benchmark/loop_times.yml
deleted file mode 100644
index 8d50d6edda..0000000000
--- a/benchmark/loop_times.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- loop_times: |
- 30_000_000.times{|e|}
-loop_count: 1
diff --git a/benchmark/loop_whileloop.yml b/benchmark/loop_whileloop.yml
deleted file mode 100644
index 0fa797aed4..0000000000
--- a/benchmark/loop_whileloop.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- loop_whileloop: |
- i = 0
- while i<30_000_000 # benchmark loop 1
- i += 1
- end
-loop_count: 1
diff --git a/benchmark/loop_whileloop2.yml b/benchmark/loop_whileloop2.yml
deleted file mode 100644
index 2cf83908b3..0000000000
--- a/benchmark/loop_whileloop2.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- loop_whileloop2: |
- i = 0
- while i< 6_000_000 # benchmark loop 2
- i += 1
- end
-loop_count: 1
diff --git a/benchmark/marshal_dump_flo.yml b/benchmark/marshal_dump_flo.yml
deleted file mode 100644
index 0e3cc1394a..0000000000
--- a/benchmark/marshal_dump_flo.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- marshal_dump_flo: |
- bug10761 = 10000.times.map { |x| x.to_f }
- 100.times { Marshal.dump(bug10761) }
-loop_count: 1
diff --git a/benchmark/marshal_dump_load_geniv.yml b/benchmark/marshal_dump_load_geniv.yml
deleted file mode 100644
index 6395c1d1cd..0000000000
--- a/benchmark/marshal_dump_load_geniv.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-benchmark:
- marshal_dump_load_geniv: |
- a = ''
- a.instance_eval do
- @a = :a
- @b = :b
- @c = :c
- end
- 100000.times do
- a = Marshal.load(Marshal.dump(a))
- end
- #p(a.instance_eval { @a == :a && @b == :b && @c == :c })
-loop_count: 1
diff --git a/benchmark/marshal_dump_load_time.yml b/benchmark/marshal_dump_load_time.yml
deleted file mode 100644
index 0c25c2d677..0000000000
--- a/benchmark/marshal_dump_load_time.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-benchmark:
- marshal_dump_load_time: |
- 100000.times { Marshal.load(Marshal.dump(Time.now)) }
-loop_count: 1
diff --git a/benchmark/securerandom.yml b/benchmark/securerandom.yml
deleted file mode 100644
index 187ca2e294..0000000000
--- a/benchmark/securerandom.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-benchmark:
- securerandom: |
- require "securerandom"
-
- 20_0000.times do
- SecureRandom.random_number(100)
- end
-loop_count: 1
diff --git a/benchmark/so_ackermann.yml b/benchmark/so_ackermann.yml
deleted file mode 100644
index 4082169f5e..0000000000
--- a/benchmark/so_ackermann.yml
+++ /dev/null
@@ -1,21 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
-benchmark:
- so_ackermann: |
-
- def ack(m, n)
- if m == 0 then
- n + 1
- elsif n == 0 then
- ack(m - 1, 1)
- else
- ack(m - 1, ack(m, n - 1))
- end
- end
-
- NUM = 9
- ack(3, NUM)
-loop_count: 1
diff --git a/benchmark/so_array.yml b/benchmark/so_array.yml
deleted file mode 100644
index e68643879e..0000000000
--- a/benchmark/so_array.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
- # with help from Paul Brannan and Mark Hubbart
-benchmark:
- so_array: |
-
- n = 9000 # Integer(ARGV.shift || 1)
-
- x = Array.new(n)
- y = Array.new(n, 0)
-
- n.times{|bi|
- x[bi] = bi + 1
- }
-
- (0 .. 999).each do |e|
- (n-1).step(0,-1) do |bi|
- y[bi] += x.at(bi)
- end
- end
- # puts "#{y.first} #{y.last}"
-loop_count: 1
diff --git a/benchmark/so_binary_trees.yml b/benchmark/so_binary_trees.yml
deleted file mode 100644
index 9e943d50ff..0000000000
--- a/benchmark/so_binary_trees.yml
+++ /dev/null
@@ -1,66 +0,0 @@
-prelude: |
- # The Computer Language Shootout Benchmarks
- # http://shootout.alioth.debian.org
-benchmark:
- so_binary_trees: |
- #
- # contributed by Jesse Millikan
-
- # disable output
- alias puts_orig puts
- def puts str
- # disable puts
- end
-
- def item_check(tree)
- if tree[0] == nil
- tree[1]
- else
- tree[1] + item_check(tree[0]) - item_check(tree[2])
- end
- end
-
- def bottom_up_tree(item, depth)
- if depth > 0
- item_item = 2 * item
- depth -= 1
- [bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)]
- else
- [nil, item, nil]
- end
- end
-
- max_depth = 16 # ARGV[0].to_i
- min_depth = 4
-
- max_depth = min_depth + 2 if min_depth + 2 > max_depth
-
- stretch_depth = max_depth + 1
- stretch_tree = bottom_up_tree(0, stretch_depth)
-
- puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}"
- stretch_tree = nil
-
- long_lived_tree = bottom_up_tree(0, max_depth)
-
- min_depth.step(max_depth + 1, 2) do |depth|
- iterations = 2**(max_depth - depth + min_depth)
-
- check = 0
-
- for i in 1..iterations
- temp_tree = bottom_up_tree(i, depth)
- check += item_check(temp_tree)
-
- temp_tree = bottom_up_tree(-i, depth)
- check += item_check(temp_tree)
- end
-
- puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}"
- end
-
- puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}"
-
- undef puts
- alias puts puts_orig
-loop_count: 1
diff --git a/benchmark/so_concatenate.yml b/benchmark/so_concatenate.yml
deleted file mode 100644
index 13d6559745..0000000000
--- a/benchmark/so_concatenate.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
- # based on code from Aristarkh A Zagorodnikov and Dat Nguyen
-benchmark:
- so_concatenate: |
-
- STUFF = "hello\n"
- i = 0
- while i<10
- i += 1
- hello = ''
- 4_000_000.times do |e|
- hello << STUFF
- end
- end
- # puts hello.length
-loop_count: 1
diff --git a/benchmark/so_exception.yml b/benchmark/so_exception.yml
deleted file mode 100644
index 0bfe3718eb..0000000000
--- a/benchmark/so_exception.yml
+++ /dev/null
@@ -1,65 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
-benchmark:
- so_exception: |
-
- $HI = 0
- $LO = 0
- NUM = 250000 # Integer(ARGV[0] || 1)
-
-
- class Lo_Exception < Exception
- def initialize(num)
- @value = num
- end
- end
-
- class Hi_Exception < Exception
- def initialize(num)
- @value = num
- end
- end
-
- def some_function(num)
- begin
- hi_function(num)
- rescue
- print "We shouldn't get here, exception is: #{$!.type}\n"
- end
- end
-
- def hi_function(num)
- begin
- lo_function(num)
- rescue Hi_Exception
- $HI = $HI + 1
- end
- end
-
- def lo_function(num)
- begin
- blowup(num)
- rescue Lo_Exception
- $LO = $LO + 1
- end
- end
-
- def blowup(num)
- if num % 2 == 0
- raise Lo_Exception.new(num)
- else
- raise Hi_Exception.new(num)
- end
- end
-
-
- i = 1
- max = NUM+1
- while i < max
- i += 1
- some_function(i+1)
- end
-loop_count: 1
diff --git a/benchmark/so_fannkuch.yml b/benchmark/so_fannkuch.yml
deleted file mode 100644
index 3d7a2b43bd..0000000000
--- a/benchmark/so_fannkuch.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-prelude: |
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org/
- # Contributed by Sokolov Yura
- # Modified by Ryan Williams
-benchmark:
- so_fannkuch: |
-
- def fannkuch(n)
- maxFlips, m, r, check = 0, n-1, n, 0
- count = (1..n).to_a
- perm = (1..n).to_a
-
- while true
- if check < 30
- puts "#{perm}"
- check += 1
- end
-
- while r != 1
- count[r-1] = r
- r -= 1
- end
-
- if perm[0] != 1 and perm[m] != n
- perml = perm.clone #.dup
- flips = 0
- while (k = perml.first ) != 1
- perml = perml.slice!(0, k).reverse + perml
- flips += 1
- end
- maxFlips = flips if flips > maxFlips
- end
- while true
- if r==n then return maxFlips end
- perm.insert r,perm.shift
- break if (count[r] -= 1) > 0
- r += 1
- end
- end
- end
-
- def puts *args
- end
-
- N = 9 # (ARGV[0] || 1).to_i
- puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"
-loop_count: 1
diff --git a/benchmark/so_fasta.yml b/benchmark/so_fasta.yml
deleted file mode 100644
index c7c6a92958..0000000000
--- a/benchmark/so_fasta.yml
+++ /dev/null
@@ -1,84 +0,0 @@
-prelude: |
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org/
- # Contributed by Sokolov Yura
-benchmark:
- so_fasta: |
-
- $last = 42.0
- def gen_random(max, im=139968, ia=3877, ic=29573)
- (max * ($last = ($last * ia + ic) % im)) / im
- end
-
- alu =
- "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"+
- "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"+
- "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"+
- "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"+
- "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"+
- "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"+
- "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"
-
- iub = [
- ["a", 0.27],
- ["c", 0.12],
- ["g", 0.12],
- ["t", 0.27],
-
- ["B", 0.02],
- ["D", 0.02],
- ["H", 0.02],
- ["K", 0.02],
- ["M", 0.02],
- ["N", 0.02],
- ["R", 0.02],
- ["S", 0.02],
- ["V", 0.02],
- ["W", 0.02],
- ["Y", 0.02],
- ]
- homosapiens = [
- ["a", 0.3029549426680],
- ["c", 0.1979883004921],
- ["g", 0.1975473066391],
- ["t", 0.3015094502008],
- ]
-
- def make_repeat_fasta(id, desc, src, n)
- puts ">#{id} #{desc}"
- v = nil
- width = 60
- l = src.length
- s = src * ((n / l) + 1)
- s.slice!(n, l)
- puts(s.scan(/.{1,#{width}}/).join("\n"))
- end
-
- def make_random_fasta(id, desc, table, n)
- puts ">#{id} #{desc}"
- rand, v = nil,nil
- width = 60
- chunk = 1 * width
- prob = 0.0
- table.each{|v| v[1]= (prob += v[1])}
- for i in 1..(n/width)
- puts((1..width).collect{
- rand = gen_random(1.0)
- table.find{|v| v[1]>rand}[0]
- }.join)
- end
- if n%width != 0
- puts((1..(n%width)).collect{
- rand = gen_random(1.0)
- table.find{|v| v[1]>rand}[0]
- }.join)
- end
- end
-
-
- n = (ARGV[0] or 250_000).to_i
-
- make_repeat_fasta('ONE', 'Homo sapiens alu', alu, n*2)
- make_random_fasta('TWO', 'IUB ambiguity codes', iub, n*3)
- make_random_fasta('THREE', 'Homo sapiens frequency', homosapiens, n*5)
-loop_count: 1
diff --git a/benchmark/so_lists.yml b/benchmark/so_lists.yml
deleted file mode 100644
index 44a7495a2f..0000000000
--- a/benchmark/so_lists.yml
+++ /dev/null
@@ -1,51 +0,0 @@
-prelude: |
- #from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
-benchmark:
- so_lists: |
-
- NUM = 300
- SIZE = 10000
-
- def test_lists()
- # create a list of integers (Li1) from 1 to SIZE
- li1 = (1..SIZE).to_a
- # copy the list to li2 (not by individual items)
- li2 = li1.dup
- # remove each individual item from left side of li2 and
- # append to right side of li3 (preserving order)
- li3 = Array.new
- while (not li2.empty?)
- li3.push(li2.shift)
- end
- # li2 must now be empty
- # remove each individual item from right side of li3 and
- # append to right side of li2 (reversing list)
- while (not li3.empty?)
- li2.push(li3.pop)
- end
- # li3 must now be empty
- # reverse li1 in place
- li1.reverse!
- # check that first item is now SIZE
- if li1[0] != SIZE then
- p "not SIZE"
- 0
- else
- # compare li1 and li2 for equality
- if li1 != li2 then
- return(0)
- else
- # return the length of the list
- li1.length
- end
- end
- end
-
- i = 0
- while i<NUM
- i += 1
- result = test_lists()
- end
-
- result
-loop_count: 1
diff --git a/benchmark/so_mandelbrot.yml b/benchmark/so_mandelbrot.yml
deleted file mode 100644
index daa58a0133..0000000000
--- a/benchmark/so_mandelbrot.yml
+++ /dev/null
@@ -1,61 +0,0 @@
-prelude: |
- # The Computer Language Benchmarks Game
- # http://shootout.alioth.debian.org/
-benchmark:
- so_mandelbrot: |
- #
- # contributed by Karl von Laudermann
- # modified by Jeremy Echols
-
- size = 600 # ARGV[0].to_i
-
- puts "P4\n#{size} #{size}"
-
- ITER = 49 # Iterations - 1 for easy for..in looping
- LIMIT_SQUARED = 4.0 # Presquared limit
-
- byte_acc = 0
- bit_num = 0
-
- count_size = size - 1 # Precomputed size for easy for..in looping
-
- # For..in loops are faster than .upto, .downto, .times, etc.
- for y in 0..count_size
- for x in 0..count_size
- zr = 0.0
- zi = 0.0
- cr = (2.0*x/size)-1.5
- ci = (2.0*y/size)-1.0
- escape = false
-
- # To make use of the for..in code, we use a dummy variable,
- # like one would in C
- for dummy in 0..ITER
- tr = zr*zr - zi*zi + cr
- ti = 2*zr*zi + ci
- zr, zi = tr, ti
-
- if (zr*zr+zi*zi) > LIMIT_SQUARED
- escape = true
- break
- end
- end
-
- byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1)
- bit_num += 1
-
- # Code is very similar for these cases, but using separate blocks
- # ensures we skip the shifting when it's unnecessary, which is most cases.
- if (bit_num == 8)
- print byte_acc.chr
- byte_acc = 0
- bit_num = 0
- elsif (x == count_size)
- byte_acc <<= (8 - bit_num)
- print byte_acc.chr
- byte_acc = 0
- bit_num = 0
- end
- end
- end
-loop_count: 1
diff --git a/benchmark/so_matrix.yml b/benchmark/so_matrix.yml
deleted file mode 100644
index 9a534471d9..0000000000
--- a/benchmark/so_matrix.yml
+++ /dev/null
@@ -1,50 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
-benchmark:
- so_matrix: |
-
- n = 60 #Integer(ARGV.shift || 1)
-
- size = 40
-
- def mkmatrix(rows, cols)
- count = 1
- mx = Array.new(rows)
- (0 .. (rows - 1)).each do |bi|
- row = Array.new(cols, 0)
- (0 .. (cols - 1)).each do |j|
- row[j] = count
- count += 1
- end
- mx[bi] = row
- end
- mx
- end
-
- def mmult(rows, cols, m1, m2)
- m3 = Array.new(rows)
- (0 .. (rows - 1)).each do |bi|
- row = Array.new(cols, 0)
- (0 .. (cols - 1)).each do |j|
- val = 0
- (0 .. (cols - 1)).each do |k|
- val += m1.at(bi).at(k) * m2.at(k).at(j)
- end
- row[j] = val
- end
- m3[bi] = row
- end
- m3
- end
-
- m1 = mkmatrix(size, size)
- m2 = mkmatrix(size, size)
- mm = Array.new
- n.times do
- mm = mmult(size, size, m1, m2)
- end
- # puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"
-loop_count: 1
diff --git a/benchmark/so_meteor_contest.yml b/benchmark/so_meteor_contest.yml
deleted file mode 100644
index c35df18f68..0000000000
--- a/benchmark/so_meteor_contest.yml
+++ /dev/null
@@ -1,567 +0,0 @@
-prelude: |
- #!/usr/bin/env ruby
-benchmark:
- so_meteor_contest: |
- #
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org
- # contributed by Kevin Barnes (Ruby novice)
-
- # PROGRAM: the main body is at the bottom.
- # 1) read about the problem here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
- # 2) see how I represent a board as a bitmask by reading the blank_board comments
- # 3) read as your mental paths take you
-
- def print *args
- end
-
- # class to represent all information about a particular rotation of a particular piece
- class Rotation
- # an array (by location) containing a bit mask for how the piece maps at the given location.
- # if the rotation is invalid at that location the mask will contain false
- attr_reader :start_masks
-
- # maps a direction to a relative location. these differ depending on whether it is an even or
- # odd row being mapped from
- @@rotation_even_adder = { :west => -1, :east => 1, :nw => -7, :ne => -6, :sw => 5, :se => 6 }
- @@rotation_odd_adder = { :west => -1, :east => 1, :nw => -6, :ne => -5, :sw => 6, :se => 7 }
-
- def initialize( directions )
- @even_offsets, @odd_offsets = normalize_offsets( get_values( directions ))
-
- @even_mask = mask_for_offsets( @even_offsets)
- @odd_mask = mask_for_offsets( @odd_offsets)
-
- @start_masks = Array.new(60)
-
- # create the rotational masks by placing the base mask at the location and seeing if
- # 1) it overlaps the boundaries and 2) it produces a prunable board. if either of these
- # is true the piece cannot be placed
- 0.upto(59) do | offset |
- mask = is_even(offset) ? (@even_mask << offset) : (@odd_mask << offset)
- if (blank_board & mask == 0 && !prunable(blank_board | mask, 0, true)) then
- imask = compute_required( mask, offset)
- @start_masks[offset] = [ mask, imask, imask | mask ]
- else
- @start_masks[offset] = false
- end
- end
- end
-
- def compute_required( mask, offset )
- board = blank_board
- 0.upto(offset) { | i | board |= 1 << i }
- board |= mask
- return 0 if (!prunable(board | mask, offset))
- board = flood_fill(board,58)
- count = 0
- imask = 0
- 0.upto(59) do | i |
- if (board[i] == 0) then
- imask |= (1 << i)
- count += 1
- end
- end
- (count > 0 && count < 5) ? imask : 0
- end
-
- def flood_fill( board, location)
- return board if (board[location] == 1)
- board |= 1 << location
- row, col = location.divmod(6)
- board = flood_fill( board, location - 1) if (col > 0)
- board = flood_fill( board, location + 1) if (col < 4)
- if (row % 2 == 0) then
- board = flood_fill( board, location - 7) if (col > 0 && row > 0)
- board = flood_fill( board, location - 6) if (row > 0)
- board = flood_fill( board, location + 6) if (row < 9)
- board = flood_fill( board, location + 5) if (col > 0 && row < 9)
- else
- board = flood_fill( board, location - 5) if (col < 4 && row > 0)
- board = flood_fill( board, location - 6) if (row > 0)
- board = flood_fill( board, location + 6) if (row < 9)
- board = flood_fill( board, location + 7) if (col < 4 && row < 9)
- end
- board
- end
-
- # given a location, produces a list of relative locations covered by the piece at this rotation
- def offsets( location)
- if is_even( location) then
- @even_offsets.collect { | value | value + location }
- else
- @odd_offsets.collect { | value | value + location }
- end
- end
-
- # returns a set of offsets relative to the top-left most piece of the rotation (by even or odd rows)
- # this is hard to explain. imagine we have this partial board:
- # 0 0 0 0 0 x [positions 0-5]
- # 0 0 1 1 0 x [positions 6-11]
- # 0 0 1 0 0 x [positions 12-17]
- # 0 1 0 0 0 x [positions 18-23]
- # 0 1 0 0 0 x [positions 24-29]
- # 0 0 0 0 0 x [positions 30-35]
- # ...
- # The top-left of the piece is at position 8, the
- # board would be passed as a set of positions (values array) containing [8,9,14,19,25] not necessarily in that
- # sorted order. Since that array starts on an odd row, the offsets for an odd row are: [0,1,6,11,17] obtained
- # by subtracting 8 from everything. Now imagine the piece shifted up and to the right so it's on an even row:
- # 0 0 0 1 1 x [positions 0-5]
- # 0 0 1 0 0 x [positions 6-11]
- # 0 0 1 0 0 x [positions 12-17]
- # 0 1 0 0 0 x [positions 18-23]
- # 0 0 0 0 0 x [positions 24-29]
- # 0 0 0 0 0 x [positions 30-35]
- # ...
- # Now the positions are [3,4,8,14,19] which after subtracting the lowest value (3) gives [0,1,5,11,16] thus, the
- # offsets for this particular piece are (in even, odd order) [0,1,5,11,16],[0,1,6,11,17] which is what
- # this function would return
- def normalize_offsets( values)
- min = values.min
- even_min = is_even(min)
- other_min = even_min ? min + 6 : min + 7
- other_values = values.collect do | value |
- if is_even(value) then
- value + 6 - other_min
- else
- value + 7 - other_min
- end
- end
- values.collect! { | value | value - min }
-
- if even_min then
- [values, other_values]
- else
- [other_values, values]
- end
- end
-
- # produce a bitmask representation of an array of offset locations
- def mask_for_offsets( offsets )
- mask = 0
- offsets.each { | value | mask = mask + ( 1 << value ) }
- mask
- end
-
- # finds a "safe" position that a position as described by a list of directions can be placed
- # without falling off any edge of the board. the values returned a location to place the first piece
- # at so it will fit after making the described moves
- def start_adjust( directions )
- south = east = 0;
- directions.each do | direction |
- east += 1 if ( direction == :sw || direction == :nw || direction == :west )
- south += 1 if ( direction == :nw || direction == :ne )
- end
- south * 6 + east
- end
-
- # given a set of directions places the piece (as defined by a set of directions) on the board at
- # a location that will not take it off the edge
- def get_values( directions )
- start = start_adjust(directions)
- values = [ start ]
- directions.each do | direction |
- if (start % 12 >= 6) then
- start += @@rotation_odd_adder[direction]
- else
- start += @@rotation_even_adder[direction]
- end
- values += [ start ]
- end
-
- # some moves take you back to an existing location, we'll strip duplicates
- values.uniq
- end
- end
-
- # describes a piece and caches information about its rotations to as to be efficient for iteration
- # ATTRIBUTES:
- # rotations -- all the rotations of the piece
- # type -- a numeic "name" of the piece
- # masks -- an array by location of all legal rotational masks (a n inner array) for that location
- # placed -- the mask that this piece was last placed at (not a location, but the actual mask used)
- class Piece
- attr_reader :rotations, :type, :masks
- attr_accessor :placed
-
- # transform hashes that change one direction into another when you either flip or rotate a set of directions
- @@flip_converter = { :west => :west, :east => :east, :nw => :sw, :ne => :se, :sw => :nw, :se => :ne }
- @@rotate_converter = { :west => :nw, :east => :se, :nw => :ne, :ne => :east, :sw => :west, :se => :sw }
-
- def initialize( directions, type )
- @type = type
- @rotations = Array.new();
- @map = {}
-
- generate_rotations( directions )
- directions.collect! { | value | @@flip_converter[value] }
- generate_rotations( directions )
-
- # creates the masks AND a map that returns [location, rotation] for any given mask
- # this is used when a board is found and we want to draw it, otherwise the map is unused
- @masks = Array.new();
- 0.upto(59) do | i |
- even = true
- @masks[i] = @rotations.collect do | rotation |
- mask = rotation.start_masks[i]
- @map[mask[0]] = [ i, rotation ] if (mask)
- mask || nil
- end
- @masks[i].compact!
- end
- end
-
- # rotates a set of directions through all six angles and adds a Rotation to the list for each one
- def generate_rotations( directions )
- 6.times do
- rotations.push( Rotation.new(directions))
- directions.collect! { | value | @@rotate_converter[value] }
- end
- end
-
- # given a board string, adds this piece to the board at whatever location/rotation
- # important: the outbound board string is 5 wide, the normal location notation is six wide (padded)
- def fill_string( board_string)
- location, rotation = @map[@placed]
- rotation.offsets(location).each do | offset |
- row, col = offset.divmod(6)
- board_string[ row*5 + col, 1 ] = @type.to_s
- end
- end
- end
-
- # a blank bit board having this form:
- #
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 0 0 0 0 0 1
- # 1 1 1 1 1 1
- #
- # where left lest significant bit is the top left and the most significant is the lower right
- # the actual board only consists of the 0 places, the 1 places are blockers to keep things from running
- # off the edges or bottom
- def blank_board
- 0b111111100000100000100000100000100000100000100000100000100000100000
- end
-
- def full_board
- 0b111111111111111111111111111111111111111111111111111111111111111111
- end
-
- # determines if a location (bit position) is in an even row
- def is_even( location)
- (location % 12) < 6
- end
-
- # support function that create three utility maps:
- # $converter -- for each row an array that maps a five bit row (via array mapping)
- # to the a five bit representation of the bits below it
- # $bit_count -- maps a five bit row (via array mapping) to the number of 1s in the row
- # @@new_regions -- maps a five bit row (via array mapping) to an array of "region" arrays
- # a region array has three values the first is a mask of bits in the region,
- # the second is the count of those bits and the third is identical to the first
- # examples:
- # 0b10010 => [ 0b01100, 2, 0b01100 ], [ 0b00001, 1, 0b00001]
- # 0b01010 => [ 0b10000, 1, 0b10000 ], [ 0b00100, 1, 0b00100 ], [ 0b00001, 1, 0b00001]
- # 0b10001 => [ 0b01110, 3, 0b01110 ]
- def create_collector_support
- odd_map = [0b11, 0b110, 0b1100, 0b11000, 0b10000]
- even_map = [0b1, 0b11, 0b110, 0b1100, 0b11000]
-
- all_odds = Array.new(0b100000)
- all_evens = Array.new(0b100000)
- bit_counts = Array.new(0b100000)
- new_regions = Array.new(0b100000)
- 0.upto(0b11111) do | i |
- bit_count = odd = even = 0
- 0.upto(4) do | bit |
- if (i[bit] == 1) then
- bit_count += 1
- odd |= odd_map[bit]
- even |= even_map[bit]
- end
- end
- all_odds[i] = odd
- all_evens[i] = even
- bit_counts[i] = bit_count
- new_regions[i] = create_regions( i)
- end
-
- $converter = []
- 10.times { | row | $converter.push((row % 2 == 0) ? all_evens : all_odds) }
- $bit_counts = bit_counts
- $regions = new_regions.collect { | set | set.collect { | value | [ value, bit_counts[value], value] } }
- end
-
- # determines if a board is punable, meaning that there is no possibility that it
- # can be filled up with pieces. A board is prunable if there is a grouping of unfilled spaces
- # that are not a multiple of five. The following board is an example of a prunable board:
- # 0 0 1 0 0
- # 0 1 0 0 0
- # 1 1 0 0 0
- # 0 1 0 0 0
- # 0 0 0 0 0
- # ...
- #
- # This board is prunable because the top left corner is only 3 bits in area, no piece will ever fit it
- # parameters:
- # board -- an initial bit board (6 bit padded rows, see blank_board for format)
- # location -- starting location, everything above and to the left is already full
- # slotting -- set to true only when testing initial pieces, when filling normally
- # additional assumptions are possible
- #
- # Algorithm:
- # The algorithm starts at the top row (as determined by location) and iterates a row at a time
- # maintainng counts of active open areas (kept in the collector array) each collector contains
- # three values at the start of an iteration:
- # 0: mask of bits that would be adjacent to the collector in this row
- # 1: the number of bits collected so far
- # 2: a scratch space starting as zero, but used during the computation to represent
- # the empty bits in the new row that are adjacent (position 0)
- # The exact procedure is described in-code
- def prunable( board, location, slotting = false)
- collectors = []
- # loop across the rows
- (location / 6).to_i.upto(9) do | row_on |
- # obtain a set of regions representing the bits of the current row.
- regions = $regions[(board >> (row_on * 6)) & 0b11111]
- converter = $converter[row_on]
-
- # track the number of collectors at the start of the cycle so that
- # we don't compute against newly created collectors, only existing collectors
- initial_collector_count = collectors.length
-
- # loop against the regions. For each region of the row
- # we will see if it connects to one or more existing collectors.
- # if it connects to 1 collector, the bits from the region are added to the
- # bits of the collector and the mask is placed in collector[2]
- # If the region overlaps more than one collector then all the collectors
- # it overlaps with are merged into the first one (the others are set to nil in the array)
- # if NO collectors are found then the region is copied as a new collector
- regions.each do | region |
- collector_found = nil
- region_mask = region[2]
- initial_collector_count.times do | collector_num |
- collector = collectors[collector_num]
- if (collector) then
- collector_mask = collector[0]
- if (collector_mask & region_mask != 0) then
- if (collector_found) then
- collector_found[0] |= collector_mask
- collector_found[1] += collector[1]
- collector_found[2] |= collector[2]
- collectors[collector_num] = nil
- else
- collector_found = collector
- collector[1] += region[1]
- collector[2] |= region_mask
- end
- end
- end
- end
- if (collector_found == nil) then
- collectors.push(Array.new(region))
- end
- end
-
- # check the existing collectors, if any collector overlapped no bits in the region its [2] value will
- # be zero. The size of any such reaason is tested if it is not a multiple of five true is returned since
- # the board is prunable. if it is a multiple of five it is removed.
- # Collector that are still active have a new adjacent value [0] set based n the matched bits
- # and have [2] cleared out for the next cycle.
- collectors.length.times do | collector_num |
- collector = collectors[collector_num]
- if (collector) then
- if (collector[2] == 0) then
- return true if (collector[1] % 5 != 0)
- collectors[collector_num] = nil
- else
- # if a collector matches all bits in the row then we can return unprunable early for the
- # following reasons:
- # 1) there can be no more unavailable bits bince we fill from the top left downward
- # 2) all previous regions have been closed or joined so only this region can fail
- # 3) this region must be good since there can never be only 1 region that is nuot
- # a multiple of five
- # this rule only applies when filling normally, so we ignore the rule if we are "slotting"
- # in pieces to see what configurations work for them (the only other time this algorithm is used).
- return false if (collector[2] == 0b11111 && !slotting)
- collector[0] = converter[collector[2]]
- collector[2] = 0
- end
- end
- end
-
- # get rid of all the empty converters for the next round
- collectors.compact!
- end
- return false if (collectors.length <= 1) # 1 collector or less and the region is fine
- collectors.any? { | collector | (collector[1] % 5) != 0 } # more than 1 and we test them all for bad size
- end
-
- # creates a region given a row mask. see prunable for what a "region" is
- def create_regions( value )
- regions = []
- cur_region = 0
- 5.times do | bit |
- if (value[bit] == 0) then
- cur_region |= 1 << bit
- else
- if (cur_region != 0 ) then
- regions.push( cur_region)
- cur_region = 0;
- end
- end
- end
- regions.push(cur_region) if (cur_region != 0)
- regions
- end
-
- # find up to the counted number of solutions (or all solutions) and prints the final result
- def find_all
- find_top( 1)
- find_top( 0)
- print_results
- end
-
- # show the board
- def print_results
- print "#{@boards_found} solutions found\n\n"
- print_full_board( @min_board)
- print "\n"
- print_full_board( @max_board)
- print "\n"
- end
-
- # finds solutions. This special version of the main function is only used for the top level
- # the reason for it is basically to force a particular ordering on how the rotations are tested for
- # the first piece. It is called twice, first looking for placements of the odd rotations and then
- # looking for placements of the even locations.
- #
- # WHY?
- # Since any found solution has an inverse we want to maximize finding solutions that are not already found
- # as an inverse. The inverse will ALWAYS be 3 one of the piece configurations that is exactly 3 rotations away
- # (an odd number). Checking even vs odd then produces a higher probability of finding more pieces earlier
- # in the cycle. We still need to keep checking all the permutations, but our probability of finding one will
- # diminsh over time. Since we are TOLD how many to search for this lets us exit before checking all pieces
- # this bennifit is very great when seeking small numbers of solutions and is 0 when looking for more than the
- # maximum number
- def find_top( rotation_skip)
- board = blank_board
- (@pieces.length-1).times do
- piece = @pieces.shift
- piece.masks[0].each do | mask, imask, cmask |
- if ((rotation_skip += 1) % 2 == 0) then
- piece.placed = mask
- find( 1, 1, board | mask)
- end
- end
- @pieces.push(piece)
- end
- piece = @pieces.shift
- @pieces.push(piece)
- end
-
- # the normail find routine, iterates through the available pieces, checks all rotations at the current location
- # and adds any boards found. depth is achieved via recursion. the overall approach is described
- # here: http://www-128.ibm.com/developerworks/java/library/j-javaopt/
- # parameters:
- # start_location -- where to start looking for place for the next piece at
- # placed -- number of pieces placed
- # board -- current state of the board
- #
- # see in-code comments
- def find( start_location, placed, board)
- # find the next location to place a piece by looking for an empty bit
- while board[start_location] == 1
- start_location += 1
- end
-
- @pieces.length.times do
- piece = @pieces.shift
- piece.masks[start_location].each do | mask, imask, cmask |
- if ( board & cmask == imask) then
- piece.placed = mask
- if (placed == 9) then
- add_board
- else
- find( start_location + 1, placed + 1, board | mask)
- end
- end
- end
- @pieces.push(piece)
- end
- end
-
- # print the board
- def print_full_board( board_string)
- 10.times do | row |
- print " " if (row % 2 == 1)
- 5.times do | col |
- print "#{board_string[row*5 + col,1]} "
- end
- print "\n"
- end
- end
-
- # when a board is found we "draw it" into a string and then flip that string, adding both to
- # the list (hash) of solutions if they are unique.
- def add_board
- board_string = "99999999999999999999999999999999999999999999999999"
- @all_pieces.each { | piece | piece.fill_string( board_string ) }
- save( board_string)
- save( board_string.reverse)
- end
-
- # adds a board string to the list (if new) and updates the current best/worst board
- def save( board_string)
- if (@all_boards[board_string] == nil) then
- @min_board = board_string if (board_string < @min_board)
- @max_board = board_string if (board_string > @max_board)
- @all_boards.store(board_string,true)
- @boards_found += 1
-
- # the exit motif is a time saver. Ideally the function should return, but those tests
- # take noticeable time (performance).
- if (@boards_found == @stop_count) then
- print_results
- exit(0)
- end
- end
- end
-
-
- ##
- ## MAIN BODY :)
- ##
- create_collector_support
- @pieces = [
- Piece.new( [ :nw, :ne, :east, :east ], 2),
- Piece.new( [ :ne, :se, :east, :ne ], 7),
- Piece.new( [ :ne, :east, :ne, :nw ], 1),
- Piece.new( [ :east, :sw, :sw, :se ], 6),
- Piece.new( [ :east, :ne, :se, :ne ], 5),
- Piece.new( [ :east, :east, :east, :se ], 0),
- Piece.new( [ :ne, :nw, :se, :east, :se ], 4),
- Piece.new( [ :se, :se, :se, :west ], 9),
- Piece.new( [ :se, :se, :east, :se ], 8),
- Piece.new( [ :east, :east, :sw, :se ], 3)
- ];
-
- @all_pieces = Array.new( @pieces)
-
- @min_board = "99999999999999999999999999999999999999999999999999"
- @max_board = "00000000000000000000000000000000000000000000000000"
- @stop_count = ARGV[0].to_i || 2089
- @all_boards = {}
- @boards_found = 0
-
- find_all ######## DO IT!!!
-loop_count: 1
diff --git a/benchmark/so_nbody.yml b/benchmark/so_nbody.yml
deleted file mode 100644
index e4d111cd38..0000000000
--- a/benchmark/so_nbody.yml
+++ /dev/null
@@ -1,152 +0,0 @@
-prelude: |
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org
-benchmark:
- so_nbody: |
- #
- # Optimized for Ruby by Jesse Millikan
- # From version ported by Michael Neumann from the C gcc version,
- # which was written by Christoph Bauer.
-
- SOLAR_MASS = 4 * Math::PI**2
- DAYS_PER_YEAR = 365.24
-
- def _puts *args
- end
-
- class Planet
- attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass
-
- def initialize(x, y, z, vx, vy, vz, mass)
- @x, @y, @z = x, y, z
- @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR
- @mass = mass * SOLAR_MASS
- end
-
- def move_from_i(bodies, nbodies, dt, i)
- while i < nbodies
- b2 = bodies[i]
- dx = @x - b2.x
- dy = @y - b2.y
- dz = @z - b2.z
-
- distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
- mag = dt / (distance * distance * distance)
- b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag
-
- @vx -= dx * b2_mass_mag
- @vy -= dy * b2_mass_mag
- @vz -= dz * b2_mass_mag
- b2.vx += dx * b_mass_mag
- b2.vy += dy * b_mass_mag
- b2.vz += dz * b_mass_mag
- i += 1
- end
-
- @x += dt * @vx
- @y += dt * @vy
- @z += dt * @vz
- end
- end
-
- def energy(bodies)
- e = 0.0
- nbodies = bodies.size
-
- for i in 0 ... nbodies
- b = bodies[i]
- e += 0.5 * b.mass * (b.vx * b.vx + b.vy * b.vy + b.vz * b.vz)
- for j in (i + 1) ... nbodies
- b2 = bodies[j]
- dx = b.x - b2.x
- dy = b.y - b2.y
- dz = b.z - b2.z
- distance = Math.sqrt(dx * dx + dy * dy + dz * dz)
- e -= (b.mass * b2.mass) / distance
- end
- end
- e
- end
-
- def offset_momentum(bodies)
- px, py, pz = 0.0, 0.0, 0.0
-
- for b in bodies
- m = b.mass
- px += b.vx * m
- py += b.vy * m
- pz += b.vz * m
- end
-
- b = bodies[0]
- b.vx = - px / SOLAR_MASS
- b.vy = - py / SOLAR_MASS
- b.vz = - pz / SOLAR_MASS
- end
-
- BODIES = [
- # sun
- Planet.new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0),
-
- # jupiter
- Planet.new(
- 4.84143144246472090e+00,
- -1.16032004402742839e+00,
- -1.03622044471123109e-01,
- 1.66007664274403694e-03,
- 7.69901118419740425e-03,
- -6.90460016972063023e-05,
- 9.54791938424326609e-04),
-
- # saturn
- Planet.new(
- 8.34336671824457987e+00,
- 4.12479856412430479e+00,
- -4.03523417114321381e-01,
- -2.76742510726862411e-03,
- 4.99852801234917238e-03,
- 2.30417297573763929e-05,
- 2.85885980666130812e-04),
-
- # uranus
- Planet.new(
- 1.28943695621391310e+01,
- -1.51111514016986312e+01,
- -2.23307578892655734e-01,
- 2.96460137564761618e-03,
- 2.37847173959480950e-03,
- -2.96589568540237556e-05,
- 4.36624404335156298e-05),
-
- # neptune
- Planet.new(
- 1.53796971148509165e+01,
- -2.59193146099879641e+01,
- 1.79258772950371181e-01,
- 2.68067772490389322e-03,
- 1.62824170038242295e-03,
- -9.51592254519715870e-05,
- 5.15138902046611451e-05)
- ]
-
- init = 200_000 # ARGV[0]
- n = Integer(init)
-
- offset_momentum(BODIES)
-
- puts "%.9f" % energy(BODIES)
-
- nbodies = BODIES.size
- dt = 0.01
-
- n.times do
- i = 0
- while i < nbodies
- b = BODIES[i]
- b.move_from_i(BODIES, nbodies, dt, i + 1)
- i += 1
- end
- end
-
- puts "%.9f" % energy(BODIES)
-loop_count: 1
diff --git a/benchmark/so_nested_loop.yml b/benchmark/so_nested_loop.yml
deleted file mode 100644
index 64a6901eac..0000000000
--- a/benchmark/so_nested_loop.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
- # from Avi Bryant
-benchmark:
- so_nested_loop: |
-
- n = 16 # Integer(ARGV.shift || 1)
- x = 0
- n.times do
- n.times do
- n.times do
- n.times do
- n.times do
- n.times do
- x += 1
- end
- end
- end
- end
- end
- end
- # puts x
-loop_count: 1
diff --git a/benchmark/so_nsieve.yml b/benchmark/so_nsieve.yml
deleted file mode 100644
index 0799cff7a7..0000000000
--- a/benchmark/so_nsieve.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-prelude: |
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org/
-benchmark:
- so_nsieve: |
- #
- # contributed by Glenn Parker, March 2005
- # modified by Evan Phoenix, Sept 2006
-
- def sieve(m)
- flags = Flags.dup[0,m]
- count = 0
- pmax = m - 1
- p = 2
- while p <= pmax
- unless flags[p].zero?
- count += 1
- mult = p
- while mult <= pmax
- flags[mult] = 0
- mult += p
- end
- end
- p += 1
- end
- count
- end
-
- n = 9 # (ARGV[0] || 2).to_i
- Flags = ("\x1" * ( 2 ** n * 10_000)).unpack("c*")
-
- n.downto(n-2) do |exponent|
- break if exponent < 0
- m = (1 << exponent) * 10_000
- # m = (2 ** exponent) * 10_000
- count = sieve(m)
- printf "Primes up to %8d %8d\n", m, count
- end
-loop_count: 1
diff --git a/benchmark/so_nsieve_bits.yml b/benchmark/so_nsieve_bits.yml
deleted file mode 100644
index 08b47f53bb..0000000000
--- a/benchmark/so_nsieve_bits.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- #coding: us-ascii
-benchmark:
- so_nsieve_bits: |
- #
- # The Great Computer Language Shootout
- # http://shootout.alioth.debian.org/
- #
- # nsieve-bits in Ruby
- # Contributed by Glenn Parker, March 2005
-
- CharExponent = 3
- BitsPerChar = 1 << CharExponent
- LowMask = BitsPerChar - 1
-
- def sieve(m)
- items = "\xFF" * ((m / BitsPerChar) + 1)
- masks = ""
- BitsPerChar.times do |b|
- masks << (1 << b).chr
- end
-
- count = 0
- pmax = m - 1
- 2.step(pmax, 1) do |p|
- if items[p >> CharExponent][p & LowMask] == 1
- count += 1
- p.step(pmax, p) do |mult|
- a = mult >> CharExponent
- b = mult & LowMask
- items[a] -= masks[b] if items[a][b] != 0
- end
- end
- end
- count
- end
-
- n = 9 # (ARGV[0] || 2).to_i
- n.step(n - 2, -1) do |exponent|
- break if exponent < 0
- m = 2 ** exponent * 10_000
- count = sieve(m)
- printf "Primes up to %8d %8d\n", m, count
- end
-loop_count: 1
diff --git a/benchmark/so_object.yml b/benchmark/so_object.yml
deleted file mode 100644
index 89fbce83cd..0000000000
--- a/benchmark/so_object.yml
+++ /dev/null
@@ -1,59 +0,0 @@
-prelude: |
- #!/usr/bin/ruby
- # -*- mode: ruby -*-
- # $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
- # http://www.bagley.org/~doug/shootout/
- # with help from Aristarkh Zagorodnikov
-benchmark:
- so_object: |
-
- class Toggle
- def initialize(start_state)
- @bool = start_state
- end
-
- def value
- @bool
- end
-
- def activate
- @bool = !@bool
- self
- end
- end
-
- class NthToggle < Toggle
- def initialize(start_state, max_counter)
- super start_state
- @count_max = max_counter
- @counter = 0
- end
-
- def activate
- @counter += 1
- if @counter >= @count_max
- @bool = !@bool
- @counter = 0
- end
- self
- end
- end
-
- n = 1500000 # (ARGV.shift || 1).to_i
-
- toggle = Toggle.new 1
- 5.times do
- toggle.activate.value ? 'true' : 'false'
- end
- n.times do
- toggle = Toggle.new 1
- end
-
- ntoggle = NthToggle.new 1, 3
- 8.times do
- ntoggle.activate.value ? 'true' : 'false'
- end
- n.times do
- ntoggle = NthToggle.new 1, 3
- end
-loop_count: 1
diff --git a/benchmark/so_partial_sums.yml b/benchmark/so_partial_sums.yml
deleted file mode 100644
index d45017bca8..0000000000
--- a/benchmark/so_partial_sums.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-benchmark:
- so_partial_sums: |
- n = 2_500_000 # (ARGV.shift || 1).to_i
-
- alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0
-
- 1.upto(n) do |d|
- d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)
-
- s0 += (2.0 / 3.0) ** (d - 1.0)
- s1 += 1.0 / Math.sqrt(d)
- s2 += 1.0 / (d * (d + 1.0))
- s3 += 1.0 / (d3 * ds * ds)
- s4 += 1.0 / (d3 * dc * dc)
- s5 += 1.0 / d
- s6 += 1.0 / d2
- s7 += alt / d
- s8 += alt / (2.0 * d - 1.0)
-
- alt = -alt
- end
-
- if false
- printf("%.9f\t(2/3)^k\n", s0)
- printf("%.9f\tk^-0.5\n", s1)
- printf("%.9f\t1/k(k+1)\n", s2)
- printf("%.9f\tFlint Hills\n", s3)
- printf("%.9f\tCookson Hills\n", s4)
- printf("%.9f\tHarmonic\n", s5)
- printf("%.9f\tRiemann Zeta\n", s6)
- printf("%.9f\tAlternating Harmonic\n", s7)
- printf("%.9f\tGregory\n", s8)
- end
-loop_count: 1
diff --git a/benchmark/so_pidigits.yml b/benchmark/so_pidigits.yml
deleted file mode 100644
index 793745f5b5..0000000000
--- a/benchmark/so_pidigits.yml
+++ /dev/null
@@ -1,95 +0,0 @@
-prelude: |
- # The Great Computer Language Shootout
- # http://shootout.alioth.debian.org/
-benchmark:
- so_pidigits: |
- #
- # contributed by Gabriele Renzi
-
- class PiDigitSpigot
-
- def initialize()
- @z = Transformation.new 1,0,0,1
- @x = Transformation.new 0,0,0,0
- @inverse = Transformation.new 0,0,0,0
- end
-
- def next!
- @y = @z.extract(3)
- if safe? @y
- @z = produce(@y)
- @y
- else
- @z = consume @x.next!()
- next!()
- end
- end
-
- def safe?(digit)
- digit == @z.extract(4)
- end
-
- def produce(i)
- @inverse.qrst(10,-10*i,0,1).compose(@z)
- end
-
- def consume(a)
- @z.compose(a)
- end
- end
-
-
- class Transformation
- attr_reader :q, :r, :s, :t
- def initialize(q, r, s, t)
- @q,@r,@s,@t,@k = q,r,s,t,0
- end
-
- def next!()
- @q = @k = @k + 1
- @r = 4 * @k + 2
- @s = 0
- @t = 2 * @k + 1
- self
- end
-
- def extract(j)
- (@q * j + @r) / (@s * j + @t)
- end
-
- def compose(a)
- self.class.new( @q * a.q,
- @q * a.r + r * a.t,
- @s * a.q + t * a.s,
- @s * a.r + t * a.t
- )
- end
-
- def qrst *args
- initialize *args
- self
- end
-
-
- end
-
-
- WIDTH = 10
- n = 2_500 # Integer(ARGV[0])
- j = 0
-
- digits = PiDigitSpigot.new
-
- while n > 0
- if n >= WIDTH
- WIDTH.times {print digits.next!}
- j += WIDTH
- else
- n.times {print digits.next!}
- (WIDTH-n).times {print " "}
- j += n
- end
- puts "\t:"+j.to_s
- n -= WIDTH
- end
-loop_count: 1
diff --git a/benchmark/so_random.yml b/benchmark/so_random.yml
deleted file mode 100644
index 3a39453377..0000000000
--- a/benchmark/so_random.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-prelude: |
- # from http://www.bagley.org/~doug/shootout/bench/random/random.ruby
-benchmark:
- so_random: |
-
- IM = 139968.0
- IA = 3877.0
- IC = 29573.0
-
- $last = 42.0
-
- def gen_random(max)
- (max * ($last = ($last * IA + IC) % IM)) / IM
- end
-
- N = 3_000_000
-
- i = 0
- while i<N
- i +=1
- gen_random(100.0)
- end
- # "%.9f" % gen_random(100.0)
-loop_count: 1
diff --git a/benchmark/so_sieve.yml b/benchmark/so_sieve.yml
deleted file mode 100644
index ae90f8f6fb..0000000000
--- a/benchmark/so_sieve.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-prelude: |
- # from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
-benchmark:
- so_sieve: |
- num = 500
- count = i = j = 0
- flags0 = Array.new(8192,1)
- k = 0
- while k < num
- k += 1
- count = 0
- flags = flags0.dup
- i = 2
- while i<8192
- i += 1
- if flags[i]
- # remove all multiples of prime: i
- j = i*i
- while j < 8192
- j += i
- flags[j] = nil
- end
- count += 1
- end
- end
- end
- count
-loop_count: 1
diff --git a/benchmark/so_spectralnorm.yml b/benchmark/so_spectralnorm.yml
deleted file mode 100644
index 45373b6476..0000000000
--- a/benchmark/so_spectralnorm.yml
+++ /dev/null
@@ -1,54 +0,0 @@
-prelude: |
- # The Computer Language Shootout
- # http://shootout.alioth.debian.org/
- # Contributed by Sokolov Yura
-benchmark:
- so_spectralnorm: |
-
- def eval_A(i,j)
- return 1.0/((i+j)*(i+j+1)/2+i+1)
- end
-
- def eval_A_times_u(u)
- v, i = nil, nil
- (0..u.length-1).collect { |i|
- v = 0
- for j in 0..u.length-1
- v += eval_A(i,j)*u[j]
- end
- v
- }
- end
-
- def eval_At_times_u(u)
- v, i = nil, nil
- (0..u.length-1).collect{|i|
- v = 0
- for j in 0..u.length-1
- v += eval_A(j,i)*u[j]
- end
- v
- }
- end
-
- def eval_AtA_times_u(u)
- return eval_At_times_u(eval_A_times_u(u))
- end
-
- n = 500 # ARGV[0].to_i
-
- u=[1]*n
- for i in 1..10
- v=eval_AtA_times_u(u)
- u=eval_AtA_times_u(v)
- end
- vBv=0
- vv=0
- for i in 0..n-1
- vBv += u[i]*v[i]
- vv += v[i]*v[i]
- end
-
- str = "%0.9f" % (Math.sqrt(vBv/vv)), "\n"
- # print str
-loop_count: 1
diff --git a/benchmark/string_index.yml b/benchmark/string_index.yml
deleted file mode 100644
index f89193a448..0000000000
--- a/benchmark/string_index.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-benchmark:
- string_index: |
- str1 = "あ" * 1024 + "い" # not single byte optimizable
- str2 = "い"
- 100_000.times { str1.index(str2) }
-loop_count: 1
diff --git a/benchmark/string_scan_re.yml b/benchmark/string_scan_re.yml
deleted file mode 100644
index a1d249ff52..0000000000
--- a/benchmark/string_scan_re.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- string_scan_re: |
- str = Array.new(1_000, 'abc').join(',')
- 1_000.times { str.scan(/abc/) }
-loop_count: 1
diff --git a/benchmark/string_scan_str.yml b/benchmark/string_scan_str.yml
deleted file mode 100644
index 3c1bae451a..0000000000
--- a/benchmark/string_scan_str.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- string_scan_str: |
- str = Array.new(1_000, 'abc').join(',')
- 1_000.times { str.scan('abc') }
-loop_count: 1
diff --git a/benchmark/time_subsec.yml b/benchmark/time_subsec.yml
deleted file mode 100644
index ee787639c6..0000000000
--- a/benchmark/time_subsec.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-benchmark:
- time_subsec: |
- t = Time.now
- 4000000.times { t.subsec }
-loop_count: 1
diff --git a/benchmark/vm3_backtrace.yml b/benchmark/vm3_backtrace.yml
deleted file mode 100644
index 58df4bc191..0000000000
--- a/benchmark/vm3_backtrace.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-prelude: |
- # get last backtrace
-benchmark:
- vm3_backtrace: |
-
- begin
- caller(0, 0)
- rescue ArgumentError
- alias caller_orig caller
- def caller lev, n
- caller_orig(lev)[0..n]
- end
- end
-
- def rec n
- if n < 0
- 100_000.times{
- caller(0, 1)
- }
- else
- rec(n-1)
- end
- end
-
- rec 50
-loop_count: 1
diff --git a/benchmark/vm3_clearmethodcache.yml b/benchmark/vm3_clearmethodcache.yml
deleted file mode 100644
index 63dea7aa58..0000000000
--- a/benchmark/vm3_clearmethodcache.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-benchmark:
- vm3_clearmethodcache: |
- i = 0
- while i<200_000
- i += 1
-
- Class.new{
- def m; end
- }
- end
-loop_count: 1
diff --git a/benchmark/vm3_gc.yml b/benchmark/vm3_gc.yml
deleted file mode 100644
index 5ca177a79a..0000000000
--- a/benchmark/vm3_gc.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-benchmark:
- vm3_gc: |
- 5000.times do
- 100.times do
- {"xxxx"=>"yyyy"}
- end
- GC.start
- end
-loop_count: 1
diff --git a/benchmark/vm3_gc_old_full.yml b/benchmark/vm3_gc_old_full.yml
deleted file mode 100644
index 11958c2d0a..0000000000
--- a/benchmark/vm3_gc_old_full.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- vm3_gc_old_full: |
- old_object = Array.new(1_000_000){''}
- 100.times do
- GC.start
- end
-loop_count: 1
diff --git a/benchmark/vm3_gc_old_immediate.yml b/benchmark/vm3_gc_old_immediate.yml
deleted file mode 100644
index 3aea9c05f9..0000000000
--- a/benchmark/vm3_gc_old_immediate.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- vm3_gc_old_immediate: |
- old_object = Array.new(1_000_000){''}
- 30_000.times do
- GC.start(full_mark: false, immediate_sweep: true)
- end
-loop_count: 1
diff --git a/benchmark/vm3_gc_old_lazy.yml b/benchmark/vm3_gc_old_lazy.yml
deleted file mode 100644
index 37ad5c38f1..0000000000
--- a/benchmark/vm3_gc_old_lazy.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-benchmark:
- vm3_gc_old_lazy: |
- old_object = Array.new(1_000_000){''}
- 30_000.times do
- GC.start(full_mark: false, immediate_sweep: false)
- end
-loop_count: 1
diff --git a/benchmark/vm_symbol_block_pass.yml b/benchmark/vm_symbol_block_pass.yml
deleted file mode 100644
index c690b5944e..0000000000
--- a/benchmark/vm_symbol_block_pass.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-benchmark:
- vm_symbol_block_pass: |
- class C
- 1000.times {|i|
- eval("def i#{i};end")
- }
- end
-
- c = C.new
- m = C.instance_methods(false)
- 5_000.times do
- m.each do |n|
- c.tap(&n)
- end
- end
-loop_count: 1
diff --git a/benchmark/vm_thread_alive_check1.yml b/benchmark/vm_thread_alive_check1.yml
deleted file mode 100644
index 4ab97401da..0000000000
--- a/benchmark/vm_thread_alive_check1.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-benchmark:
- vm_thread_alive_check1: |
- 5_000.times{
- t = Thread.new{}
- while t.alive?
- Thread.pass
- end
- }
-loop_count: 1
diff --git a/benchmark/vm_thread_close.yml b/benchmark/vm_thread_close.yml
deleted file mode 100644
index 4867f1ca2a..0000000000
--- a/benchmark/vm_thread_close.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-benchmark:
- vm_thread_close: |
- 1000.times { Thread.new { sleep } }
- i = 0
- while i<100_000 # benchmark loop 3
- i += 1
- IO.pipe.each(&:close)
- end
-loop_count: 1
diff --git a/benchmark/vm_thread_condvar1.yml b/benchmark/vm_thread_condvar1.yml
deleted file mode 100644
index 1f481ab757..0000000000
--- a/benchmark/vm_thread_condvar1.yml
+++ /dev/null
@@ -1,32 +0,0 @@
-prelude: |
- # two threads, two mutex, two condvar ping-pong
-benchmark:
- vm_thread_condvar1: |
- require 'thread'
- m1 = Mutex.new
- m2 = Mutex.new
- cv1 = ConditionVariable.new
- cv2 = ConditionVariable.new
- max = 100000
- i = 0
- wait = nil
- m2.synchronize do
- wait = Thread.new do
- m1.synchronize do
- m2.synchronize { cv2.signal }
- while (i += 1) < max
- cv1.wait(m1)
- cv2.signal
- end
- end
- end
- cv2.wait(m2)
- end
- m1.synchronize do
- while i < max
- cv1.signal
- cv2.wait(m1)
- end
- end
- wait.join
-loop_count: 1
diff --git a/benchmark/vm_thread_condvar2.yml b/benchmark/vm_thread_condvar2.yml
deleted file mode 100644
index 5b5798c7c5..0000000000
--- a/benchmark/vm_thread_condvar2.yml
+++ /dev/null
@@ -1,39 +0,0 @@
-prelude: |
- # many threads, one mutex, many condvars
-benchmark:
- vm_thread_condvar2: |
- require 'thread'
- m = Mutex.new
- cv1 = ConditionVariable.new
- cv2 = ConditionVariable.new
- max = 1000
- n = 100
- waiting = 0
- scvs = []
- waiters = n.times.map do |i|
- start_cv = ConditionVariable.new
- scvs << start_cv
- start_mtx = Mutex.new
- start_mtx.synchronize do
- th = Thread.new(start_mtx, start_cv) do |sm, scv|
- m.synchronize do
- sm.synchronize { scv.signal }
- max.times do
- cv2.signal if (waiting += 1) == n
- cv1.wait(m)
- end
- end
- end
- start_cv.wait(start_mtx)
- th
- end
- end
- m.synchronize do
- max.times do
- cv2.wait(m) until waiting == n
- waiting = 0
- cv1.broadcast
- end
- end
- waiters.each(&:join)
-loop_count: 1
diff --git a/benchmark/vm_thread_create_join.yml b/benchmark/vm_thread_create_join.yml
deleted file mode 100644
index 7fe82b3fb0..0000000000
--- a/benchmark/vm_thread_create_join.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-benchmark:
- vm_thread_create_join: |
- i = 0
- while i<100_000 # benchmark loop 3
- i += 1
- Thread.new{
- }.join
- end
-loop_count: 1
diff --git a/benchmark/vm_thread_mutex1.yml b/benchmark/vm_thread_mutex1.yml
deleted file mode 100644
index 33ab7a2651..0000000000
--- a/benchmark/vm_thread_mutex1.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-prelude: |
- # one thread, one mutex (no contention)
-benchmark:
- vm_thread_mutex1: |
-
- require 'thread'
- m = Thread::Mutex.new
- r = 0
- max = 2000
- lmax = max * max
- (1..1).map{
- Thread.new{
- i = 0
- while i<lmax
- i += 1
- m.synchronize{
- r += 1
- }
- end
- }
- }.each{|e|
- e.join
- }
- raise r.to_s if r != max * max
-loop_count: 1
diff --git a/benchmark/vm_thread_mutex2.yml b/benchmark/vm_thread_mutex2.yml
deleted file mode 100644
index e6abe59635..0000000000
--- a/benchmark/vm_thread_mutex2.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-prelude: |
- # two threads, one mutex
-benchmark:
- vm_thread_mutex2: |
-
- require 'thread'
- m = Thread::Mutex.new
- r = 0
- max = 2000
- lmax = (max * max)/2
- (1..2).map{
- Thread.new{
- i = 0
- while i<lmax
- i += 1
- m.synchronize{
- r += 1
- }
- end
- }
- }.each{|e|
- e.join
- }
- raise r.to_s if r != max * max
-loop_count: 1
diff --git a/benchmark/vm_thread_mutex3.yml b/benchmark/vm_thread_mutex3.yml
deleted file mode 100644
index 99f3b81f99..0000000000
--- a/benchmark/vm_thread_mutex3.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-prelude: |
- # 1000 threads, one mutex
-benchmark:
- vm_thread_mutex3: |
-
- require 'thread'
- m = Thread::Mutex.new
- r = 0
- max = 2000
- (1..max).map{
- Thread.new{
- i = 0
- while i<max
- i += 1
- m.synchronize{
- r += 1
- }
- end
- }
- }.each{|e|
- e.join
- }
- raise r.to_s if r != max * max
-loop_count: 1
diff --git a/benchmark/vm_thread_pass.yml b/benchmark/vm_thread_pass.yml
deleted file mode 100644
index c5f264ee36..0000000000
--- a/benchmark/vm_thread_pass.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-prelude: |
- # Plenty Thtread.pass
- # A performance may depend on GVL implementation.
-benchmark:
- vm_thread_pass: |
-
- tmax = (ARGV.shift || 2).to_i
- lmax = 200_000 / tmax
-
- (1..tmax).map{
- Thread.new{
- lmax.times{
- Thread.pass
- }
- }
- }.each{|t| t.join}
-loop_count: 1
diff --git a/benchmark/vm_thread_pass_flood.yml b/benchmark/vm_thread_pass_flood.yml
deleted file mode 100644
index 953288ebe4..0000000000
--- a/benchmark/vm_thread_pass_flood.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-prelude: |
- # n.b. this is a good test for GVL when pinned to a single CPU
-benchmark:
- vm_thread_pass_flood: |
-
- 1000.times{
- Thread.new{loop{Thread.pass}}
- }
-
- i = 0
- while i<10000
- i += 1
- end
-loop_count: 1
diff --git a/benchmark/vm_thread_pipe.yml b/benchmark/vm_thread_pipe.yml
deleted file mode 100644
index fe4f3b8166..0000000000
--- a/benchmark/vm_thread_pipe.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-prelude: |
- # Measure small and plenty pipe read/write.
- # A performance may depend on GVL implementation.
-benchmark:
- vm_thread_pipe: |
-
- lmax = 100_000
- r, w = IO.pipe
- [Thread.new{
- lmax.times{
- w.write('a')
- }
- p "w:exit"
- }, Thread.new{
- lmax.times{
- r.read(1)
- }
- p "r:exit"
- }].each{|t| t.join}
-loop_count: 1
diff --git a/benchmark/vm_thread_queue.yml b/benchmark/vm_thread_queue.yml
deleted file mode 100644
index 1294ad3a13..0000000000
--- a/benchmark/vm_thread_queue.yml
+++ /dev/null
@@ -1,21 +0,0 @@
-benchmark:
- vm_thread_queue: |
- require 'thread'
-
- n = 1_000_000
- q = Thread::Queue.new
- consumer = Thread.new{
- while q.pop
- # consuming
- end
- }
-
- producer = Thread.new{
- n.times{
- q.push true
- }
- q.push nil
- }
-
- consumer.join
-loop_count: 1
diff --git a/benchmark/vm_thread_sized_queue.yml b/benchmark/vm_thread_sized_queue.yml
deleted file mode 100644
index 0a79bd4fc1..0000000000
--- a/benchmark/vm_thread_sized_queue.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-benchmark:
- vm_thread_sized_queue: |
- require 'thread'
- # on producer, one consumer
-
- n = 1_000_000
- q = Thread::SizedQueue.new(100)
- consumer = Thread.new{
- while q.pop
- # consuming
- end
- }
-
- producer = Thread.new{
- while n > 0
- q.push true
- n -= 1
- end
- q.push nil
- }
-
- consumer.join
-loop_count: 1
diff --git a/benchmark/vm_thread_sized_queue2.yml b/benchmark/vm_thread_sized_queue2.yml
deleted file mode 100644
index 7a5c2251c1..0000000000
--- a/benchmark/vm_thread_sized_queue2.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-benchmark:
- vm_thread_sized_queue2: |
- require 'thread'
- # one producer, many consumers
- n = 1_000_000
- m = 10
- q = Thread::SizedQueue.new(100)
- consumers = m.times.map do
- Thread.new do
- while q.pop
- # consuming
- end
- end
- end
-
- producer = Thread.new do
- while n > 0
- q.push true
- n -= 1
- end
- m.times { q.push nil }
- end
-
- producer.join
- consumers.each(&:join)
-loop_count: 1
diff --git a/benchmark/vm_thread_sized_queue3.yml b/benchmark/vm_thread_sized_queue3.yml
deleted file mode 100644
index 6eefe50984..0000000000
--- a/benchmark/vm_thread_sized_queue3.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-benchmark:
- vm_thread_sized_queue3: |
- require 'thread'
- # many producers, one consumer
- n = 1_000_000
- m = 10
- q = Thread::SizedQueue.new(100)
- consumer = Thread.new do
- while q.pop
- # consuming
- end
- end
-
- producers = m.times.map do
- Thread.new do
- while n > 0
- q.push true
- n -= 1
- end
- end
- end
- producers.each(&:join)
- q.push nil
- consumer.join
-loop_count: 1
diff --git a/benchmark/vm_thread_sized_queue4.yml b/benchmark/vm_thread_sized_queue4.yml
deleted file mode 100644
index 2af8ea4ebe..0000000000
--- a/benchmark/vm_thread_sized_queue4.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-benchmark:
- vm_thread_sized_queue4: |
- require 'thread'
- # many producers, many consumers
- nr = 1_000_000
- n = 10
- m = 10
- q = Thread::SizedQueue.new(100)
- consumers = n.times.map do
- Thread.new do
- while q.pop
- # consuming
- end
- end
- end
-
- producers = m.times.map do
- Thread.new do
- while nr > 0
- q.push true
- nr -= 1
- end
- end
- end
-
- producers.each(&:join)
- n.times { q.push nil }
- consumers.each(&:join)
-loop_count: 1