File: sample.rb

package info (click to toggle)
ruby-stackprof 0.2.26-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 552 kB
  • sloc: python: 2,494; ruby: 1,264; perl: 920; ansic: 761; javascript: 735; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 662 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$:.unshift File.expand_path('../lib', __FILE__)
require 'stackprof'

class A
  def initialize
    pow
    self.class.newobj
    math
  end

  def pow
    2 ** 100
  end

  def self.newobj
    Object.new
    Object.new
  end

  def math
    2.times do
      2 + 3 * 4 ^ 5 / 6
    end
  end
end

#profile = StackProf.run(mode: :object, interval: 1) do
#profile = StackProf.run(mode: :wall, interval: 1000) do
profile = StackProf.run(mode: :cpu, interval: 1000) do
  1_000_000.times do
    A.new
  end
end

result = StackProf::Report.new(profile)
puts
result.print_method(/pow|newobj|math/)
puts
result.print_text
puts
result.print_graphviz
puts
result.print_debug