summaryrefslogtreecommitdiff
path: root/lib/ffi_yajl/benchmark
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-11-17 13:41:09 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-11-17 13:41:09 -0800
commitb9ca0bb55c70cc179939134ce212dde86465488b (patch)
treee399ce4c4117e183be6cc8b7f29e4a62afc4e431 /lib/ffi_yajl/benchmark
parentf7f8f268e7aa97bcef04cfb83af23a856aebb8c2 (diff)
downloadffi-yajl-b9ca0bb55c70cc179939134ce212dde86465488b.tar.gz
install yajl-ruby to bmark against
Diffstat (limited to 'lib/ffi_yajl/benchmark')
-rw-r--r--lib/ffi_yajl/benchmark/encode.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb
index d86312f..cd77c50 100644
--- a/lib/ffi_yajl/benchmark/encode.rb
+++ b/lib/ffi_yajl/benchmark/encode.rb
@@ -3,7 +3,10 @@
require 'rubygems'
require 'benchmark'
-require 'yajl'
+begin
+ require 'yajl'
+rescue LoadError
+end
require 'stringio'
require 'ffi_yajl'
begin
@@ -30,8 +33,6 @@ module FFI_Yajl
times = ARGV[1] ? ARGV[1].to_i : 1000
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
::Benchmark.bmbm { |x|
- io_encoder = Yajl::Encoder.new
- string_encoder = Yajl::Encoder.new
x.report("FFI_Yajl::Encoder.encode (to a String)") {
times.times {
@@ -45,16 +46,22 @@ module FFI_Yajl
}
}
- x.report("Yajl::Encoder#encode (to an IO)") {
- times.times {
- io_encoder.encode(hash, StringIO.new)
+ if defined?(Yajl::Encoder)
+ io_encoder = Yajl::Encoder.new
+ x.report("Yajl::Encoder#encode (to an IO)") {
+ times.times {
+ io_encoder.encode(hash, StringIO.new)
+ }
}
- }
- x.report("Yajl::Encoder#encode (to a String)") {
- times.times {
- output = string_encoder.encode(hash)
+
+ string_encoder = Yajl::Encoder.new
+ x.report("Yajl::Encoder#encode (to a String)") {
+ times.times {
+ output = string_encoder.encode(hash)
+ }
}
- }
+ end
+
if defined?(JSON)
x.report("JSON.generate") {
times.times {