Ruby/Development/profile

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Profiling Your Application

#!/usr/bin/env ruby
require "profile"
total = 0
("a".."zz").each do |seq|
  ["a", "b", "c"].each do |i|
    if seq.index(i)
      total += 1
      break
    end
  end
end
puts "Total: #{total}"



Ruby profiler: add require "profile" to the start of your code

# , or run it with ruby --r profile before your source file name.
require "profile"
class Calculator
  def self.count_to_large_number
    x = 0
    100000.times { x += 1 }
  end
  def self.count_to_small_number
    x = 0
    1000.times { x += 1 }
  end
end
Calculator.count_to_large_number
Calculator.count_to_small_number