class Object

  1. benchmarks/benchmark.rb
  2. ext/ruby_prof/extconf.rb
  3. test/module_test.rb
  4. test/prime.rb
  5. test/recursive_test.rb
  6. show all
Parent: benchmark.rb

Included modules

  1. Bar

Public Instance methods

add_define (name, value = nil)
[show source]
# File ext/ruby_prof/extconf.rb, line 29
def add_define(name, value = nil)
  if value
    $defs.push("-D#{name}=#{value}")
  else
    $defs.push("-D#{name}")
  end
end
cycle (n)
[show source]
# File test/recursive_test.rb, line 11
def cycle(n)
  sub_cycle(n)
end
find_largest (primes)
[show source]
# File test/prime.rb, line 31
def find_largest(primes)
  largest = primes.first

  # Intentionally use upto for example purposes
  # (upto is also called from is_prime)
  0.upto(primes.length-1) do |i|
    sleep(0.02)
    prime = primes[i]
    if prime > largest
      largest = prime
    end
  end
  largest
end
find_primes (arr)
[show source]
# File test/prime.rb, line 24
def find_primes(arr)
  result = arr.select do |value|
    is_prime(value)
  end
  result
end
go ()
[show source]
# File benchmarks/benchmark.rb, line 4
def go
end
is_prime (x)
[show source]
# File test/prime.rb, line 16
def is_prime(x)
  y = 2
  y.upto(x-1) do |i|
    return false if (x % i) == 0
  end
  true
end
make_random_array (length, maxnum)

A silly little test program that finds prime numbers. It is intentionally badly designed to show off the use of ruby-prof.

Source from people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/

[show source]
# File test/prime.rb, line 7
def make_random_array(length, maxnum)
  result = Array.new(length)
  result.each_index do |i|
    result[i] = rand(maxnum)
  end

  result
end
run_primes (length=10, maxnum=1000)
[show source]
# File test/prime.rb, line 46
def run_primes(length=10, maxnum=1000)
  # Create random numbers
  random_array = make_random_array(length, maxnum)

  # Find the primes
  primes = find_primes(random_array)

  # Find the largest primes
  # largest = find_largest(primes)
end
simple (n)
[show source]
# File test/recursive_test.rb, line 4
def simple(n)
  sleep(1)
  n -= 1
  return if n == 0
  simple(n)
end
sub_cycle (n)
[show source]
# File test/recursive_test.rb, line 15
def sub_cycle(n)
  sleep(1)
  n -= 1
  return if n == 0
  cycle(n)
end