summaryrefslogtreecommitdiff
path: root/bin/ffi-yajl-bench
blob: a861d1f86340ad1ca9955442471b1546dbd0ca71 (plain)
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
34
35
36
#!/usr/bin/env ruby

$LOAD_PATH << File.expand_path(File.join(File.dirname( File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__ ), "../lib"))

require "optparse"
require "ffi_yajl/benchmark"

opts = {}
optparse = OptionParser.new do |o|
  o.banner = "Usage: ffi-yajl-bench"

  opts[:profile] = false
  o.on( "-p", "--profile", "Run perftools.rb profiling" ) do
    opts[:profile] = true
  end

  o.on( "-F", "--ffi", "Force using FFI" ) do
    opts[:ffi] = true
  end

  o.on( "-E", "--ext", "Force using C ext" ) do
    opts[:ext] = true
  end
end

optparse.parse!

ENV["FORCE_FFI_YAJL"] = "ffi" if opts[:ffi]
ENV["FORCE_FFI_YAJL"] = "ext" if opts[:ext]

if opts[:profile]
  FFI_Yajl::Benchmark::ParseProfileRubyProf.new.run
else
  FFI_Yajl::Benchmark::Parse.new.run
  FFI_Yajl::Benchmark::Encode.new.run
end