diff options
| author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
|---|---|---|
| committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
| commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
| tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/sample/benchmark.rb | |
Fresh start
Diffstat (limited to 'jni/ruby/sample/benchmark.rb')
| -rw-r--r-- | jni/ruby/sample/benchmark.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/jni/ruby/sample/benchmark.rb b/jni/ruby/sample/benchmark.rb new file mode 100644 index 0000000..de5d66f --- /dev/null +++ b/jni/ruby/sample/benchmark.rb @@ -0,0 +1,19 @@ +require 'benchmark' + +include Benchmark + +n = ARGV[0].to_i.nonzero? || 50000 +puts %Q([#{n} times iterations of `a = "1"']) +benchmark(CAPTION, 7, FORMAT) do |x| + x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure + x.report("times:") {n.times do ; _ = "1"; end} + x.report("upto:") {1.upto(n) do ; _ = "1"; end} +end + +benchmark do + [ + measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure + measure{n.times do ; _ = "1"; end}, + measure{1.upto(n) do ; _ = "1"; end} + ] +end |
