summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-11-17 13:35:55 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-11-17 13:35:55 -0800
commita2d05c7b645461ac5ce0b54a1960829d07f298be (patch)
treecf1f0cb17fcbef062bf9daf5be450a45dab57a20
parentb4c8f40254c195b8c4ce1ee7d2e66d27ae1214f1 (diff)
downloadffi-yajl-a2d05c7b645461ac5ce0b54a1960829d07f298be.tar.gz
working benchmark script
-rwxr-xr-xbin/ffi-yajl-bench8
-rw-r--r--ffi-yajl.gemspec4
-rw-r--r--lib/ffi_yajl/benchmark.rb4
-rw-r--r--lib/ffi_yajl/benchmark/encode.rb11
4 files changed, 22 insertions, 5 deletions
diff --git a/bin/ffi-yajl-bench b/bin/ffi-yajl-bench
new file mode 100755
index 0000000..0ab2f1e
--- /dev/null
+++ b/bin/ffi-yajl-bench
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+$: << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))
+
+require 'ffi_yajl/benchmark'
+
+FFI_Yajl::Benchmark::Encode.new().run()
+
diff --git a/ffi-yajl.gemspec b/ffi-yajl.gemspec
index 59d141b..cc5240c 100644
--- a/ffi-yajl.gemspec
+++ b/ffi-yajl.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency "ffi", "~> 1.9"
s.bindir = "bin"
- s.executables = []
+ s.executables = %w( ffi-yajl-bench )
s.require_path = 'lib'
- s.files = %w(Rakefile LICENSE README.md) + Dir.glob("{bin,lib,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
+ s.files = %w(Rakefile LICENSE README.md) + Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
end
diff --git a/lib/ffi_yajl/benchmark.rb b/lib/ffi_yajl/benchmark.rb
new file mode 100644
index 0000000..852cbbe
--- /dev/null
+++ b/lib/ffi_yajl/benchmark.rb
@@ -0,0 +1,4 @@
+
+require 'ffi_yajl/benchmark/encode.rb'
+require 'ffi_yajl/benchmark/parse.rb'
+
diff --git a/lib/ffi_yajl/benchmark/encode.rb b/lib/ffi_yajl/benchmark/encode.rb
index fba4855..1e598c4 100644
--- a/lib/ffi_yajl/benchmark/encode.rb
+++ b/lib/ffi_yajl/benchmark/encode.rb
@@ -16,15 +16,18 @@ begin
rescue LoadError
end
-class FFI_Yajl::Benchmark::Encode
+module FFI_Yajl
+ class Benchmark
+ class Encode
def run
- filename = ARGV[0] || 'benchmark/subjects/ohai.json'
+ #filename = ARGV[0] || 'benchmark/subjects/ohai.json'
+ filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json"))
hash = File.open(filename, 'rb') { |f| Yajl::Parser.new.parse(f.read) }
times = ARGV[1] ? ARGV[1].to_i : 1000
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
- Benchmark.bmbm { |x|
+ ::Benchmark.bmbm { |x|
io_encoder = Yajl::Encoder.new
string_encoder = Yajl::Encoder.new
@@ -84,5 +87,7 @@ class FFI_Yajl::Benchmark::Encode
end
}
end
+ end
+ end
end