Sha256: 3211a82c09d0546d43f18bcc2f2cd838c1c0652eb18688e524879f457f3aefef

Contents?: true

Size: 920 Bytes

Versions: 3

Compression:

Stored size: 920 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '/profile_helper')

class ShellshotProfile < Test::Unit::TestCase

  def setup
    RubyProf.measure_mode = RubyProf::WALL_TIME
  end

  def benchmark(title, &block)
    puts "#{title} \n"
    time = Benchmark.measure &block
    puts "Time spent: #{time.to_s.squeeze.strip} \n"
  end

  def cmd
    %q[ruby -e '10000.times { puts "a" }']
  end

  def test_builtin_exec
    profile "system" do
      system("#{cmd} > /dev/null")
    end
  end

  def test_executing_large_stdout
    profile "Shellshot" do
      Shellshot.exec cmd #, :stdout => '/dev/null'
    end
  end

  def profile(name, &block)
    time = Benchmark.measure do
      result = RubyProf.profile &block
      printer = RubyProf::FlatPrinter.new(result)
      puts "\n#== #{name} ==\n"
      printer.print(STDOUT, :min_percent => 10)
    end
    puts "Time spent: #{time.to_s.squeeze.strip} \n"
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shellshot-0.4.3 profile/shellshot_profile.rb
shellshot-0.4.2 profile/shellshot_profile.rb
shellshot-0.4.1 profile/shellshot_profile.rb