Class: FFI_Yajl::Benchmark::Encode

### Home Classes Methods

### In Files

- lib/ffi_yajl/benchmark/encode.rb

### Parent

Object

### Methods

- #run

### Files

- LICENSE
- MIT-LICENSE

### Class/Module Index

Quicksearch

- FFI_Yajl
- FFI_Yajl::Benchmark
- FFI_Yajl::Benchmark::Encode
- FFI_Yajl::Benchmark::EncodeProfile
- FFI_Yajl::Benchmark::Parse
- FFI_Yajl::Benchmark::ParseProfile
- FFI_Yajl::Benchmark::ParseProfileRubyProf
- FFI_Yajl::EncodeError
- FFI_Yajl::Encoder
- FFI_Yajl::FFI
- FFI_Yajl::FFI::Encoder
- FFI_Yajl::FFI::Parser
- FFI_Yajl::ParseError
- FFI_Yajl::Parser
- FFI_Yajl::Platform
- FFI_Yajl::YajlCallbacks
- JSON
- JSON::GeneratorError
- JSON::JSONError
- JSON::ParserError
- Array
- Bignum
- Date
- DateTime
- FalseClass
- Fixnum
- Float
- Hash
- Kernel
- NilClass
- Object
- String
- Symbol
- Time
- TrueClass

No matching classes.

# FFI_Yajl::Benchmark::Encode

### Public Instance Methods

run() click to toggle source

    # File lib/ffi_yajl/benchmark/encode.rb, line 46
          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| FFI_Yajl::Parser.parse(f.read) }

            times = ARGV[1] ? ARGV[1].to_i : 1000
            puts "Starting benchmark encoding #{filename} #{times} times\n\n"
            ::Benchmark.bmbm { |x|

              x.report("FFI_Yajl::Encoder.encode (to a String)") {
                times.times {
                  output = FFI_Yajl::Encoder.encode(hash)
                }
              }

              ffi_string_encoder = FFI_Yajl::Encoder.new
              x.report("FFI_Yajl::Encoder#encode (to a String)") {
                times.times {
                  output = ffi_string_encoder.encode(hash)
                }
              }

              if defined?(Oj)
                x.report("Oj.dump (to a String)") {
                  times.times {
                    output = Oj.dump(hash)
                  }
                }
              end

              if defined?(Yajl::Encoder)
                x.report("Yajl::Encoder.encode (to a String)") {
                  times.times {
                    output = Yajl::Encoder.encode(hash)
                  }
                }

                io_encoder = Yajl::Encoder.new
                x.report("Yajl::Encoder#encode (to an IO)") {
                  times.times {
                    io_encoder.encode(hash, StringIO.new)
                  }
                }

                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 {
                    JSON.generate(hash)
                  }
                }
                x.report("JSON.fast_generate") {
                  times.times {
                    JSON.fast_generate(hash)
                  }
                }
              end
              if defined?(Psych)
                x.report("Psych.to_json") {
                  times.times {
                    Psych.to_json(hash)
                  }
                }
                if defined?(Psych::JSON::Stream)
                  x.report("Psych::JSON::Stream") {
                    times.times {
                      io = StringIO.new
                      stream = Psych::JSON::Stream.new io
                      stream.start
                      stream.push hash
                      stream.finish
                    }
                  }
                end
              end
    #          if defined?(ActiveSupport::JSON)
    #            x.report("ActiveSupport::JSON.encode") {
    #              times.times {
    #                ActiveSupport::JSON.encode(hash)
    #              }
    #            }
    #          end
            }
          end

[Validate]

Generated with the Darkfish Rdoc Generator 2.