Sha256: 65a0fe1cfb9d6f524883f3f801c9291a04c9122e2688ce587d16fafa4270f29e

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

#!/usr/bin/env ruby

require 'test/unit'
require 'ruby-prof'
require 'test_helper'
require 'prime'


# --  Tests ----
class MeasureModeTest < Test::Unit::TestCase

  def test_process_time
    RubyProf::measure_mode = RubyProf::PROCESS_TIME
    assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
    result = RubyProf.profile do
      run_primes
    end
    
    result.threads.each do |thread_id, methods|
      methods.each do |method|
        check_parent_times(method)
        check_parent_calls(method)
        check_child_times(method)   
      end
    end
  end
  
  def test_wall_time
    RubyProf::measure_mode = RubyProf::WALL_TIME
    assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
    result = RubyProf.profile do
      run_primes
    end
    
    result.threads.values.each do |methods|
      methods.each do |method|
        check_parent_times(method)
        check_parent_calls(method)
        check_child_times(method)   
      end
    end
  end
  
  def test_cpu
    return unless RubyProf.constants.include?('CPU_TIME')
    
    RubyProf::measure_mode = RubyProf::CPU_TIME
    assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
    result = RubyProf.profile do
      run_primes
    end
    
    result.threads.values.each do |methods|
      methods.each do |method|
        check_parent_times(method)
        check_parent_calls(method)
        check_child_times(method)   
      end
    end
  end
  
  def test_allocated_objects
    return unless RubyProf.constants.include?('ALLOCATIONS')
    
    RubyProf::measure_mode = RubyProf::ALLOCATIONS
    
    assert_equal(RubyProf::ALLOCATIONS, RubyProf::measure_mode)
    
    result = RubyProf.profile do
      Array.new
    end
  end
  
  def test_invalid
    assert_raise(ArgumentError) do
      RubyProf::measure_mode = 7777
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-prof-0.5.2-mswin32 test/measure_mode_test.rb
ruby-prof-0.5.1-mswin32 test/measure_mode_test.rb
ruby-prof-0.5.0-mswin32 test/measure_mode_test.rb
ruby-prof-0.5.2 test/measure_mode_test.rb
ruby-prof-0.5.1 test/measure_mode_test.rb
ruby-prof-0.5.0 test/measure_mode_test.rb