File: parse_profile.rb

package info (click to toggle)
ruby-ffi-yajl 2.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 936 kB
  • sloc: ruby: 1,904; ansic: 527; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 865 bytes parent folder | download | duplicates (2)
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
# Portions Originally Copyright (c) 2008-2011 Brian Lopez - http://github.com/brianmario
# See MIT-LICENSE

require "rubygems"
require "ffi_yajl"
begin
  require "perftools"
rescue LoadError
  puts "INFO: perftools.rb gem not installed"
end

ENV["CPUPROFILE_FREQUENCY"] = "4000"

module FFI_Yajl
  class Benchmark
    class ParseProfile
      def run
        return if defined?(PerfTools)

        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"

        PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do
          times.times { FFI_Yajl::Parser.parse(json) }
        end
        system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
      end
    end
  end
end