#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'ffi-yajl' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

Gem.use_gemdeps

version = ">= 0.a"

str = ARGV.first
if str
  str = str.b[/\A_(.*)_\z/, 1]
  if str and Gem::Version.correct?(str)
    version = str
    ARGV.shift
  end
end

path =
  if Gem.respond_to?(:activate_bin_path)
    Gem.activate_bin_path('ffi-yajl', 'ffi-yajl-bench', version)
  else
    gem "ffi-yajl", version
    Gem.bin_path("ffi-yajl", "ffi-yajl-bench", version)
  end

if __FILE__ == path
#!/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

else
  load(path)
end
