performance measurements

Each table row shows performance measurements for this Ruby program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
2,000Failed  478   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read pidigits benchmark to see what this program should do.

 notes

ruby 2.1.5p273 (2014-11-13 revision 48405) [i686-linux]

 pidigits Ruby #5 program source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org

# contributed by Aaron Tavistock

# Leverage GMP like all the other languages 
require 'gmp'

# Helpers that improve readability
class GMP::Z
  def mul!(a,b)
    GMP::Z.mul(self, a, b)
  end

  def times!(a)
    GMP::Z.mul(self, self, a)
  end
end

# Constants to reduce object instantiation and casting
ZERO = GMP::Z(0)
ONE = GMP::Z(1)
TWO = GMP::Z(2)
THREE = GMP::Z(3)
TEN = GMP::Z(10)

# Allocate these expensive objects once
@display_chunk = GMP::Z(0)
@k = GMP::Z(0)
@a = GMP::Z(0)
@t = GMP::Z(0)
@u = GMP::Z(0)
@k1 = GMP::Z(1)
@n = GMP::Z(1)
@d = GMP::Z(1)
@tmp = GMP::Z(0)

def next_chunk
  @tmp.mul!(@d, @t)
  @a.sub!(@tmp)
  @a.times!(TEN)
  @n.times!(TEN)
end

def produce_chunk
  @k.add!(ONE)
  @t.mul!(@n, TWO)
  @n.times!(@k)

  @a.add!(@t)
  @k1.add!(TWO)
  @a.times!(@k1)
  @d.times!(@k1)
  
  if @a >= @n
    @tmp.mul!(@n, THREE)
    @tmp.add!(@a)
    @t = @tmp.fdiv(@d)
    @u = @tmp.fmod(@d)
    @u.add!(@n)
    if @d > @u
      @display_chunk.times!(TEN)
      @display_chunk.add!(@t)
      return true
    end
  end
  
  false
end  

N = (ARGV[0] || 100).to_i
count = 0
while(count < N) do
  if produce_chunk
    count += 1
    if count % 10 == 0
      STDOUT.write "%010d\t:%d\n" % [@display_chunk.to_i, count]
      @display_chunk.times!(ZERO)
    end 
    next_chunk
  end
end

if @display_chunk.to_i > 0
  STDOUT.write "%s\t:%d\n" % [@display_chunk.to_s.ljust(10), count]
end

 make, command-line, and program output logs

Sat, 15 Nov 2014 11:56:52 GMT

COMMAND LINE:
/usr/local/src/ruby/bin/ruby pidigits.yarv-5.yarv 2000

PROGRAM FAILED 


PROGRAM OUTPUT:

/usr/local/src/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- gmp (LoadError)
	from /usr/local/src/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from pidigits.yarv-5.yarv:7:in `<main>'

Revised BSD license

  Home   Conclusions   License   Play