summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb
blob: db72e4598ebca0af3eb83620a1eb66e702e18a0c (plain)
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
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE

require 'rubygems'
require 'ffi_yajl'

module FFI_Yajl
  class Benchmark
    class ParseProfileRubyProf
      def run
        begin
          require 'ruby-prof'
        rescue LoadError
          puts "INFO: perftools.rb gem not installed"
        end

        if defined?(RubyProf)
          filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
          json = File.new(filename, 'r').read

          times = 1000
          puts "Starting profiling encoding #{filename} #{times} times\n\n"

          result = RubyProf.profile do
            times.times {
              output = FFI_Yajl::Parser.parse(json)
            }
          end

          printer = RubyProf::GraphPrinter.new(result)
          printer.print(STDOUT, {})

        end
      end
    end
  end
end