#!/usr/bin/env ruby
# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

require "benchmark"

def bench_itself
  puts Benchmark.measure { "a"*1_000_000 }

  n = 50_000
  Benchmark.bm(7) {|x|
    x.report { for i in 1..n; a = "1"; end }
    x.report { n.times do   ; a = "1"; end }
    x.report { 1.upto(n) do ; a = "1"; end }
  }
end

def benchmark
  result = nil
  Benchmark.bm {|x|
    x.report { 
      result = yield 
    }
  }
  return result
end

def bench_benchmark
  benchmark {
    "a"*10_000_000 
  }
end

def main
  #bench_itself
  bench_benchmark
end
main
