summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl/benchmark/encode_profile.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ffi_yajl/benchmark/encode_profile.rb')
-rw-r--r--lib/ffi_yajl/benchmark/encode_profile.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb
index f7ac7c2..36b92c7 100644
--- a/lib/ffi_yajl/benchmark/encode_profile.rb
+++ b/lib/ffi_yajl/benchmark/encode_profile.rb
@@ -5,7 +5,7 @@ require 'rubygems'
require 'ffi_yajl'
begin
require 'perftools'
-rescue Exception
+rescue LoadError
puts "INFO: perftools.rb gem not installed"
end
@@ -15,21 +15,19 @@ module FFI_Yajl
class Benchmark
class EncodeProfile
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) }
+ return unless defined?(PerfTools)
- times = 1000
- puts "Starting profiling encoding #{filename} #{times} times\n\n"
+ filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
+ hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) }
- 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")
+ 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 { ffi_string_encoder.encode(hash) }
end
+ system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out")
end
end
end