Skip to content

Instantly share code, notes, and snippets.

@lest
Created September 28, 2012 11:42
Show Gist options
  • Save lest/a012d50e817373c08f79 to your computer and use it in GitHub Desktop.
Save lest/a012d50e817373c08f79 to your computer and use it in GitHub Desktop.
require File.expand_path('../../config/environment', __FILE__)
require 'benchmark'
statuses = TruckStatus.order(:id).limit(10_000)
MultiJson.engine = :json_gem
Benchmark.bm do |x|
x.report 'default ' do
statuses.to_json
end
x.report 'attrs ' do
statuses.to_json methods: [:latitude, :longitude, :timestamp, :virtual_odometer]
end
x.report 'select ' do
statuses.select([:latitude, :longitude, :timestamp, :virtual_odometer]).to_json methods: [:latitude, :longitude, :timestamp, :virtual_odometer]
end
x.report 'lightning' do
statuses.lightning.to_json
end
x.report 'json ' do
JSON.dump statuses.lightning
end
x.report 'yajl ' do
Yajl.dump statuses.lightning
end
x.report 'oj ' do
Oj.dump statuses.lightning, mode: :compat
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment