Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
avro_turf / perf / encoding_speed.rb
Size: Mime:
#!/usr/bin/env ruby
#
# Measures the time it takes to encode messages of increasing size.

$LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__)))

require 'benchmark'
require 'avro_turf'

# Number of iterations per run.
N = 10_000

Benchmark.bm(15) do |x|
  sizes = [1, 10, 100, 1_000, 10_000]
  avro = AvroTurf.new(schemas_path: File.dirname(__FILE__))

  sizes.each do |size|
    data = {
      "name" => "John" * size,
      "address" => {
        "street" => "1st st." * size,
        "city" => "Citytown" * size
      }
    }

    x.report("size #{size}:") do
      N.times { avro.encode(data, schema_name: "person") }
    end
  end
end