Created
December 14, 2014 03:30
-
-
Save y-yagi/d71c88ca407cc09f28e4 to your computer and use it in GitHub Desktop.
pg array parser 性能測定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'benchmark/ips' | |
require 'ruby-prof' | |
require 'pg_array_parser' | |
require 'active_record/connection_adapters/postgresql/array_parser' | |
class MyPgArrayParser | |
include PgArrayParser | |
end | |
class RailsPgArrayParser | |
include ActiveRecord::ConnectionAdapters::PostgreSQL::ArrayParser | |
end | |
test_string = '{some,strings that,"May have some ,\'s"}' | |
Benchmark.ips do |x| | |
x.report('pg_array_parser') do | |
parser = MyPgArrayParser.new | |
parser.parse_pg_array test_string | |
end | |
x.report('rails_pg_array_parser') do | |
parser = RailsPgArrayParser.new | |
parser.parse_pg_array test_string | |
end | |
x.compare! | |
end | |
########################## | |
Calculating ------------------------------------- | |
pg_array_parser 66.151k i/100ms | |
rails_pg_array_parser | |
5.554k i/100ms | |
------------------------------------------------- | |
pg_array_parser 1.308M (± 5.7%) i/s - 6.549M | |
rails_pg_array_parser | |
56.155k (± 7.2%) i/s - 283.254k | |
Comparison: | |
pg_array_parser: 1308030.9 i/s | |
rails_pg_array_parser: 56154.7 i/s - 23.29x slower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment