class FFI_Yajl::Benchmark::EncodeProfile

Public Instance Methods

run() click to toggle source
# File lib/ffi_yajl/benchmark/encode_profile.rb, line 18
def run
  if defined?(PerfTools)
    filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
    hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }

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

    ffi_string_encoder = FFI_Yajl::Encoder.new
    PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do
      times.times {
        output = ffi_string_encoder.encode(hash)
      }
    end
    system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
  end
end