Stanislav Karchebny wrote:

int sum = 0; for (i = 0; i < 50000; ++i) sum += data[i];
[...]
btw, ruby/lib/1.8/benchmark.rb is a good place to look for several ways to
perform this test.

Thank you. It helped me set up this example:

  require "benchmark"
  include Benchmark

  data = (0..49999)

  bm do |z|
    z.report { n = data.inject(0) { |x,y| x += y } }
    z.report { sum = 0; data.each { |y| sum += y } }
  end

Results here:

      user     system      total        real
  0.280000   0.000000   0.280000 (  0.280593)
  0.100000   0.000000   0.100000 (  0.101712)

-jcw

_____________________________________________
Metakit mailing list  -  [email protected]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to