<commit_before># Portions Originally Copyright (c) 2008-2011 <NAME> - http://github.com/brianmario
# See MIT-LICENSE

require 'rubygems'
require 'benchmark'
begin
  require 'yajl'
rescue
  puts "INFO: yajl-ruby not installed"
end
require 'stringio'
require 'ffi_yajl'
begin
  require 'json'
rescue
  puts "INFO: json gem not installed"
end
begin
  require 'psych'
rescue
  puts "INFO: psych gem not installed"
end
begin
  require 'active_support'
rescue
  puts "INFO: active_support gem not installed"
end

module FFI_Yajl
  class Benchmark
    class Encode

      def run
        #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|
<commit_msg>jruby throws an uncatchable exception<commit_after># Portions Originally Copyright (c) 2008-2011 <NAME> - http://github.com/brianmario
# See MIT-LICENSE

require 'rubygems'
require 'benchmark'
unless RUBY_VERSION =~ /jruby/
  begin
    require 'yajl'
    require 'stringio'
  rescue
    puts "INFO: yajl-ruby not installed"
  end
end
require 'ffi_yajl'
begin
  require 'json'
rescue
  puts "INFO: json gem not installed"
end
begin
  require 'psych'
rescue
  puts "INFO: psych gem not installed"
end
begin
  require 'active_support'
rescue
  puts "INFO: active_support gem not installed"
end

module FFI_Yajl
  class Benchmark
    class Encode

      def run
        #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|

{'fraction_non_alphanumeric': 0.1166584280771132, 'fraction_numerical': 0.014829461196243203, 'mean_word_length': 3.5585585585585586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2341398', 'n_tokens_mistral': 747, 'n_tokens_neox': 709, 'n_words': 196}