/mobile Handheld Friendly website
Ubuntu : Intel® Q6600® one core |
Each table row shows performance measurements for this Ruby 2.0 program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 500 | 7.10 | 7.78 | 20,148 | 828 | 0% 1% 0% 100% |
| 3,000 | 274.52 | 275.21 | 24,932 | 828 | 0% 0% 0% 100% |
| 5,500 | 717.21 | 718.21 | 25,120 | 828 | 0% 0% 0% 100% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read spectral-norm benchmark to see what this program should do.
ruby 2.0.0p0 (2013-02-24 revision 39474) [i686-linux]
# The Computer Language Benchmarks Game # http://benchmarksgame.alioth.debian.org # Contributed by Rick Branson # # There is currently a bug in JRuby as of 11/16/2010 that causes # Marshal to read IOs in a blocking manner, which will cause this # script to hang. IS_THREADED = RUBY_PLATFORM == "java" if IS_THREADED require "fcntl" end class Worker attr_reader :reader def initialize(enum, index, total, &block) @enum = enum @index = index @total = total @reader, @writer = IO.pipe if IS_THREADED @thread = Thread.new do self.execute(&block) end else @p = Process.fork do @reader.close self.execute(&block) @writer.close end @writer.close end end def execute(&block) chk = @enum.size / @total (0 ... @enum.size).step(@total) do |i| idx = i + @index d = @enum[idx] to_parent([idx, yield(d)]) unless d == nil end end def to_parent(msg) Marshal.dump(msg, @writer) end def self.gather(workers) res = [] ios = workers.map { |w| w.reader } while ios.size > 0 do sr, sw, se = IO.select(ios, nil, nil) if sr sr.each do |io| begin loop do msg = Marshal.load(io) idx, content = msg res[idx] = content end rescue EOFError ios.delete(io) end end end end Process.waitall res end def self.map(enum, worker_count = 6, &block) count = [enum.size, worker_count].min workers = (0 ... count).map do |idx| Worker.new(enum, idx, count, &block) end Worker.gather(workers) end end def eval_A_times_u(u) usz = u.size urange = (0 ... usz) umap = urange.to_a Worker.map(umap) do |i| urange.inject(0) do |sum, j| sum += (1.0 / ((i + j) * (i + j + 1) / 2 + i + 1)) * u[j] end end end def eval_At_times_u(u) usz = u.size urange = (0 ... usz) umap = urange.to_a Worker.map(umap) do |i| urange.inject(0) do |sum, j| sum += (1.0 / ((j + i) * (j + i + 1) / 2 + j + 1)) * u[j] end end end def eval_AtA_times_u(u) eval_At_times_u(eval_A_times_u(u)) end n = ARGV[0].to_i u = [1] * n v = nil 10.times do v = eval_AtA_times_u(u) u = eval_AtA_times_u(v) end vBv = 0 vv = 0 (0 ... n).each do |i| vBv += u[i] * v[i] vv += v[i] * v[i] end print "%0.9f" % (Math.sqrt(vBv / vv)), "\n"
Sun, 24 Feb 2013 20:35:49 GMT COMMAND LINE: /usr/local/src/ruby-2.0.0-p0/ruby spectralnorm.yarv-3.yarv 5500 PROGRAM OUTPUT: 1.274224153